4

I'd like to create a separate definitions.yml file using json remote references, so I can share the definitions across multiple YML files.

We followed the instructions in https://azimi.me/2015/07/16/split-swagger-into-smaller-files.html by moving the definitions section to a separate file. The mimimal YML file looks like:

api.yml:

responses:
  '200':
    description: "A user."
    schema:
      $ref: "#/definitions/User"
definitions:
  $ref: "./definitions.yml"

definitions.yml

User:
  type: string

somefile.py

from flasgger import swag_from
...
# use BluePrint to specify API
@swag_from('api.yml')

command

flask run

The expected localhost:5000/apidocs result would have a complete API for the GET, with User defined as a model. The actual result shows that '#/definitions/User' was not found, and the models are missing.

Does flasgger support this?

arthuston
  • 227
  • 1
  • 3
  • 10

2 Answers2

3

You can import file

definitions:
  import: "./definitions.yml"
Koluchi
  • 39
  • 3
  • 1
    Just a heads up this will only work if definitions.yml is in the root of your flask project. Otherwise provide the relative path from your project root to definitions.yml. Not the relative path from your other swagger yaml files. – Karaja Nov 11 '21 at 17:52
2

The current version of flassger (0.9.3) does not support including external yaml files, however, it would be possible to pre-process the files to include the external references, either inside the flask script or before running the flask script. Here's an example of a solution for connexion: https://github.com/zalando/connexion/issues/254#issuecomment-497194240

arthuston
  • 227
  • 1
  • 3
  • 10