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

support additionalProperties false #26

Closed
podhmo opened this issue Oct 14, 2017 · 4 comments · Fixed by #80
Closed

support additionalProperties false #26

podhmo opened this issue Oct 14, 2017 · 4 comments · Fixed by #80

Comments

@podhmo
Copy link
Owner

podhmo commented Oct 14, 2017

No description provided.

@podhmo
Copy link
Owner Author

podhmo commented Nov 4, 2020

This behavior can be modified with the unknown option, which accepts one of the following:

  • RAISE (default): raise a ValidationError if there are any unknown fields
  • EXCLUDE: exclude unknown fields
  • INCLUDE: accept and include the unknown fields

https://marshmallow.readthedocs.io/en/stable/quickstart.html#handling-unknown-fields

@podhmo
Copy link
Owner Author

podhmo commented Nov 4, 2020

default is RAISE

@podhmo
Copy link
Owner Author

podhmo commented Nov 4, 2020

Now, the default output is changed

# this is auto-generated by swagger-marshmallow-codegen
from __future__ import annotations
from marshmallow import (
    Schema,
    fields,
    INCLUDE,
    RAISE,
)


class Person(Schema):
    name = fields.String(required=True)

    class Meta:
        unknown = INCLUDE



class Person_AdditionalProperties_True(Schema):
    name = fields.String(required=True)

    class Meta:
        unknown = INCLUDE



class Person_AdditionalProperties_False(Schema):
    name = fields.String(required=True)

    class Meta:
        unknown = RAISE

from

{
  "version": "2.0.0",
  "definitions": {
    "Person": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ]
    },
    "Person_AdditionalProperties_True": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": true
    },
    "Person_AdditionalProperties_False": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": false
    }
  }
}

@podhmo
Copy link
Owner Author

podhmo commented Nov 4, 2020

if you need strict output -- this is old behavior, add --strict-additional-properties option.

$ swagger-marshmallow-codegen 01person.yaml --strict-additional-properties 01person.yaml
# this is auto-generated by swagger-marshmallow-codegen
from __future__ import annotations
from marshmallow import (
    Schema,
    fields,
    INCLUDE,
    RAISE,
)


class Person(Schema):
    name = fields.String(required=True)


class Person_AdditionalProperties_True(Schema):
    name = fields.String(required=True)

    class Meta:
        unknown = INCLUDE



class Person_AdditionalProperties_False(Schema):
    name = fields.String(required=True)

    class Meta:
        unknown = RAISE

need Meta.unknown even Person class, run with --explicit option

@podhmo podhmo closed this as completed in #80 Nov 4, 2020
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

Successfully merging a pull request may close this issue.

1 participant