factset/quart-openapi

How to make a https scheme/server automatically available?

Closed this issue · 2 comments

Hi,
First let me thank you for the work done here, really appreciated.
Coming to my question, is it possible to add a https option for the requests without the need of creating manually a swagger yml file?

Editing the yaml file, I know it is possible:

openapi: 3.0.0
info:
  title: OpenApi Rest Documentation
  version: '1.0'
servers:
  - url: 'http://'
  - url: 'https://'

But I wanted to know if it is possible to add the option when creating the app:

from quart_openapi import Pint, Resource
from swagger_ui import quart_api_doc

# Construct the core application
app = Pint(__name__, no_openapi=True)

@app.route("/api/doc/swagger.json")
async def openapi():
    return jsonify(app.__schema__)


quart_api_doc(
    app,
    config_url="http://localhost:8080/api/doc/swagger.json",
    url_prefix="/api/doc",
    title="API doc",
)

.
.
.

Hi! Thanks for using this package and for the feedback!

Just want to clarify something: Are you specifically looking to have more than one url listed? Or just want the https url to be the one it uses?

Currently the library doesn't have a way to specify multiple URLs yet, but Quart has a way of specifying config vars for the App link so this library hooks into those config variables.

If you set the config variable PREFERRED_URL_SCHEME then that is what will be used as the scheme in the generated swagger (ie: set it to 'https' and that's what will be used). Alternatively, Quart also has a config PREFER_SECURE_URLS which it uses for internal construction of urls which if set to True will use https instead of http as the default for quart-openapi as well.

This library also uses the config SERVER_NAME as the way to specify the host used. So if all you need is to customize that url or the scheme, using the above config variables should be sufficient.

If you actually want to have multiple server urls in the outputted Swagger doc, then yea, an update will need to be made to this library to do that. So please let me know if the above solves your issue or if you're specifically looking to have more than one url listed in the resulting swagger. Thanks!

Hi,
Thank for your reply, it definitely helped me. I would like to have the 2 options available, but is a nice to have. For now I can work with choosing http or https.
Btw, I checked the code and it wouldnt be too hard to allow to have both options. Maybe an issue can be opened with that goal and I can contribute to this lib ;)

Thank you!