OpenAPI 3.1 nullable compatibility
Description
OpenAPI 3.1 specification defines Schemas properties nullable types as described below to follow JSON Schema 4.
API Platform Admin openAPI schema Analyzer does not process nullable type and fallback to string type instead of extracting type from the non-nullable type. This introduces wrong input type when using Component like InputGuesser for example.
Schema Analyzer should take into account nullable types.
Example
# OpenAPI specification example
[…]
properties:
myProperty:
type:
- integer
- null
# Before fix
schemaAnalyze field type is `string`
# After fix
schemaAnalyzer field type is `integer`
Thanks for the report.
I managed to reproduce in the example api included in this repo by making the following changes in Review.php:
/** The rating of this review (between 0 and 5) */
// #[ORM\Column(type: 'smallint')]
// #[Assert\Range(min: 0, max: 5)]
public ?int $rating = 0;
Debugging the JS code shows that getFieldType is called with field where field.type is an array ['integer', 'null']. Hence the resolved type is 'text'.
schemaAnalyzer.ts will probably need to be updated to account for nullable types, however, to me, this issue first needs to be addressed in api-doc-parser, as their TS type still suggests that field.type can only be string | null | undefined, which is wrong.
Would you mind opening an issue on the https://github.com/api-platform/api-doc-parser repo to request fixing the TS type and/or the parsing logic?
I'm mentioning the parsing logic because I see in the TS type there is also a nullable field, but it is incorrectly false in this case.
{
"name": "rating",
"id": null,
"range": null,
"type": {
"0": "integer",
"1": "null"
},
"arrayType": null,
"enum": null,
"reference": null,
"embedded": null,
"nullable": false,
"required": false,
"description": ""
}
Thanks