-
-
Notifications
You must be signed in to change notification settings - Fork 933
Closed
Closed
Copy link
Description
Description
With the Operation override
openapi: new Operation(
description: 'Foo',
summary: 'Foo',
requestBody: new RequestBody('Bar'),
responses: [
200 => new Response('Bar'),
]
),
Which means
- I can override the description and the summary of an operation and still having the OpenApiFactory filling the requestBody/responses
- I can override the description of the request body and still having the OpenApiFactory filling the content of the requestBody
- I can override a response code 200 and still having other responses code in the api doc
- As soon as I override a response code description I'm loosing the content
This is because of this check https://github.com/api-platform/core/blame/510fa5523802f9c173d852c218317f95f9ef2d90/src/OpenApi/Factory/OpenApiFactory.php#L503-L505
While a null check on the content is done for the request body
core/src/OpenApi/Factory/OpenApiFactory.php
Lines 452 to 476 in 510fa55
if ( | |
\in_array($method, ['PATCH', 'PUT', 'POST'], true) | |
&& !(false === ($input = $operation->getInput()) || (\is_array($input) && null === $input['class'])) | |
) { | |
$content = $openapiOperation->getRequestBody()?->getContent(); | |
if (null === $content) { | |
$operationInputSchemas = []; | |
foreach ($requestMimeTypes as $operationFormat) { | |
$operationInputSchema = null; | |
if (str_starts_with($operationFormat, 'json')) { | |
$operationInputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection); | |
$this->appendSchemaDefinitions($schemas, $operationInputSchema->getDefinitions()); | |
} | |
$operationInputSchemas[$operationFormat] = $operationInputSchema; | |
} | |
$content = $this->buildContent($requestMimeTypes, $operationInputSchemas); | |
} | |
$openapiOperation = $openapiOperation->withRequestBody(new RequestBody( | |
description: $openapiOperation->getRequestBody()?->getDescription() ?? \sprintf('The %s %s resource', 'POST' === $method ? 'new' : 'updated', $resourceShortName), | |
content: $content, | |
required: $openapiOperation->getRequestBody()?->getRequired() ?? true, | |
)); | |
} |
since the PR #6374
Would you be open to a similar behavior @soyuka for Response ?
Example
Code should be changed to something like
private function buildOpenApiResponse(array $existingResponses, int|string $status, string $description, ?Operation $openapiOperation = null, ?HttpOperation $operation = null, ?array $responseMimeTypes = null, ?array $operationOutputSchemas = null, ?ResourceMetadataCollection $resourceMetadataCollection = null): Operation
{
$noOutput = \is_array($operation?->getOutput()) && null === $operation->getOutput()['class'];
$response = $existingResponses[$status] ?? null;
$responseContent = $response?->getContent();
if (null === $responseContent && $responseMimeTypes && $operationOutputSchemas && !$noOutput) {
$responseContent = $this->buildContent($responseMimeTypes, $operationOutputSchemas);
}
$responseLinks = $response?->getLinks();
if (null === $responseLinks && $resourceMetadataCollection && $operation) {
$responseLinks = $this->getLinks($resourceMetadataCollection, $operation);
}
return $openapiOperation->withResponse($status, new Response($description, $responseContent, $response?->getHeaders(), $responseLinks));
}
Metadata
Metadata
Assignees
Labels
No labels