Skip to content

[OpenAPI] Typing Issue with openapiContext in #[ApiProperty] Leading to any in Documentation #6893

Closed
@SebLevDev

Description

@SebLevDev

API Platform version(s) affected: 4.x

Description
When I specify an openapiContext in my #[ApiProperty], the typing of the same property is no longer used, and I am forced to explicitly specify it within the openapiContext array.

As a result, both Swagger and ReDoc documentation display the field as any.

We have observed this issue with several strictly typed fields in PHP, such as bool, DateTimeImmutable, and others.

How to reproduce
this configuration provide a any type in the documentation

#[ApiProperty(
    openapiContext: [
        'description' => 'The date on which the Article was created or the item was added to a feed.'
    ],
    types: ['https://schema.org/datePublished']
)]
#[Groups(['Article:Read:List'])]
public ?\DateTimeImmutable $publishedAt = null,

Additional Context
Here is the dump of $propertySchema in ApiPlatform\JsonSchema\SchemaFactory

array:2 [▼
  "externalDocs" => array:1 [▼
    "url" => "https://schema.org/datePublished"
  ]
  "description" => "The date on which the News was created or the item was added to a feed."
]

if i remove the openapiContext in my ApiProperty attribute

#[ApiProperty]
#[Groups(['Article:Read:List'])]
public ?\DateTimeImmutable $publishedAt = null,

The dump returned is good

array:2 [▼
  "type" => array:2 [▼
    0 => "string"
    1 => "null"
  ]
  "format" => "date-time"
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions