API Platform version(s) affected: 3.2
Description
According to the OpenApi 3.1 specification type cannot contain a list of types. Instead the oneOf, allOf or anyOf key should be used when describing an union/intersection type on a property.
Instead of doing this #5470 changed the behaviour to generate a list of types (invalid) instead.
3.1:
|
switch ($schema->getVersion()) { |
|
case Schema::VERSION_JSON_SCHEMA: |
|
$nullableStringDefinition = ['type' => ['string', 'null']]; |
|
break; |
|
case Schema::VERSION_OPENAPI: |
|
$nullableStringDefinition = ['type' => 'string', 'nullable' => true]; |
|
break; |
|
} |
3.2:
|
switch ($schema->getVersion()) { |
|
// JSON Schema + OpenAPI 3.1 |
|
case Schema::VERSION_OPENAPI: |
|
case Schema::VERSION_JSON_SCHEMA: |
|
$nullableStringDefinition = ['type' => ['string', 'null']]; |
|
break; |
|
// Swagger |
|
default: |
|
$nullableStringDefinition = ['type' => 'string']; |
|
break; |
|
} |
How to reproduce
Using the OpenApiFactory to generate documentation and passing this to swagger-php causes an TypeError to be thrown by PHP because an array (list of types) is given instead of the expected string type.
TypeError: OpenApi\Analysis::getSchemaForSource(): Argument #1 ($fqdn) must be of type string, array given
https://github.com/zircote/swagger-php/blob/595d8b63a589e6ac0835c83a45304c7397dc37d1/src/Analysis.php#L326
Possible Solution
A simple rollback on the highlighted code to the version 3.1 variant should fix this issue.
Additional Context
Related issue: zircote/swagger-php#1464.
PHPUnit failure: nelmio/NelmioApiDocBundle#2141 (comment)
API Platform version(s) affected: 3.2
Description
According to the OpenApi 3.1 specification
typecannot contain a list of types. Instead theoneOf,allOforanyOfkey should be used when describing an union/intersection type on a property.Instead of doing this #5470 changed the behaviour to generate a list of types (invalid) instead.
3.1:
core/src/Hydra/JsonSchema/SchemaFactory.php
Lines 96 to 103 in c617b18
3.2:
core/src/Hydra/JsonSchema/SchemaFactory.php
Lines 94 to 104 in 002c8b2
How to reproduce
Using the
OpenApiFactoryto generate documentation and passing this toswagger-phpcauses anTypeErrorto be thrown by PHP because an array (list of types) is given instead of the expectedstringtype.TypeError: OpenApi\Analysis::getSchemaForSource(): Argument #1 ($fqdn) must be of type string, array givenhttps://github.com/zircote/swagger-php/blob/595d8b63a589e6ac0835c83a45304c7397dc37d1/src/Analysis.php#L326
Possible Solution
A simple rollback on the highlighted code to the version 3.1 variant should fix this issue.
Additional Context
Related issue: zircote/swagger-php#1464.
PHPUnit failure: nelmio/NelmioApiDocBundle#2141 (comment)