Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type for OpenApi spec #5975

Closed
DjordyKoert opened this issue Nov 17, 2023 · 0 comments
Closed

Incorrect type for OpenApi spec #5975

DjordyKoert opened this issue Nov 17, 2023 · 0 comments

Comments

@DjordyKoert
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant