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

[JSON Schema] Manage correctly nullability #3817

Merged

Conversation

alanpoulain
Copy link
Member

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tickets N/A
License MIT
Doc PR N/A

Following #3402 and the list of PR from #3807.

In order to validate correctly nullable data against the generated JSON Schema (using assertMatchesResourceItemJsonSchema and assertMatchesResourceCollectionJsonSchema), the schema needs to be compliant with the specification for nullability:

{"type": ["string", "null"]}

However OpenAPI < 3.1 doesn't understand this syntax (OpenAPI 3.1 will at least! https://github.com/OAI/OpenAPI-Specification/releases/tag/3.1.0-rc0) and only understands:

{"type": "string", "nullable": true}

That's why we need a condition when the schema is generated for JSON Schema only.

@Ocramius you may be interested.

@Ocramius
Copy link
Contributor

Ocramius commented Nov 6, 2020

Overall OK for me - would be easier to just say that we generate OpenAPI 3.1 schema here though 🤷

@alanpoulain
Copy link
Member Author

Not really because we are not in an OpenAPI context here (pure JSON Schema use). However we could also introduce a new key for OpenAPI 3.1, like you suggested in your PR. But maybe when it will be released, don't you think?

@Ocramius
Copy link
Contributor

Ocramius commented Nov 6, 2020

Wait... OpenAPI 3.1 is still not out yet? :O

@alanpoulain
Copy link
Member Author

@soyuka
Copy link
Member

soyuka commented Nov 7, 2020

Anyways we're going to support only the latest openapi version, by that I mean that we're probably not going to handle multiple open api versions, too hard to maintain.

@alanpoulain you should also try this on master as the OpenAPI code has been refactored there.

@alanpoulain
Copy link
Member Author

🤔 The code is exactly the same on master, isn't it?

return array_merge($jsonSchema, ['nullable' => true]);

I think it would be merged without conflicts.

@soyuka
Copy link
Member

soyuka commented Nov 8, 2020

The code for the schema yes the code for the open api generation no.

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 this pull request may close these issues.

3 participants