apidoc2/templates/openapi.yaml
Antonio de la Rosa aaf3c17220 Added files
2025-04-26 16:50:27 +02:00

108 lines
2.9 KiB
YAML

openapi: 3.0.2
servers:
- url: ${appdoc.url}
info:
description: |-
${appdoc.description}
version: ${version}
title: ${title}
termsOfService: '${terms_of_service}'
contact:
email: ${email}
license:
name: ${license['name']}
url: ${license['url']}
tags:
% for tag, tag_description in appdoc.tags.items():
- name: ${tag}
description: ${tag_description}
% endfor
paths:
% for route in appdoc.routes.values():
${route.route}:
${route.method}:
% if route.bearer:
security:
- Bearer: [] # use the same name as above
% endif
tags:
- ${route.tag}
summary: ${route.summary}
description: ${route.description}
operationId: ${route.operationId}
% if len(route.parameters)>0:
parameters:
% for param in route.parameters:
- name: ${param['name']}
in: ${param['in']}
description: ${param['description']}
required: ${param['required']}
schema:
type: ${param['schema']['type']}
%endfor
% endif
responses:
'200':
description: successful operation
content:
application/json:
schema:
%if not route.return_obj:
$ref: '#/components/schemas/StandardResponse'
% else:
$ref: '#/components/schemas/${route.return_obj}'
% endif
'400':
description: Invalid ID supplied
'404':
description: Element not found
'405':
description: Invalid input
% if route.method=='post' or route.method=='put':
requestBody:
description: ${route.post['description']}
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/${route.post['content']}'
% endif
% endfor
components:
securitySchemes:
Bearer: # arbitrary name for the security scheme
type: http
scheme: bearer
bearerFormat: JWT # optional, arbitrary value for documentation purposes
schemas:
StandardResponse:
type: object
properties:
error:
type: boolean
example: 0
message:
type: string
code_error:
type: integer
error_form:
type: object
% for name_component, properties in appdoc.components.items():
${name_component}:
type: object
properties:
% for prop_name, prop in properties.items():
${prop_name}:
% if prop['type']!='array':
type: ${prop['type']}
format: ${prop['format']}
% if prop['example']!='':
example: ${prop['example']}
%endif
%else:
type: array
items:
$ref: '#/components/schemas/${prop['object']}'
%endif
%endfor
% endfor