grktsh / falcon-oas

Design first approach with OpenAPI 3 for Falcon
Apache License 2.0
7 stars 4 forks source link

Support nullable array items #3

Closed sisp closed 5 years ago

sisp commented 5 years ago

I believe OpenAPI supports nullable also for array items. falcon-oas currently does not honor nullable inside array items:

type: array
items:
  nullable: true
  ...

To support this, another custom validator for items needs to be added like this one: https://github.com/grktsh/falcon-oas/blob/0328d7f4c0c806bc2cdd9c45f5c720a1ec61cbc4/src/falcon_oas/oas/schema/validators.py#L11-L19

I'd be happy to create a PR if you agree that array items can be nullable according to OpenAPI 3.

grktsh commented 5 years ago

I think this is already supported. Here is the test case:

def test_unmarshal_nullable_array_items():
    schema = {
        'type': 'array',
        'items': {
            'nullable': True,
            'type': 'string',
            'format': 'date',
        },
    }
    instance = [None, '2018-01-02']
    unmarshaled = SchemaUnmarshaler().unmarshal(instance, schema)
    assert unmarshaled == [None, datetime.date(2018, 1, 2)]
sisp commented 5 years ago

It seems you're right. Sorry.

I had a case with a nullable enum and nullable array items for which the entire schema failed (because multiple sub-schemas are combined with anyOf) and I somehow concluded that support for both nullable cases was missing. But it's working only with added nullable enum support.