aubergine-developers / nadia

Small and lightweight library for creating marshmallow Schemas for objects defined in OpenAPI 3 specs.
MIT License
1 stars 0 forks source link

Support for oneOf, anyOf and allOf keywords #5

Open dexter2206 opened 6 years ago

dexter2206 commented 6 years ago

Nadia should support combining schemas using oneOf, anyOf and allOf keywords.

The official OpenAPI docs can be used to provide examples/unit tests cases for this feature:

magdanowak commented 5 years ago

@dexter2206 The way nadia is set up now, if we try validating a anyOf/allOf schema, it's not possible for the single schemas to be valid, unless they are identical. check_unknown_fields will not recognize fields from the different schema, and raise an error.

Example:

  PetByAnythingWithoutRefs:
    anyOf:
      - type: object
        properties:
          age:
            type: integer
          nickname:
            type: string
        required:
          - age
      - type: object
        properties:
          pet_type:
            type: string
          hunts:
            type: integer
        required:
          - pet_type

If this schema receives an object with age and pet_type, each single schema should fail, since there are extra fields. We need to rethink the strategy here.

dexter2206 commented 5 years ago

@magdanowak This is true, and it stems from the fact I incorrectly implemented schemas as if they had additionalProperties set to false. It should be quite opposite, OpenAPI specification says that additionalProperties has the default value of true. I will think how to correctly handle additionalProperties respecting its default value, and I think that doing so should fix the problem you described.

magdanowak commented 5 years ago

Okay, so let's separate this issue. I'll create a MR for the support of oneOf etc., let's just remember that it will use the current validate method to validate each schema, resulting in wrong values. Let's not merge until the issue with additionalProperties is fixed, so that I can make proper tests.