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

Add support for content to Parameter attribute #1344

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Annotations/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Parameter extends AbstractAnnotation
* The key is the media type and the value describes it.
* The map must only contain one entry.
*
* @var MediaType[]
* @var array<MediaType>|JsonContent|XmlContent|Attachable
*/
public $content = Generator::UNDEFINED;

Expand Down
10 changes: 6 additions & 4 deletions src/Attributes/ParameterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
trait ParameterTrait
{
/**
* @param array<string,Examples> $examples
* @param array<string,mixed>|null $x
* @param Attachable[]|null $attachables
* @param array<string,Examples> $examples
* @param array<MediaType>|JsonContent|XmlContent|Attachable|null $content
* @param array<string,mixed>|null $x
* @param Attachable[]|null $attachables
*/
public function __construct(
?string $parameter = null,
Expand All @@ -27,6 +28,7 @@ public function __construct(
?Schema $schema = null,
mixed $example = Generator::UNDEFINED,
?array $examples = null,
array|JsonContent|XmlContent|Attachable|null $content = null,
?string $style = null,
?bool $explode = null,
?bool $allowReserved = null,
Expand All @@ -52,7 +54,7 @@ public function __construct(
'spaceDelimited' => $spaceDelimited ?? Generator::UNDEFINED,
'pipeDelimited' => $pipeDelimited ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($schema, $examples, $attachables),
'value' => $this->combine($schema, $examples, $content, $attachables),
]);
}
}
2 changes: 1 addition & 1 deletion tests/Annotations/AttributesSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AttributesSyncTest extends OpenApiTestCase
{
public static $SCHEMA_EXCLUSIONS = ['const', 'maxProperties', 'minProperties', 'multipleOf', 'not', 'additionalItems', 'contains', 'patternProperties', 'dependencies', 'propertyNames'];
public static $PATHITEM_EXCLUSIONS = ['ref', 'get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'];
public static $PARAMETER_EXCLUSIONS = ['content', 'matrix', 'label', 'form', 'simple', 'deepObject'];
public static $PARAMETER_EXCLUSIONS = ['matrix', 'label', 'form', 'simple', 'deepObject'];

public function testCounts(): void
{
Expand Down
37 changes: 37 additions & 0 deletions tests/Fixtures/Scratch/ParameterContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

use OpenApi\Attributes as OAT;

/**
* An API endpoint.
*/
#[OAT\Info(
title: 'Parameter Content Scratch',
version: '1.0'
)]
#[OAT\Get(
path: '/api/endpoint',
tags: ['endpoints'],
description: 'An endpoint',
operationId: 'endpoint',
parameters: [
new OAT\Parameter(
name: 'filter',
in: 'query',
content: new OAT\JsonContent(
properties: [
new OAT\Property(property: 'type', type: 'string'),
new OAT\Property(property: 'color', type: 'string'),
]
)
),
],
responses: [new OAT\Response(response: 200, description: 'OK')]
)]
class Endpoint
{
}
26 changes: 26 additions & 0 deletions tests/Fixtures/Scratch/ParameterContent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
openapi: 3.0.0
info:
title: 'Parameter Content Scratch'
version: '1.0'
paths:
/api/endpoint:
get:
tags:
- endpoints
summary: 'An API endpoint.'
description: 'An endpoint'
operationId: endpoint
parameters:
-
name: filter
in: query
content:
application/json:
schema:
properties:
type: { type: string }
color: { type: string }
type: object
responses:
'200':
description: OK
2 changes: 1 addition & 1 deletion tests/ScratchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function scratchTests(): iterable
*
* @dataProvider scratchTests
*
* @requires PHP 7.4
* @requires PHP 8.1
*/
public function testScratch(string $version, string $scratch, string $spec, array $expectedLog): void
{
Expand Down