raml-org/raml-java-parser

Cannot validate example against XML Schema v1.1

dcourtil opened this issue · 3 comments

This bug affects any version of the raml-java-parser used in parallel with Apache Xerces2 2.11.2 and a RAML that !includes a XSD file with vc:minVersion set to 1.1.

XmlSchemaValidationRule#validateXmlExample fails to validate against an XML Schema v1.1 when the validator is actually instantiated for v1.0.

XSD file:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1"> <xs:element name="Message" type="xs:string"/> </xs:schema>

XML example:
<?xml version="1.0" encoding="UTF-8" ?> <Message>Example</Message>

The issue is caused by an upgrade of the Apache Xerces version, which causes the SchemaGenerator#generateXmlSchema to instantiate a different SchemaFactory implementation.

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

As Xerces documentation states

... For XML Schema 1.1 validation, the preferred way is to use the JAXP validation API, using the XSD 1.1 Schema factory. ...
... To be able to do this, we need to construct the XSD 1.1 Schema factory with the following java statement, SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1") ...

So we need a way to support the schema validation for any version or to setup the version dynamically through system properties or some sort of configuration.

Here you can find attached the pom file including the Xerces version that is causing the issue:
pom.xml.zip
Hope this helps to reproduce it.

I've added a system property where you could set the schema type as needed.

raml.xml.schema.version, defaults to current operation. Could you check ? I've had trouble reproducing.

I've added a system property where you could set the schema type as needed.

raml.xml.schema.version, defaults to current operation. Could you check ? I've had trouble reproducing.

@jpbelang I ran a simple test with the conflicting dependency and everything worked as expected. Looks good to me!