{"id":14986619,"url":"https://github.com/plainas/flask-swagger-types","last_synced_at":"2025-06-15T01:33:53.703Z","repository":{"id":141711264,"uuid":"212227355","full_name":"plainas/flask-swagger-types","owner":"plainas","description":"A swagger spec generator and type checker for flask","archived":false,"fork":false,"pushed_at":"2023-05-01T21:15:21.000Z","size":26,"stargazers_count":28,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T22:36:55.500Z","etag":null,"topics":["apispec","checker","flask","schemas","swagger","swagger-spec","swagger-ui","types"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plainas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-02T00:47:02.000Z","updated_at":"2021-12-03T12:58:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"414bd617-fb07-4499-bb29-fec1dd9aa4aa","html_url":"https://github.com/plainas/flask-swagger-types","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.25,"last_synced_commit":"2739f3d83a7a808791870a7dd6e0e732c3e34981"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/plainas/flask-swagger-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plainas%2Fflask-swagger-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plainas%2Fflask-swagger-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plainas%2Fflask-swagger-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plainas%2Fflask-swagger-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plainas","download_url":"https://codeload.github.com/plainas/flask-swagger-types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plainas%2Fflask-swagger-types/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259909280,"owners_count":22930586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apispec","checker","flask","schemas","swagger","swagger-spec","swagger-ui","types"],"created_at":"2024-09-24T14:13:14.412Z","updated_at":"2025-06-15T01:33:53.675Z","avatar_url":"https://github.com/plainas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-swagger-types\n\nFlask-swagger-types is a [swagger](https://swagger.io/) spec generator and type checker for flask applications. Define [marshmallow](https://marshmallow.readthedocs.io/en/stable/index.html) schemas for your input data and responses, anotate your routes with `@FlaskSwaggerTypes.Fstroute()` using these schemas, and get a swagger spec free at `[YOUR_APP_URL]/swagger_spec`.\n\nSwagger_ui is exposed for convenience at `[YOUR_APP_URL]/swagger_ui`.\n\nNo hand written swagger spec chunks or monster docstrings non-sense. Your swagger spec is generated from your application semantics. Why wouldn't it, really?\n\n`@FlaskSwaggerTypes.Fstroute()` calls flask's own `@flask.route()` under the hood, so all of Flask's funcionality is preserved and you can mix both anotations in the same application. This is usefull if you want to expose only a subset of your application rules in your swagger spec.\n\nFlask-swagger-types is **not** a flask plugin. It is just a tiny helper with a single anotation definition.\n\n# Installation\n\n```bash\npip3 install https://github.com/plainas/flask-swagger-types/zipball/master\n```\n\n# Example app:\n\n```python\nfrom flask import Flask, request, make_response, Response\nimport marshmallow\nimport pkg_resources\nfrom flaskswaggertypes import FlaskSwaggerTypes\n\n# 1. Define some general info you want included in your spec.\nspec_metadata = {\n    'title': \"My fancy web api\",\n    'description': \"Does some fancy api stuff on my fancy api-y server\" ,\n    #'basePath': \"/sofancy/\", #(optional)\n    'version': \"33\",\n    #'host': \"fancy.example.com\" #(optional)\n}\n\n\n# 2. Define some marshmallow schemas \nclass Pants(marshmallow.Schema):\n    _id = marshmallow.fields.Int()\n    name = marshmallow.fields.String()\n    brand = marshmallow.fields.String() \n    size = marshmallow.fields.Int()\n    \n# You can define collections by nesting an existing type with Nested()\nclass PantsList(marshmallow.Schema):\n    pants = marshmallow.fields.Nested(Pants, many=True)\n\n\n# responses are defined like so:\nresponses = [\n    [ 200 , \"Server will reply with 200 to successfull calls\" ],\n    [ 400 , \"Just mentioning that calls to this api method could go south\"],\n]\n\n# you can optionally pass the response Schema\nresponses_with_type = [\n    [ 200 , \"Server will reply with 200 to successfull calls\", PantsList ],\n    [ 400 , \"Server will repply with 400 if it rails to retrieve a list of pants\" ],\n]\n\n\n# 3. Create your flask app as usual\napp = Flask(__name__)\n\n# 4. Initialize flask-swagger-types\nfst = FlaskSwaggerTypes(app, spec_metadata)\n\n# 5. Define some routes with @Fstroute()\n@fst.Fstroute('/savePants', \"POST\", {'body' : Pants }, responses)\ndef saveYourFancyPants():\n    # Parsed and validated data will be available at\n    print(request.fst_data)\n    #...\n    return \"Success!!!\"\n\n\n# path paramters are parsed and will automatically show up in your swagger spec \n# without the need to manually pass its schema. \n@fst.Fstroute('/getManyPants/\u003cint:size\u003e/\u003cstring:brand\u003e', \"GET\", {}, responses )\ndef getManyFancyPants(size, brand):\n    print(request.fst_data)\n    # ...\n    return \"your pants list here\"\n\n\n@fst.Fstroute('/getFancyPants', \"GET\", {}, responses_with_type)\ndef getFancyPants():\n    pantslistschema = PantsList()\n    empty_list = pantslistschema.dumps([])\n    return empty_list\n\n\n# 6. Start your flask app as usual\napp.run()\n# Your swagger spec can now be accessed at [YOUR_APP_URL]/swagger_spec\n# To browse your api with swager-ui, go to [YOUR_APP_URL]/swagger_ui?url=/swagger_spec#/default\n```\n\n## Api reference\n    #TODO.\n    The sample app should cover what you need. If not, read the source. It's less than 200 lines of code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplainas%2Fflask-swagger-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplainas%2Fflask-swagger-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplainas%2Fflask-swagger-types/lists"}