Skip to content

Incorrect type for OpenApi spec #5975

Description

@DjordyKoert

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)

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