|
15 | 15 |
|
16 | 16 | use ApiPlatform\Metadata\Exception\InvalidArgumentException;
|
17 | 17 | use ApiPlatform\Metadata\GetCollection;
|
| 18 | +use ApiPlatform\Metadata\HeaderParameter; |
18 | 19 | use ApiPlatform\Metadata\Post;
|
| 20 | +use ApiPlatform\Metadata\QueryParameter; |
19 | 21 | use ApiPlatform\Metadata\Tests\Fixtures\StateOptions;
|
20 | 22 | use ApiPlatform\OpenApi\Model\ExternalDocumentation;
|
21 | 23 | use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
|
22 |
| -use ApiPlatform\OpenApi\Model\Parameter; |
| 24 | +use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter; |
23 | 25 | use ApiPlatform\OpenApi\Model\RequestBody;
|
24 | 26 | use ApiPlatform\State\OptionsInterface;
|
25 | 27 | use Symfony\Component\Config\Util\XmlUtils;
|
@@ -97,6 +99,7 @@ private function buildExtendedBase(\SimpleXMLElement $resource): array
|
97 | 99 | 'stateOptions' => $this->buildStateOptions($resource),
|
98 | 100 | 'links' => $this->buildLinks($resource),
|
99 | 101 | 'headers' => $this->buildHeaders($resource),
|
| 102 | + 'parameters' => $this->buildParameters($resource), |
100 | 103 | ]);
|
101 | 104 | }
|
102 | 105 |
|
@@ -200,7 +203,7 @@ private function buildOpenapi(\SimpleXMLElement $resource): bool|OpenApiOperatio
|
200 | 203 |
|
201 | 204 | if (isset($openapi->parameters->parameter)) {
|
202 | 205 | foreach ($openapi->parameters->parameter as $parameter) {
|
203 |
| - $data['parameters'][(string) $parameter->attributes()->name] = new Parameter( |
| 206 | + $data['parameters'][(string) $parameter->attributes()->name] = new OpenApiParameter( |
204 | 207 | name: $this->phpize($parameter, 'name', 'string'),
|
205 | 208 | in: $this->phpize($parameter, 'in', 'string'),
|
206 | 209 | description: $this->phpize($parameter, 'description', 'string'),
|
@@ -494,4 +497,48 @@ private function buildHeaders(\SimpleXMLElement $resource): ?array
|
494 | 497 |
|
495 | 498 | return $headers;
|
496 | 499 | }
|
| 500 | + |
| 501 | + /** |
| 502 | + * @return array<string, \ApiPlatform\Metadata\Parameter> |
| 503 | + */ |
| 504 | + private function buildParameters(\SimpleXMLElement $resource): ?array |
| 505 | + { |
| 506 | + if (!$resource->parameters) { |
| 507 | + return null; |
| 508 | + } |
| 509 | + |
| 510 | + $parameters = []; |
| 511 | + foreach ($resource->parameters->parameter as $parameter) { |
| 512 | + $key = (string) $parameter->attributes()->key; |
| 513 | + $cl = ('header' === (string) $parameter->attributes()->in) ? HeaderParameter::class : QueryParameter::class; |
| 514 | + $parameters[$key] = new $cl( |
| 515 | + key: $key, |
| 516 | + required: $this->phpize($parameter, 'required', 'bool'), |
| 517 | + schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null, |
| 518 | + openApi: isset($parameter->openapi) ? new OpenApiParameter( |
| 519 | + name: $this->phpize($parameter->openapi, 'name', 'string'), |
| 520 | + in: $this->phpize($parameter->openapi, 'in', 'string'), |
| 521 | + description: $this->phpize($parameter->openapi, 'description', 'string'), |
| 522 | + required: $this->phpize($parameter->openapi, 'required', 'bool'), |
| 523 | + deprecated: $this->phpize($parameter->openapi, 'deprecated', 'bool'), |
| 524 | + allowEmptyValue: $this->phpize($parameter->openapi, 'allowEmptyValue', 'bool'), |
| 525 | + schema: isset($parameter->openapi->schema->values) ? $this->buildValues($parameter->openapi->schema->values) : null, |
| 526 | + style: $this->phpize($parameter->openapi, 'style', 'string'), |
| 527 | + explode: $this->phpize($parameter->openapi, 'explode', 'bool'), |
| 528 | + allowReserved: $this->phpize($parameter->openapi, 'allowReserved', 'bool'), |
| 529 | + example: $this->phpize($parameter->openapi, 'example', 'string'), |
| 530 | + examples: isset($parameter->openapi->examples->values) ? new \ArrayObject($this->buildValues($parameter->openapi->examples->values)) : null, |
| 531 | + content: isset($parameter->openapi->content->values) ? new \ArrayObject($this->buildValues($parameter->openapi->content->values)) : null, |
| 532 | + ) : null, |
| 533 | + provider: $this->phpize($parameter, 'provider', 'string'), |
| 534 | + filter: $this->phpize($parameter, 'filter', 'string'), |
| 535 | + property: $this->phpize($parameter, 'property', 'string'), |
| 536 | + description: $this->phpize($parameter, 'description', 'string'), |
| 537 | + priority: $this->phpize($parameter, 'priority', 'integer'), |
| 538 | + extraProperties: $this->buildExtraProperties($parameter, 'extraProperties') ?? [], |
| 539 | + ); |
| 540 | + } |
| 541 | + |
| 542 | + return $parameters; |
| 543 | + } |
497 | 544 | }
|
0 commit comments