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

OpenAPI JSON should use additionalProperties #74

Closed
jonfreedman opened this issue May 24, 2019 · 3 comments
Closed

OpenAPI JSON should use additionalProperties #74

jonfreedman opened this issue May 24, 2019 · 3 comments

Comments

@jonfreedman
Copy link

jonfreedman commented May 24, 2019

OpenAPI v3 supports dictionaries to be specified with a key / value type. The following Marshamallow classes produce JSON without that information

@api.schema('Output')
class OutputSchema(ma.Schema):
    class Meta:
        strict = True

    min = ma.fields.Number()
    max = ma.fields.Number()


@api.schema('OutputDict')
class OutputDictSchema(ma.Schema):
    class Meta:
        strict = True

    data = ma.fields.Dict(keys=ma.fields.String(), values=ma.fields.Nested(OutputSchema))

Should produce something like this:

      "Output": {
        "type": "object",
        "properties": {
          "min": {
            "type": "number"
          },
          "max": {
            "type": "number"
          }
        }
      },
      "OutputDict": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string"
                },
                "text": {
                "$ref": "#/components/schemas/Output"
                }
              }
            }
          }
        }
@lafrech
Copy link
Member

lafrech commented May 24, 2019

I think it should work since marshmallow-code/apispec#202.

Looks like you're using Marshmallow 2. The keys and values arguments in Dict were added in Marshmallow 3. In Marshmallow 2, they are just ignored.

In Marshmallow 3, strict = True is removed and triggers warnings.

@jonfreedman
Copy link
Author

jonfreedman commented May 25, 2019 via email

@lafrech
Copy link
Member

lafrech commented Jun 11, 2019

Closing this. What you're seeing is normal marshmallow 2 behaviour.

We'll reopen if it doesn't work with marshmallow 3.

@lafrech lafrech closed this as completed Jun 11, 2019
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

2 participants