Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dictionary value schema definition in Swagger spec #310

Open
kathleenkusworo opened this issue Mar 27, 2024 · 0 comments
Open

Add dictionary value schema definition in Swagger spec #310

kathleenkusworo opened this issue Mar 27, 2024 · 0 comments

Comments

@kathleenkusworo
Copy link

kathleenkusworo commented Mar 27, 2024

Right now, I believe Dict fields are renderd as a generic Swagger object without further info of the dictionary values' schema. The code in Flask-Rebar is here.

Let's say we have the following Marshmallow schema:

class ComplexDict(Schema):
  dictionary = fields.Dict(
     keys=fields.String(),
     values=fields.Nested(ComplexObject),
     required=True,
  )

Based on Swagger 2.0 docs, the canonical way to define a String -> ComplexModel dictionary would be:

ComplexDict:
  type: object
  additionalProperties:
    $ref: '#/definitions/ComplexModel'

But, Flask-rebar will only render it as:

ComplexDict:
  type: object

We have been using a custom converter to work around this, see code snippet here. We can reasonably get to a point where we keep unfurling the definition of ComplexModel directly in-line within additionalProperties, like:

ComplexDict:
  type: object
  additionalProperties:
    items:
       additionalProperties: false
       description: The complex model
       properties:
           id:
              type: string
       type: object
       title: ComplexModel

but it will be ideal to get to a point where it makes a reference to the definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant