flask-swagger-ui icon indicating copy to clipboard operation
flask-swagger-ui copied to clipboard

is there a way to load up a json dict into this package instead of from a file?

Open akouminov opened this issue 3 years ago • 2 comments

I dynamically generate my doc with apisec https://github.com/marshmallow-code/apispec

can I pass its output to this package or do I need to fork and customize?

Thanks!

akouminov avatar Feb 04 '21 16:02 akouminov

I had the same problem, but it seems like this package is not handling the retrieval of your swagger specification. You can try passing the json specification like this get_swaggerui_blueprint(..., config={"spec": "<json spec>"}). It should work if the swagger-ui js version is up to date.

lausek avatar Mar 03 '21 07:03 lausek

I had this problem and I end up doing this:

def addSwagger(apiInstance, appInstance):
    ###- The ugliest thing I ever seen, but thats the way flask_swagger_ui works...
    documentationUrl = f'{apiInstance.baseUrl}{DOCUMENTATION_ENDPOINT}'
    swaggerUi = get_swaggerui_blueprint(
        documentationUrl,
        OpenApiDocumentationFile.getDocumentationFileName(apiInstance)
    )
    @appInstance.route(f'{documentationUrl}/{OpenApiDocumentationFile.getDocumentationFileName(apiInstance)}', methods=['GET'])
    def getSwagger() :
        return apiInstance.documentation
    appInstance.register_blueprint(swaggerUi, url_prefix=documentationUrl)

It's ugly, but honestly I see no solution other than this.

Im using a combination of Flask and flask_restful. But I see no reason for this not to works in Flask all alone

Any problem, just reply here and I can try write a cleanner example (I just copy pasted from my project)

SamuelJansen avatar May 24 '21 21:05 SamuelJansen