Skip to content
Open
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
10 changes: 5 additions & 5 deletions src/Metadata/Extractor/XmlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,12 @@ private function buildParameters(\SimpleXMLElement $resource): ?array
schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null,
openApi: isset($parameter->openapi) ? new OpenApiParameter(
name: $this->phpize($parameter->openapi, 'name', 'string'),
in: $this->phpize($parameter->openapi, 'in', 'string'),
description: $this->phpize($parameter->openapi, 'description', 'string'),
required: $this->phpize($parameter->openapi, 'required', 'bool'),
deprecated: $this->phpize($parameter->openapi, 'deprecated', 'bool'),
in: $this->phpize($parameter->openapi, 'in', 'string', $this->phpize($parameter, 'in', 'string', 'query')),
description: $this->phpize($parameter->openapi, 'description', 'string', ''),
required: $this->phpize($parameter->openapi, 'required', 'bool', false),
deprecated: $this->phpize($parameter->openapi, 'deprecated', 'bool', false),
allowEmptyValue: $this->phpize($parameter->openapi, 'allowEmptyValue', 'bool'),
schema: isset($parameter->openapi->schema->values) ? $this->buildValues($parameter->openapi->schema->values) : null,
schema: isset($parameter->openapi->schema->values) ? $this->buildValues($parameter->openapi->schema->values) : [],
style: $this->phpize($parameter->openapi, 'style', 'string'),
explode: $this->phpize($parameter->openapi, 'explode', 'bool'),
allowReserved: $this->phpize($parameter->openapi, 'allowReserved', 'bool'),
Expand Down
20 changes: 20 additions & 0 deletions src/Metadata/Extractor/schema/resources.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,29 @@
</xsd:sequence>
</xsd:group>

<xsd:complexType name="openApiParameter">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="schema" minOccurs="0" type="sequenceWithValues"/>
<xsd:element name="examples" minOccurs="0" type="sequenceWithValues"/>
<xsd:element name="content" minOccurs="0" type="sequenceWithValues"/>
</xsd:sequence>
<xsd:attribute type="xsd:string" name="name" use="required"/>
<xsd:attribute type="xsd:string" name="in"/>
<xsd:attribute type="xsd:string" name="description"/>
<xsd:attribute type="xsd:boolean" name="required"/>
<xsd:attribute type="xsd:boolean" name="deprecated"/>
<xsd:attribute type="xsd:boolean" name="allowEmptyValue"/>
<xsd:attribute type="xsd:string" name="style"/>
<xsd:attribute type="xsd:boolean" name="explode"/>
<xsd:attribute type="xsd:boolean" name="allowReserved"/>
<xsd:attribute type="xsd:string" name="example"/>
</xsd:complexType>

<xsd:element name="parameter">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="openApi" minOccurs="0" type="openApiOperation"/>
<xsd:element name="openapi" minOccurs="0" type="openApiParameter"/>
<xsd:element name="schema" minOccurs="0" type="sequenceWithValues"/>
<xsd:element name="extraProperties" minOccurs="0" type="sequenceWithValues"/>
</xsd:sequence>
Expand All @@ -464,6 +483,7 @@
<xsd:attribute type="xsd:string" name="property"/>
<xsd:attribute type="xsd:string" name="description"/>
<xsd:attribute type="xsd:boolean" name="required"/>
<xsd:attribute type="xsd:integer" name="priority"/>
</xsd:complexType>
</xsd:element>

Expand Down
11 changes: 11 additions & 0 deletions src/Metadata/Tests/Extractor/XmlExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,17 @@ public function testContainerParametersAreResolved(): void
$this->assertSame('is_granted("ROLE_USER")', $resources[User::class][0]['operations'][0]['security']);
}

public function testParameterOpenApiAndPriority(): void
{
$parameter = (new XmlResourceExtractor([__DIR__.'/xml/parameter_openapi.xml']))->getResources()[Comment::class][0]['parameters']['q'];

$this->assertSame(10, $parameter->getPriority());
$this->assertSame('q', $parameter->getOpenApi()->getName());
$this->assertSame('query', $parameter->getOpenApi()->getIn());
$this->assertSame('Search', $parameter->getOpenApi()->getDescription());
$this->assertTrue($parameter->getOpenApi()->getAllowReserved());
}

#[DataProvider('getInvalidPaths')]
public function testInvalidXML(string $path, string $error): void
{
Expand Down
14 changes: 14 additions & 0 deletions src/Metadata/Tests/Extractor/xml/parameter_openapi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>

<resources xmlns="https://api-platform.com/schema/metadata/resources-3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
https://api-platform.com/schema/metadata/resources-3.0.xsd">
<resource class="ApiPlatform\Metadata\Tests\Fixtures\ApiResource\Comment">
<parameters>
<parameter key="q" priority="10">
<openapi name="q" description="Search" allowReserved="true"/>
</parameter>
</parameters>
</resource>
</resources>
Loading