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

Nullable combined with allOf issue #1550

Closed
bnowak opened this issue Feb 29, 2024 · 1 comment
Closed

Nullable combined with allOf issue #1550

bnowak opened this issue Feb 29, 2024 · 1 comment

Comments

@bnowak
Copy link
Contributor

bnowak commented Feb 29, 2024

Hello,

I've got an issue in my project (where we're using https://github.com/nelmio/NelmioApiDocBundle with OAS 3.1 version) connected to nullable enums.

Currently for OAS 3.1 version it's rendered to spec as:

'nullableEnumType' => [
    'allOf' => [
        ['$ref' => '#/components/schemas/ArticleType81'], // enum ref
        ['type' => 'null'],
    ]
],

but it's impossible to match both types at the same time. We're using https://github.com/opis/json-schema to validate API data responses against API model schema and it reports above issue.

In OAS version 3.0 there's nullable field and it's used properly:

'nullableEnumType' => [
    'nullable' => true,
    'allOf' => [
        ['$ref' => '#/components/schemas/ArticleType81'], // enum ref
    ],
],

I think for OAS 3.1 we should wrap such nullable-allOf schemas with additional oneOf level to be something like:

'nullableEnumType' => [
    'oneOf' => [
        [
          'allOf' => [
              ['$ref' => '#/components/schemas/ArticleType81'], // enum ref
          ],
        ],
        ['type' => 'null'],
    ]
],

It seems that could be more general issue - not only connected to enums. Also, proposed solution IMO seems to be general as well.

I'll test it shortly and will prepare PR for it.

@bnowak
Copy link
Contributor Author

bnowak commented Mar 8, 2024

I'm closing it as the root cause was in Nelmio api doc bundle and was solved there.

@bnowak bnowak closed this as completed Mar 8, 2024
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

1 participant