podhmo / swagger-marshmallow-codegen

generating marshmallow's schema from swagger definition file
MIT License
52 stars 10 forks source link

handle additionalProperties correctly #67

Closed podhmo closed 3 years ago

podhmo commented 3 years ago
podhmo commented 3 years ago

jsonschema (and openAPI), default value of additionalProperties is true. then

class S(Schema):
    class Meta:
        unknown = INCLUDE
podhmo commented 3 years ago

default marshmallow's behavior is same as following

class S(Schema):
    class Meta:
        unknown = RAISE

This is additionalProperties is false 's behavior

podhmo commented 3 years ago

If schema (openAPI) has not properties. We can use DictField.

definitions:
  S:
    addtionalProperties:
      type: string
podhmo commented 3 years ago

if schema has properties, special Schema class is needed (This is current AdditionalPropetiesSchema)

class S(AdditionalPropertiesSchema):
    name = fields.String()

    class Meta:
        additional_field = fields.Integer()
podhmo commented 3 years ago

And if top-level definition even no properties, special Schema class is needed. (this is same as type array, and type primitive value)