Skip to content

OpenAPI 3.1 nullable compatibility #616

Open

Description

@lusimeon

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`

Activity

  1. added theissue type on May 28, 2025
  2. slax57 commented on May 28, 2025

    @slax57
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions