Giter VIP home page Giter VIP logo

flask-swagger-ui's People

Contributors

barakalon avatar gnowland avatar maicotimmerman avatar sveint avatar ukaratay avatar wangsha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flask-swagger-ui's Issues

Using local resource for api url?

This is going to be kind of a dumb question, but I'm trying to narrow down exactly what I'm doing wrong.

I'm working on a small flask project and have been unable to work out how to correctly provide a local resource as my api url. I have my file written, but whether I put it in the base of the project (i.e. where configs, bootstrap, etc live) or the base of the actual flask app (contains app.py, etc), I get the flask ui showing an error message saying "No operations defined in spec!" and a further error message saying that it can't read from the file.

I've checked my permissions, and they all seem right, so I'm trying to figure out what else I could be doing wrong. My only other thought is that I need a sort of internal endpoint to hit, rather than just supplying the file location.

Could you please confirm if there is a particular location the file needs to be in, and/or if it needs to be served to swagger via another endpoint within the application?

Completely blank white swagger page, browser reports failure to retrieve files from nonsense URLs

Flask is looking for Swagger files at nonsense locations, e.g. http://swagger-ui-standalone-preset.js/, and I get a blank white page upon loading my Swagger path. gunicorn and Python report no errors, and my API works fine apart from the Swagger page.

Firefox reports the following:

Failed to load resource: net::ERR_EMPTY_RESPONSE
swagger-ui-bundle.js/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
swagger-ui.css/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
index.css/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
(index):22 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at (index):22:9
favicon-32x32.png/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE
favicon-16x16.png/:1          Failed to load resource: net::ERR_EMPTY_RESPONSE

OAS 3.1 support

Can support for OpenAPI 3.1 be added, particularly the null type?

How to add interceptors via flask-swagger-ui?

I'm trying to add a requestInteceptor via config but swagger-ui expects a js function

image

swaggerui_blueprint = get_swaggerui_blueprint(
    SWAGGER_URL,  # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'
    API_URL,
    config={  # Swagger UI config overrides
        'app_name': "Test application",
        'showMutatedRequest': True,
        'requestInterceptor': "function (request) { console.log(request); return request; }" 
    },
)

is there anyway to make this work?

How to solve failed to load API definition?

I am trying to configure the swagger.json but every time it is giving the below error.

Fetch errorFailed to fetch C:\Project\test\swagger.json
Fetch errorPossible cross-origin (CORS) issue? The URL origin (file://) does not match the page (http://127.0.0.1:5000). Check the server returns the correct 'Access-Control-Allow-*' headers.

When i clicked on "Invalid" button {"schemaValidationMessages":[{"level":"error","message":"Can't read from file c:/Project\test\\swagger.json"}]} this error is coming .

SWAGGER_URL = '/swagger'
API_URL = 'C:\Project\test\swagger.json'
SWAGGERUI_BLUEPRINT = get_swaggerui_blueprint(
    SWAGGER_URL,
    API_URL,
    config={
        'app_name': "Seans-Python-Flask-REST-Boilerplate"
    }
)
app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL)

Let me know what i am doing wrong.

Is base_url really needed?

From what I can tell, base_url is only used in the index.html template to load the static files, which should all be relative to the html file.

I'm currently passing '.' as the base_url, to make all the static files be loaded relative to the html file and it seems to work. So, is this parameter even needed?

Upgrade Swagger UI to 5.1.0

The Swagger UI version used in the latest version of flask-swagger-ui is outdated and has some bugs that have been fixed in recent versions of Swagger UI.

Swagger UI uploads empty CSV (latin1 encoded)

Swagger UI uploads empty CSV if it is latin1 encoded (csv has danish characters like ø, Ø, Æ), works alright with standard utf-8 encoded CSV.

Here is swagger json:

{
  "swagger": "2.0",
  "info": {
    "version": "2.2",
    "title": "searcher"
  },
  "paths": {
    "/search": {
      "post": {
        "summary": "Search endpoint uploading files manually",
        "tags": [
          "Calls"
        ],
        "consumes": [
          "multipart/form-data"
        ],
        "produces": [
          "text/csv"
        ],
        "parameters": [
          {
            "name": "reference_file",
            "in": "formData",
            "type": "file",
            "required": true,
            "description": "CSV file containing reference data"
          },
          {
            "name": "query_file",
            "in": "formData",
            "type": "file",
            "required": true,
            "description": "CSV file containing query data"
          },
          {
            "name": "config_file",
            "in": "formData",
            "type": "file",
            "required": true,
            "description": "JSON file containing configuration data"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "type": "string",
              "example": "type,similarity,id,name,surname,age,gender,region,date_payment,amount,id_reference,name_reference,surname_reference,age_reference,gender_reference,region_reference\nsimilar_id,0.9999997,1771594086,Molly,Forsberg,50,male,Stockholm,43888,398.82,1771594087,Molly,Forsberg,50,male,Stockholm\nfeature_search,1.0000001,3519854485,Isak,Ek,25,male,Gotland,44797,819.62,3040728485,Isak,Ek,25,male,Gotland\nmatch,1,6919199375,William,Lundverg,35,male,Dalarna,43882,398.82,6919199375,William,Lundberg,35,male,Dalarna\n"
            }
          }
        }
      },
      "x-swagger-router-controller": "app"
    }
  }
}

here is the python code that tries to read a file identified with 'query_file' in wagger json:

from flask import request
@app.route('/search', methods=['POST'])
def seas_query() -> Response:
    try:
        filename = 'query_file'
        df = pd.read_csv(request.files[filename], sep = ',', dtype = 'object')
    except UnicodeDecodeError:
        print('Unable to read {fname}, trying with latin1 encoding.'.format(fname=request.files[filename]))

        file_obj = request.files[filename]
        file_obj.save('downloaded_'+file_obj.filename)
        # even the downloaded file from above code is empty
        df = pd.read_csv('downloaded_'+file_obj.filename, delimiter=";", encoding='latin1')
    except Exception as e:
        print('Unable to read file')

the exception I receive is:

**df = pd.read_csv('downloaded_'+file_obj.filename, delimiter=";", encoding='latin1')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ore\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pandas\util_decorators.py", line 211, in wrapper
return func(*args, kwargs)
...
...
...
File "pandas_libs\parsers.pyx", line 554, in pandas._libs.parsers.TextReader.cinit
pandas.errors.EmptyDataError: No columns to parse from file

The csv has data inside it. Also, loads data fine when I use utf-8 encoded csv or any other csv that doesn't contain danish letters.

Missing index.template.html

Because of a missing MANIFEST.in, installing the package from Pypi causes the template not to be copied in the installation.

I will be submitting a msg with a fix.

flask-swagger-ui for local yaml file

As far as I understand get_swaggerui_blueprint() expects address to yaml that is later requested via HTTP. But is it possible to "embed" yaml file at the stage of creating blueprint? (so that the yaml file does not need to be exposed to the world)

Need to Add Servers property for URL prefixing Code

I use this project frequently.
We use alot of prefixing of our url's etc.
I need to support the server property of openapi 3.x.
I've figured out and tested how to add it but would like it added to project rather than create another fork...

Its a extra property on blueprint and then adds a server spec in the index file if variable is set.
I made it optional so not to affect existing code.

flaskswaggerui-add-server.zip
Cheers
Chris

Question: How to work with several APIs that are defined in separate but private repos?

Is that possible?

Given that I have a shared common repo that defines all the clients common internally used functions like logging, error-handling.

Like to extend this shared common repo to prduce swagger docs from these APIs that are defined in another private repo.

Are there circular dependencies here, since in the API defining repos I do pip install git+http common-shared library

Then I would also do the same pip install git+http in this common shared repo in the same way into the requirements.txt? Any thoughts?

getting error when uploading multiple file upload

i am trying to send multiple file with flask_swager_ui to my flask api sever but facing issues , when i am doing request.files => its giving me an empty dictionary , also its giving data in request.Values but still that is not in good shape and looks like this.

CombinedMultiDict([ImmutableMultiDict([]), ImmutableMultiDict([('name', 'demo_122112'), ('files', '[object File],[object File],[object File]')])])

above output clearly shows that images are not coming in request.files dictionary and going as form data where also their format is little skeptical .

Authorization header not being added/sent when resource method is GET

Hi,
I have two nearly identical swagger JSONs I imported except one is a POST and one is a GET. Same authorization header.

I login/authorize to each yet the one GET method/resource does not send the header or display it in the results (e.g. I don't see it in the example curl command either). But with the POST method it is visible and works.

Can we disable a endpoint?

I know this feature is not in swagger but it will help to have an private endpoint as not part of documentation.

The swagger-ui package is vulnerable to Cross-site Scripting (XSS)

SwaggerUI supports displaying remote OpenAPI definitions through the ?url parameter. This enables robust demonstration capabilities on sites like petstore.swagger.io, editor.swagger.io, and similar sites, where users often want to see what their OpenAPI definitions would look like rendered.

Details: GHSA-qrmm-w75w-3wpx
Is it possible to bump swagger-ui to the latest version v4.1.3?

New release on Pypi

I've seen that the code currently on the master branch allows the use of a blueprint_name parameter, since a PR merged on the 10th of August. I'd need that feature for a project I'm working on.
We are going to use the workaround described here #19 (comment), as it's currently a prototype, but I'd prefer the new version as is more elegant.
¿When are you going to release a new version with this feature?
Thanks!

Swagger ui 3.0.12

There is a bug in swagger ui 3.0.12 (shipped with this extension) that prevents the 'try it out' button from working: swagger-api/swagger-ui#3146

Any chance this could be updated to a newer version of swaggerui? If you are willing to accept a merge request, I could try my hand at it (but I totally understand if you would want to do that yourself, as you couldn't easily validate that the javascript has not been tampered with).

Thanks for the extension!

LICENSE is not in PyPi package

LICENSE file is not included in PyPi package, causing problem when try to add the package to conda-forge repository.

Please add the license file to the package.

Could flask_swagger_ui support base auth?

When the swagger doc can only be accessed by someone who know the username and password, supporting base auth will be necessary.

From the website of flask_swagger_ui, it supports oauth which seems to be complicated for our project's requirement. Could you support base auth in the future release?

Here could be a usage example of base auth.

swagger_blueprint = get_swaggerui_blueprint(
'/api-docs',
'/static/swagger.json',
config={
'app_name': "app-name"
},
basic-auth-config = {users: {'userName': 'password' }}
)

Blocked resources due to wrong MIME type

Hello,

on my local system swagger ui is working great. But when deploying it in our kubernetes cluster the page apears blank. First w arning is raised:
Strict-Transport-Security: The connection to the site is untrustworthy, so the specified header was ignored.
Then an ERROR:
The resource from “https://dev-sitecloud.siemensgamesa.com/v1/elsasafalparser/api/apidocs//swagger-ui-bundle.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
And at the end the page stays blank. Any suggestions?

validatorUrl: None Config

I am trying to set the swagger Validator Url to None.

The recco in java is add 'validatorUrl: null' into the creation of the SwaggerUIBundle.

So for flask-swagger-ui i did:
swagger_ui = get_swaggerui_blueprint(BASE_URI, API_URI, config = {'validatorUrl': None})

And it did not change anything.

I am getting a swagger read error with a valid file from the BASE_URI. The file is reachable and renders a json file directly from the API_URI.

Any ideas?

Blank page when deploying to AWS Lambda

Hi,
I am using zappa to deploy to AWS lambda using API gateway. My swagger URL is as below and endpoint is something like:
https://.execute-api.eu-north-1.amazonaws.com/dev/swagger/
SWAGGER_URL = '/swagger'
When i access this i get a blank page because the swagger resources are being fetched from different URL therefore API gateway gives 403. In below URL /dev is missing.
https://
.execute-api.eu-north-1.amazonaws.com/swagger/swagger-ui-bundle.js

Is the project active?

This project seems interesting. Is there interest to keep the development of this project active? I gave a quick look and seems like it is not up-to-date with the latest version of Swagger UI.

How to add headers in JSON file?

Hello, I need to add headers for my API for it to work in Swagger but I am new to this, how should I add it?

Here is my JSON:

   "swagger":"2.0",
   "info":{
      "description":"This is a CSV translator server.  You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).",
      "version":"1.0.6",
      "title":"Swagger CSV translator",
      "termsOfService":"http://swagger.io/terms/",
      "contact":{
         "email":"[email protected]"
      },
      "license":{
         "name":"Apache 2.0",
         "url":"http://www.apache.org/licenses/LICENSE-2.0.html"
      }
   },
   "host":"127.0.0.1:5000",
   "basePath":"/",
   "tags":[
      {
         "name":"/translate",
         "description":"CSV translator",
         "externalDocs":{
            "description":"Find out more",
            "url":"http://swagger.io"
         }
      },
      {
         "name":"/download-translated-csv",
         "description":"Access to Petstore orders"
      },
      {
         "name":"/download-previously-translated-csv",
         "description":"Operations about user",
         "externalDocs":{
            "description":"Find out more about our store",
            "url":"http://swagger.io"
         }
      }
   ],
   "schemes":[
      "http"
   ],
   "paths":{
      "/translate":{
         "post":{
            "tags":[
               "upload file"
            ],
            "summary":"uploads a CSV",
            "description":"",
            "operationId":"uploadFile",
            "consumes":[
               "multipart/form-data"
            ],
            "produces":[
               "application/json"
            ],
            "parameters":[
               {
                  "name":"file_name",
                  "requestHeaders":{
                  "file_name":{
                     "description":"file name for server",
                     "required":true,
                     "type":"string"
                     }
                  }
               },
               {
                  "name":"file",
                  "in":"formData",
                  "description":"file to upload",
                  "required":true,
                  "type":"file"
               }
            ],
            "responses":{
               "200":{
                  "description":"successful operation"
               },
               "500":{
                  "description":"internal server error"
               }
            },
            "security":[
               {
                  "petstore_auth":[
                     "write:pets",
                     "read:pets"
                  ]
               }
            ]
         }
      },
      "/download-translated-csv":{
         "post":{
            "tags":[
               "download file"
            ],
            "summary":"translate and download the csv",
            "description":"",
            "operationId":"placeOrder",
            "consumes":[
               "application/json"
            ],
            "produces":[
               "application/json"
            ],
            "parameters":[
               {
                  "in":"file_name",
                  "name":"file_name",
                  "description":"file name for server",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               {
                  "in":"language",
                  "name":"language",
                  "description":"language to translate to",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"successful operation",
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               "400":{
                  "description":"Error"
               },
               "503":{
                  "description":"Server is down"
               }
            }
                  
            }
         }
      ,
      "/download-previously-translated-csv":{
         "post":{
            "tags":[
               "download file"
            ],
            "summary":"translate and download the csv",
            "description":"",
            "operationId":"placeOrder",
            "consumes":[
               "application/json"
            ],
            "produces":[
               "application/json"
            ],
            "parameters":[
               {
                  "in":"file_name",
                  "name":"file_name",
                  "description":"file name for server",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               {
                  "in":"language",
                  "name":"language",
                  "description":"language to translate to",
                  "required":true,
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               }
            ],
            "responses":{
               "200":{
                  "description":"successful operation",
                  "schema":{
                     "$ref":"#/definitions/Order"
                  }
               },
               "400":{
                  "description":"Error"
               },
               "503":{
                  "description":"Server is down"
               }
            }
                  
            }
         },
   "securityDefinitions":{
   },
   "definitions":{
      "ApiResponse":{
         "type":"object",
         "properties":{
            "code":{
               "type":"integer",
               "format":"int32"
            },
            "type":{
               "type":"string"
            },
            "message":{
               "type":"string"
            }
         }
      },
      "Category":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "name":{
               "type":"string"
            }
         },
         "xml":{
            "name":"Category"
         }
      },
      "Pet":{
         "type":"object",
         "required":[
            "name",
            "photoUrls"
         ],
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "category":{
               "$ref":"#/definitions/Category"
            },
            "name":{
               "type":"string",
               "example":"doggie"
            },
            "photoUrls":{
               "type":"array",
               "xml":{
                  "wrapped":true
               },
               "items":{
                  "type":"string",
                  "xml":{
                     "name":"photoUrl"
                  }
               }
            },
            "tags":{
               "type":"array",
               "xml":{
                  "wrapped":true
               },
               "items":{
                  "xml":{
                     "name":"tag"
                  },
                  "$ref":"#/definitions/Tag"
               }
            },
            "status":{
               "type":"string",
               "description":"pet status in the store",
               "enum":[
                  "available",
                  "pending",
                  "sold"
               ]
            }
         },
         "xml":{
            "name":"Pet"
         }
      },
      "Tag":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "name":{
               "type":"string"
            }
         },
         "xml":{
            "name":"Tag"
         }
      },
      "Order":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "petId":{
               "type":"integer",
               "format":"int64"
            },
            "quantity":{
               "type":"integer",
               "format":"int32"
            },
            "shipDate":{
               "type":"string",
               "format":"date-time"
            },
            "status":{
               "type":"string",
               "description":"Order Status",
               "enum":[
                  "placed",
                  "approved",
                  "delivered"
               ]
            },
            "complete":{
               "type":"boolean"
            }
         },
         "xml":{
            "name":"Order"
         }
      },
      "User":{
         "type":"object",
         "properties":{
            "id":{
               "type":"integer",
               "format":"int64"
            },
            "username":{
               "type":"string"
            },
            "firstName":{
               "type":"string"
            },
            "lastName":{
               "type":"string"
            },
            "email":{
               "type":"string"
            },
            "password":{
               "type":"string"
            },
            "phone":{
               "type":"string"
            },
            "userStatus":{
               "type":"integer",
               "format":"int32",
               "description":"User Status"
            }
         },
         "xml":{
            "name":"User"
         }
      }
   },
   "externalDocs":{
      "description":"Find out more about Swagger",
      "url":"http://swagger.io"
   }
}
}

I want the translate route's first parameter to be sent as a header.

`base_url` is not used when creating the Blueprint

Ok, this is probably me being thick, but when I do this :

swaggerui_blueprint = get_swaggerui_blueprint(
    '/swagger',
    '/specs',
    config={  # Swagger UI config overrides
        'app_name': "Test application"
    })

app.register_blueprint(swaggerui_blueprint)

The swagger UI is not availalbe on "/swagger".
If I believe the source : https://github.com/sveint/flask-swagger-ui/blob/master/flask_swagger_ui/flask_swagger_ui.py#L14, the base_urlparameter is not used to create the Blueprint. I need to do:

swaggerui_blueprint = get_swaggerui_blueprint(
    '/swagger',
    '/specs',
    config={  # Swagger UI config overrides
        'app_name': "Test application"
    })

swaggerui_blueprint.url_prefix = "/swagger"
app.register_blueprint(swaggerui_blueprint)

if i want to achieve the wanted result. Is there something wrong, or is my understanding of the api incorrect ?

Recommended way to serve .yaml/.json

I'm trying to find the best way to serve locally my swagger.json and set it up to get_swaggerui_blueprint. I'm not Flask fluent and the project I'm working on configured a resource that read the json file, load it into a dict and then returns it. Surely there is a better way.

I believe would be better to have an example serving the swagger.json locally on the README.md, since it's probably the most common use.

Understanding the refresh of swagger files

I'm fairly new to flask and swagger.

When I make changes to the 'swagger.yml' file and refresh the page the displayed swagger page seems to be stuck on an old version of the swagger file. Not the new one.

Why does this happen?

I have tried refreshing the page, force refreshing, restarting the flask app entirely. It just seems to get stuck on various older versions.

Is it to do the new version being invalid?

How can I check the validity of the swagger file?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.