You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 fixschemaAnalyze field type is `string`# After fixschemaAnalyzer field type is `integer`
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.
Activity
slax57 commentedon May 28, 2025
Thanks for the report.
I managed to reproduce in the example api included in this repo by making the following changes in
Review.php:Debugging the JS code shows that
getFieldTypeis called withfieldwherefield.typeis an array['integer', 'null']. Hence the resolved type is'text'.schemaAnalyzer.tswill probably need to be updated to account for nullable types, however, to me, this issue first needs to be addressed inapi-doc-parser, as their TS type still suggests thatfield.typecan only bestring | 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
nullablefield, but it is incorrectlyfalsein 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