-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
basic redefine support #48
Open
cebe
wants to merge
5
commits into
goetas-webservices:master
Choose a base branch
from
cebe:support-redefine
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GoetasWebservices\XML\XSDReader\Tests; | ||
|
||
use GoetasWebservices\XML\XSDReader\Schema\Element\Element; | ||
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef; | ||
use GoetasWebservices\XML\XSDReader\Schema\Schema; | ||
|
||
class RedefineTest extends BaseTest | ||
{ | ||
public function testBase() | ||
{ | ||
$remoteSchema = $this->reader->readString( | ||
' | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:complexType name="personName"> | ||
<xs:sequence> | ||
<xs:element name="title" minOccurs="0"/> | ||
<xs:element name="forename" minOccurs="0" maxOccurs="unbounded"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
|
||
<xs:element name="addressee" type="personName"/> | ||
</xs:schema>', 'http://www.example.com/xsd.xsd'); | ||
|
||
$schema = $this->reader->readString( | ||
' | ||
<xs:schema targetNamespace="http://www.user.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://www.example.com"> | ||
<xs:redefine schemaLocation="http://www.example.com/xsd.xsd"> | ||
<xs:complexType name="personName"> | ||
<xs:complexContent> | ||
<xs:extension base="personName"> | ||
<xs:sequence> | ||
<xs:element name="generation" minOccurs="0"/> | ||
</xs:sequence> | ||
</xs:extension> | ||
</xs:complexContent> | ||
</xs:complexType> | ||
</xs:redefine> | ||
|
||
<xs:element name="author" type="personName"/> | ||
</xs:schema>'); | ||
|
||
// check if schema is not included | ||
// we don't want to redefine original schema | ||
$this->assertNotContains($remoteSchema, $schema->getSchemas(), '', true); | ||
|
||
/* @var $localAttr \GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef */ | ||
|
||
// it should inherit namespace of main schema | ||
$localAttr = $schema->findElement('addressee', 'http://www.user.com'); | ||
$this->assertNotNull($localAttr); | ||
|
||
// find author element | ||
$localAttr = $schema->findElement('author', 'http://www.user.com'); | ||
$this->assertNotNull($localAttr); | ||
|
||
/* @var $type \GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType */ | ||
$type = $localAttr->getType(); | ||
|
||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type); | ||
|
||
$children = array(); | ||
foreach ($type->getElements() as $element) { | ||
$children[] = $element->getName(); | ||
} | ||
|
||
$this->assertContains('generation', $children); | ||
} | ||
|
||
public function testReadSchemaLocation() | ||
{ | ||
$schema = $this->reader->readFile(__DIR__.'/schema/extend-components.xsd'); | ||
$this->assertInstanceOf(Schema::class, $schema); | ||
|
||
$this->assertEquals('spec:example:xsd:CommonBasicComponents-1.0', $schema->getTargetNamespace()); | ||
|
||
// defined in /schema/base-components.xsd | ||
$dateElement = $schema->findElement('Date', 'spec:example:xsd:CommonBasicComponents-1.0'); | ||
$this->assertNotNull($dateElement); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $dateElement); | ||
$type = $dateElement->getType(); | ||
$this->assertEquals('DateType', $type->getName()); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type); | ||
|
||
$dateType = $schema->findType('DateType', 'spec:example:xsd:CommonBasicComponents-1.0'); | ||
$this->assertNotNull($dateType); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $dateType); | ||
|
||
// defined in /schema/extend-components.xsd | ||
$deliveryDateElement = $schema->findElement('DeliveryDate', 'spec:example:xsd:CommonBasicComponents-1.0'); | ||
$this->assertNotNull($deliveryDateElement); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $deliveryDateElement); | ||
$type = $deliveryDateElement->getType(); | ||
$this->assertEquals('DateType', $type->getName()); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $type); | ||
} | ||
|
||
/** | ||
* Ensure Semantics of <redefine> are the same as described in the XSD specification | ||
* @link https://www.w3.org/TR/xmlschema11-1/#modify-schema | ||
*/ | ||
public function testRedefineSemantics() | ||
{ | ||
$schema = $this->reader->readFile(__DIR__.'/schema/extend-xsd-v2.xsd'); | ||
$this->assertInstanceOf(Schema::class, $schema); | ||
|
||
// Definition from https://www.w3.org/TR/xmlschema11-1/#modify-schema | ||
|
||
// The schema corresponding to v2.xsd has everything specified by v1.xsd, with the personName type redefined, | ||
// as well as everything it specifies itself. | ||
// According to this schema, elements constrained by the personName type may end with a generation element. | ||
// This includes not only the author element, but also the addressee element. | ||
$author = $schema->findElement('author'); | ||
$addressee = $schema->findElement('addressee'); | ||
$this->assertNotNull($author); | ||
$this->assertNotNull($addressee); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $author); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef::class, $addressee); | ||
$authorType = $author->getType(); | ||
$addresseeType = $addressee->getType(); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $authorType); | ||
$this->assertInstanceOf(\GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType::class, $addresseeType); | ||
|
||
$this->assertEquals('personName', $authorType->getName()); | ||
$this->assertEquals('personName', $addresseeType->getName()); | ||
|
||
// ensure both types contain the same elements | ||
foreach([$authorType, $addresseeType] as $type) { | ||
/** @var $type \GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType */ | ||
|
||
$elements = $type->getElements(); | ||
$elementNames = array_map(function(Element $element) { return $element->getName(); }, $elements); | ||
sort($elementNames); | ||
$this->assertEquals(['forename', 'generation', 'title'], $elementNames); | ||
} | ||
|
||
|
||
// | ||
// For any document D2 pointed at by a <redefine> element in D1, it must be the case either (a) that tns(D1) = tns(D2) or else (b) that tns(D2) is ·absent·, in which case schema(D1) includes not redefine(E,schema(D2)) itself but redefine(E,schema(chameleon(tns(D1),D2))). That is, the redefinition pre-processing is applied not to the schema corresponding to D2 but instead to the schema corresponding to the schema document chameleon(tns(D1),D2), which is the result of applying chameleon pre-processing to D2 to convert it to target namespace tns(D1). | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns="spec:example:xsd:CommonBasicComponents-1.0" | ||
targetNamespace="spec:example:xsd:CommonBasicComponents-1.0" | ||
elementFormDefault="qualified" | ||
attributeFormDefault="unqualified"> | ||
<xsd:element name="Date" type="DateType"/> | ||
<xsd:element name="Indicator" type="IndicatorType"/> | ||
|
||
<xsd:complexType name="DateType"> | ||
</xsd:complexType> | ||
<xsd:complexType name="IndicatorType"> | ||
</xsd:complexType> | ||
|
||
</xsd:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="iso-8859-1" ?> | ||
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns="spec:example:xsd:CommonBasicComponents-1.0" | ||
targetNamespace="spec:example:xsd:CommonBasicComponents-1.0" | ||
elementFormDefault="qualified" | ||
attributeFormDefault="unqualified"> | ||
|
||
<xsd:redefine schemaLocation="base-components.xsd"> | ||
</xsd:redefine> | ||
|
||
<xsd:element name="DeliveryDate" type="DateType"> | ||
<xsd:annotation><xsd:documentation>Lieferdatum</xsd:documentation> | ||
</xsd:annotation> | ||
</xsd:element> | ||
<xsd:element name="BacklogIndicator" type="IndicatorType"> | ||
<xsd:annotation><xsd:documentation>Indikator</xsd:documentation> | ||
</xsd:annotation> | ||
</xsd:element> | ||
</xsd:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="iso-8859-1" ?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:complexType name="personName"> | ||
<xs:sequence> | ||
<xs:element name="title" minOccurs="0"/> | ||
<xs:element name="forename" minOccurs="0" maxOccurs="unbounded"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
|
||
<xs:element name="addressee" type="personName"/> | ||
</xs:schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="iso-8859-1" ?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:redefine schemaLocation="extend-xsd-v1.xsd"> | ||
<xs:complexType name="personName"> | ||
<xs:complexContent> | ||
<xs:extension base="personName"> | ||
<xs:sequence> | ||
<xs:element name="generation" minOccurs="0"/> | ||
</xs:sequence> | ||
</xs:extension> | ||
</xs:complexContent> | ||
</xs:complexType> | ||
</xs:redefine> | ||
|
||
<xs:element name="author" type="personName"/> | ||
</xs:schema> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure that
redefine
semantics is applied onschemaLocation
and on the target namespace?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that it implements all semantics defined for it but it works for the case where additional Elements and Types are added to a namespace. this is what is covered in the test cases from the original PR and also in the case I extracted from the spec I am currently working with.