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
2 changes: 1 addition & 1 deletion src/Metadata/Extractor/ResourceExtractorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function phpize(\SimpleXMLElement|array|null $resource, string $key, str

private function buildArgs(\SimpleXMLElement $resource): ?array
{
if (!isset($resource->args->arg)) {
if (!isset($resource->args)) {
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Metadata/Extractor/XmlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ private function buildLinks(\SimpleXMLElement $resource): ?array
}

$links = [];
foreach ($resource->links as $link) {
$links[] = new Link(rel: (string) $link->link->attributes()->rel, href: (string) $link->link->attributes()->href);
foreach ($resource->links->link as $link) {
$links[] = new Link(rel: (string) $link->attributes()->rel, href: (string) $link->attributes()->href);
}

return $links;
Expand All @@ -526,8 +526,8 @@ private function buildHeaders(\SimpleXMLElement $resource): ?array
}

$headers = [];
foreach ($resource->headers as $header) {
$headers[(string) $header->header->attributes()->key] = (string) $header->header->attributes()->value;
foreach ($resource->headers->header as $header) {
$headers[(string) $header->attributes()->key] = (string) $header->attributes()->value;
}

return $headers;
Expand Down
17 changes: 9 additions & 8 deletions src/Metadata/Extractor/schema/resources.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<xsd:attributeGroup ref="extendedBase"/>
<xsd:attribute type="xsd:string" name="uriTemplate"/>
<xsd:attribute type="xsd:string" name="class" use="required"/>
<xsd:attribute type="xsd:boolean" name="openapi"/>
</xsd:complexType>

<xsd:complexType name="operations">
Expand All @@ -45,7 +46,7 @@
<xsd:attribute type="xsd:boolean" name="write"/>
<xsd:attribute type="xsd:boolean" name="serialize"/>
<xsd:attribute type="xsd:boolean" name="openapi"/>
<xsd:attribute type="xsd:positiveInteger" name="priority"/>
<xsd:attribute type="xsd:integer" name="priority"/>
<xsd:attribute type="xsd:integer" name="routePriority"/>
<xsd:attribute type="xsd:string" name="name"/>
<xsd:attribute type="xsd:string" name="itemUriTemplate"/>
Expand Down Expand Up @@ -73,14 +74,14 @@
<xsd:attribute type="xsd:boolean" name="validate"/>
<xsd:attribute type="xsd:boolean" name="write"/>
<xsd:attribute type="xsd:boolean" name="serialize"/>
<xsd:attribute type="xsd:positiveInteger" name="priority"/>
<xsd:attribute type="xsd:integer" name="priority"/>
<xsd:attribute type="xsd:integer" name="routePriority"/>
<xsd:attribute type="xsd:string" name="name"/>
</xsd:complexType>

<xsd:complexType name="args">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="arg" maxOccurs="unbounded" type="arg"/>
<xsd:sequence>
<xsd:element name="arg" minOccurs="0" maxOccurs="unbounded" type="arg"/>
</xsd:sequence>
</xsd:complexType>

Expand Down Expand Up @@ -420,7 +421,7 @@

<xsd:complexType name="links">
<xsd:sequence>
<xsd:element ref="link"/>
<xsd:element ref="link" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

Expand All @@ -433,7 +434,7 @@

<xsd:complexType name="headers">
<xsd:sequence>
<xsd:element ref="header"/>
<xsd:element ref="header" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

Expand Down Expand Up @@ -513,8 +514,8 @@
<xsd:attribute type="xsd:boolean" name="paginationEnabled"/>
<xsd:attribute type="xsd:boolean" name="paginationFetchJoinCollection"/>
<xsd:attribute type="xsd:boolean" name="paginationUseOutputWalkers"/>
<xsd:attribute type="xsd:positiveInteger" name="paginationItemsPerPage"/>
<xsd:attribute type="xsd:positiveInteger" name="paginationMaximumItemsPerPage"/>
<xsd:attribute type="xsd:nonNegativeInteger" name="paginationItemsPerPage"/>
<xsd:attribute type="xsd:nonNegativeInteger" name="paginationMaximumItemsPerPage"/>
<xsd:attribute type="xsd:boolean" name="paginationPartial"/>
<xsd:attribute type="xsd:string" name="paginationType"/>
<xsd:attribute type="xsd:string" name="processor"/>
Expand Down
12 changes: 12 additions & 0 deletions src/Metadata/Tests/Extractor/XmlExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ public static function getInvalidPaths(): array
];
}

public function testLessStrictSchema(): void
{
$resource = (new XmlResourceExtractor([__DIR__.'/xml/less_strict_schema.xml']))->getResources()[Comment::class][0];

$this->assertFalse($resource['openapi']);
$this->assertSame(0, $resource['paginationItemsPerPage']);
$this->assertSame(['https://example.com/a', 'https://example.com/b'], array_map(static fn ($link) => $link->getHref(), $resource['links']));
$this->assertSame(['X-A' => 'a', 'X-B' => 'b'], $resource['headers']);
$this->assertSame(-1, $resource['operations'][0]['priority']);
$this->assertSame([], $resource['graphQlOperations'][0]['args']);
}

/**
* Tests issue #8175: two XML operations sharing an explicit name silently
* dropped one another. The factory must reject the duplicate up front.
Expand Down
25 changes: 25 additions & 0 deletions src/Metadata/Tests/Extractor/xml/less_strict_schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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" openapi="false" paginationItemsPerPage="0">
<links>
<link rel="a" href="https://example.com/a"/>
<link rel="b" href="https://example.com/b"/>
</links>
<headers>
<header key="X-A" value="a"/>
<header key="X-B" value="b"/>
</headers>
<operations>
<operation class="ApiPlatform\Metadata\Get" priority="-1"/>
</operations>
<graphQlOperations>
<graphQlOperation class="ApiPlatform\Metadata\GraphQl\Query" name="notRetrievedQuery">
<args/>
</graphQlOperation>
</graphQlOperations>
</resource>
</resources>
Loading