Skip to content

Commit fdc5bce

Browse files
GregoireHebertalanpoulain
authored andcommitted
fix graphql operation xsd (#2558)
* fix graphql operation xsd * Add metadata.xsd schema test
1 parent c30e42a commit fdc5bce

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed

src/Metadata/schema/metadata.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</xsd:complexType>
6666

6767
<xsd:complexType name="operation">
68-
<xsd:sequence maxOccurs="unbounded">
68+
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
6969
<xsd:element name="attribute" maxOccurs="unbounded" type="attribute"/>
7070
</xsd:sequence>
7171
<xsd:attribute type="xsd:string" name="name"/>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0"?>
2+
<resource>
3+
</resource>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0"?>
2+
<resources xmlns="https://api-platform.com/schema/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd">
3+
<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd" class="App\Entity\Book">
4+
<attribute>
5+
<attribute name="normalization_context">
6+
<attribute name="groups">
7+
<attribute>read</attribute>
8+
</attribute>
9+
</attribute>
10+
<attribute name="denormalization_context">
11+
<attribute name="groups">
12+
<attribute>write</attribute>
13+
</attribute>
14+
</attribute>
15+
<attribute name="Create a Book instead"/>
16+
</attribute>
17+
<graphql>
18+
<operation name="query">
19+
<attribute name="normalization_context">
20+
<attribute name="groups">
21+
<attribute>query</attribute>
22+
</attribute>
23+
</attribute>
24+
</operation>
25+
<operation name="create">
26+
<attribute name="normalization_context">
27+
<attribute name="groups">
28+
<attribute>query</attribute>
29+
</attribute>
30+
</attribute>
31+
<attribute name="denormalization_context">
32+
<attribute name="groups">
33+
<attribute>mutation</attribute>
34+
</attribute>
35+
</attribute>
36+
</operation>
37+
<operation name="delete"/>
38+
</graphql>
39+
<itemOperations>
40+
<itemOperation name="get">
41+
<attribute name="method">GET</attribute>
42+
<attribute name="path">/grimoire/{id}</attribute>
43+
<attribute name="requirements">
44+
<attribute name="id">\d+</attribute>
45+
</attribute>
46+
<attribute name="defaults">
47+
<attribute name="color">brown</attribute>
48+
</attribute>
49+
<attribute name="options">
50+
<attribute name="my_option">my_option_value</attribute>
51+
</attribute>
52+
<attribute name="schemes">
53+
<attribute>https</attribute>
54+
</attribute>
55+
<attribute name="host">{subdomain}.api-platform.com</attribute>
56+
</itemOperation>
57+
<itemOperation name="put">
58+
<attribute name="method">PUT</attribute>
59+
<attribute name="path">/grimoire/{id}/update</attribute>
60+
<attribute name="hydra_context">
61+
<attribute name="foo">bar</attribute>
62+
</attribute>
63+
</itemOperation>
64+
<itemOperation name="post_publication">
65+
<attribute name="route_name">book_post_publication</attribute>
66+
<attribute name="deprecation_reason">Retrieve a Book instead</attribute>
67+
<attribute name="sunset">01/01/2020</attribute>
68+
</itemOperation>
69+
<itemOperation name="book_post_discontinuation"/>
70+
</itemOperations>
71+
<property name="id" description="identifiant unique" iri="http://schema.org/id" identifier="1"/>
72+
<property name="name" readable="1" writable="1"/>
73+
<property name="author" readable="1">
74+
<subresource resourceClass="App\Entity\Holder"/>
75+
</property>
76+
<property name="scribus">
77+
<attribute>
78+
<attribute name="Use the author property instead"/>
79+
</attribute>
80+
</property>
81+
</resource>
82+
</resources>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Metadata\schema;
15+
16+
use PHPUnit\Framework\TestCase;
17+
use Symfony\Component\Config\Util\XmlUtils;
18+
19+
/**
20+
* @author Grégoire Hébert <[email protected]>
21+
*/
22+
class XmlSchemaTest extends TestCase
23+
{
24+
public function testSchema(): void
25+
{
26+
$fixtures = __DIR__.'/../../Fixtures/Metadata/schema/';
27+
$schema = __DIR__.'/../../../src/Metadata/schema/metadata.xsd';
28+
29+
try {
30+
XmlUtils::loadFile($fixtures.'invalid.xml', $schema);
31+
$this->fail();
32+
} catch (\InvalidArgumentException $e) {
33+
$this->assertContains('ERROR 1845', $e->getMessage());
34+
}
35+
36+
$this->assertInstanceOf(\DOMDocument::class, XmlUtils::loadFile($fixtures.'valid.xml', $schema));
37+
}
38+
}

0 commit comments

Comments
 (0)