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
When trying to overwrite the type of a property with OA\Property attribute - using type or ref successfully replaced the types defined by the php itself. However when using oneOf, anyOf or allOf - those are instead merged with the PHP type definitions and it's impossible to overwrite them from attribute alone. The only way to overwrite them is to define them as schema in the config file and use a ref to point to the new schema. This is because of this line:
However some validators like thephpleague/openapi-psr7-validator match integers to both type interger and type number which makes the validation of the schema of integer input invalid (it's one of, not any of and it matches 2 schemas).
To overcome this I try overwriting it like this:
#[OA\Property(anyOf: [
new OA\Schema(type: 'null'),
new OA\Schema(type: 'number'),
new OA\Schema(type: 'boolean'),
new OA\Schema(type: 'integer'),
new OA\Schema(type: 'string'),
])]
public null|float|bool|int|string $value,
#[OA\Property(oneOf: [
new OA\Schema(type: 'number'),
new OA\Schema(type: 'boolean'),
new OA\Schema(type: 'string', nullable: true),
])]
public null|float|bool|int|string $value,
Just today I stumbled over the exact same issue. In my case it was even weirder as parts of the merged schema came from the getters and the setters of the property.
Version
4.26.1
Description
When trying to overwrite the type of a property with
OA\Property
attribute - usingtype
orref
successfully replaced the types defined by the php itself. However when usingoneOf
,anyOf
orallOf
- those are instead merged with the PHP type definitions and it's impossible to overwrite them from attribute alone. The only way to overwrite them is to define them as schema in the config file and use aref
to point to the new schema. This is because of this line:NelmioApiDocBundle/src/ModelDescriber/ObjectModelDescriber.php
Line 174 in 9379c44
type
andref
. A very easy fix is to add the above 3 in the check.Now why I need this? I have the following situation:
This generates the following spec:
However some validators like
thephpleague/openapi-psr7-validator
match integers to both typeinterger
and typenumber
which makes the validation of the schema of integer input invalid (it's one of, not any of and it matches 2 schemas).To overcome this I try overwriting it like this:
However this results into this spec:
Even if I use
oneOf
with less types like this:It merges them like that:
So I cannot overwrite it with
anyOf
,oneOf
orallOf
. The only solution is to define in the config a schema like this:And reference it like this:
Additional context
No response
The text was updated successfully, but these errors were encountered: