Skip to content

fix(openapi): do not use jsonld schema for all media types#4247

Merged
alanpoulain merged 5 commits into
api-platform:2.6from
guilliamxavier:fix-4215
May 6, 2021
Merged

fix(openapi): do not use jsonld schema for all media types#4247
alanpoulain merged 5 commits into
api-platform:2.6from
guilliamxavier:fix-4215

Conversation

@guilliamxavier

Copy link
Copy Markdown
Contributor
Q A
Branch? 2.6
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #4215
License MIT
Doc PR

Follows #4213

Comment on lines +197 to +207
And the JSON node "paths./dummies.get.responses.200.content.application/json" should be equal to:
"""
{
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Dummy"
}
}
}
"""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step was failing (the schema was the same as jsonld above)

Comment thread src/JsonSchema/SchemaFactory.php Outdated
public function buildSchema(string $className, string $format = 'json', string $type = Schema::TYPE_OUTPUT, ?string $operationType = null, ?string $operationName = null, ?Schema $schema = null, ?array $serializerContext = null, bool $forceCollection = false): Schema
{
$schema = $schema ?? new Schema();
$schema = null !== $schema ? clone $schema : new Schema();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$schema ? clone $schema : new Schema() would work as well right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this comment. Thanks for proposing a suggestion, I've just accepted it

Comment on lines -257 to -259
$schema = new Schema('openapi');
$schema->setDefinitions($schemas);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was added by #4213, not needed anymore

$this->jsonSchemaFactory->buildSchema($resourceClass, $format, $type, $operationType, $operationName, $schema, $serializerContext, $forceCollection);

return $schema;
return $this->jsonSchemaFactory->buildSchema($resourceClass, $format, $type, $operationType, $operationName, $schema, $serializerContext, $forceCollection);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a consequence of the fix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soyuka: Refs #4215 (comment). I have added a note to the changelog entry

@guilliamxavier guilliamxavier changed the title Fix OpenAPI using jsonld for all media types Fix OpenAPI uses jsonld for all media types Apr 26, 2021

@alanpoulain alanpoulain left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alanpoulain alanpoulain requested a review from soyuka April 27, 2021 13:37
@guilliamxavier guilliamxavier changed the title Fix OpenAPI uses jsonld for all media types fix(openapi): do not use jsonld schema for all media types Apr 30, 2021
Comment thread CHANGELOG.md Outdated
Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>
@guilliamxavier guilliamxavier requested a review from soyuka April 30, 2021 13:38
Comment thread src/JsonSchema/SchemaFactory.php Outdated
Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>
@alanpoulain alanpoulain merged commit 7d99161 into api-platform:2.6 May 6, 2021
@alanpoulain

Copy link
Copy Markdown
Member

Thank you @guilliamxavier.

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

Successfully merging this pull request may close these issues.

3 participants