PWZER / swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask and Sanic. https://pwzer.github.io/swagger-ui-py/
https://pypi.org/project/swagger-ui-py
Apache License 2.0
68 stars 31 forks source link

Adding support to pass JSON/YAML string as spec to render SwaggerUI #28

Closed sripathivenky closed 2 years ago

sripathivenky commented 3 years ago

Added ability to pass API spec to pass as a string via spec field to api_doc. This was swagger-UI-py can be used in connection with libraries like apices

spec_string = '{"paths": {"/random": {"get": {"description": "Get a random pet", "security": [{"ApiKeyAuth": []}],' \ ' "responses": {"200": {"description": "Return a pet", "content": {"application/json":' \ ' {"schema": {"$ref": "#/components/schemas/Pet"}}}}}}}}, ' \ '"info": {"title": "Swagger Petstore", "version": "1.0.0"},' \ ' "openapi": "3.0.0", "servers" : [ {"url": "http://127.0.0.1:8989/api"}],' \ ' "components": {"schemas": {"Category": {"type": "object", "properties": ' \ '{"id": {"type": "integer"}, "name": {"type": "string"}}, "required": ["name"]}, "Pet": ' \ '{"type": "object", "properties": {"categories": {"type": "array", "items": ' \ '{"$ref": "#/components/schemas/Category"}}, "name": {"type": "string"}}}}, "securitySchemes": ' \ '{"ApiKeyAuth": {"type": "apiKey", "in": "header", "name": "X-API-Key"}}}}' api_doc(app, spec=spec_string, url_prefix='/api/doc/')