factset / quart-openapi

Module for Quart to add Flask-RESTPlus like functionality
https://factset.github.io/quart-openapi/
Other
82 stars 22 forks source link

Swagger integration #42

Closed kev11moreno closed 4 years ago

kev11moreno commented 4 years ago

Hello, I saw that you integrated Swagger into the project, but, do you have an example that how to use it?, other question, this integration includes swagger ui?, I'm reading the code and documentations but I can't understand how to used it.

zeroshade commented 4 years ago

The current integration does not include swagger ui, it will only generate an openapi.json endpoint which produces swagger compatible json. As shown in the readme (with more examples in the docs here), a simple script of:

from quart_openapi import Pint, Resource

app = Pint(__name__, title='Sample App')

@app.route('/')
class Root(Resource):
  async def get(self):
    '''Hello World Route

    This docstring will show up as the description and short-description
    for the openapi docs for this route.
    '''
    return "hello"

app.run()

Will create a server with a "/" route that just returns 'hello' to get requests, and will also have an endpoint "/openapi.json" which will return the following:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Sample App",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "http://"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "summary": "Hello World Route",
        "description": "This docstring will show up as the description and short-description\nfor the openapi docs for this route.",
        "tags": [],
        "responses": {
          "200": {
            "description": "Success"
          }
        },
        "operationId": "get_root"
      }
    }
  }
}

Which is parseable in swagger ui. I haven't had the time to add the swagger-ui integration here, but it's not difficult to do given that they provide a distributible package that can be easily incorporated and served.

kev11moreno commented 4 years ago

Hi, thanks you for the answer, I deduced it after I make this answer, for the record I used this lib swagger-ui-py, and just pass as argument the exposed json (url) that you returns.