fnogatz / xsd2json

Translate XML Schema into equivalent JSON Schema
MIT License
149 stars 28 forks source link

Problem with xhtml tag in a annotation element #31

Closed dguyonvarch closed 8 years ago

dguyonvarch commented 8 years ago

The XMLSchema.xsd authorizes any element (with relaxed validation) in documentation content :

<xs:element name="documentation" id="documentation">
...
  <xs:complexType mixed="true">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:any processContents="lax"/>
    </xs:sequence>
    ...
  </xs:complexType>
</xs:element>

so this xsd

<?xml version="1.0" encoding="UTF-8"?>
<s:schema targetNamespace="http://www.mgdis.fr/public/demande-paiement/v1" 
    xmlns:s="http://www.w3.org/2001/XMLSchema" 
    xmlns:tns="http://www.mgdis.fr/public/demande-paiement/v1" 
    elementFormDefault="qualified">
  <s:element name="acomplexobject">
    <s:complexType>
      <s:sequence>
        <s:element name="aproperty" type="s:string" minOccurs="0">
          <s:annotation>
            <s:documentation xml:lang="EN"><p>A description</p></s:documentation>
          </s:annotation>
        </s:element>
      </s:sequence>
    </s:complexType>
  </s:element>
</s:schema> 

should generate this jsonschema

{
  "type":"object", 
  "properties": {
    "aproperty": {
      "description":"<p>A description</p>",
      "type":"string"
    }
  }
}

but it fails with :

ERROR: Prolog initialisation failed:
ERROR: term_to_atom/2: Type error: `text' expected, found `http://www.w3.org/2001/XMLSchema:documentation'

The question is open : Does it parse the xhtml tag (especially <br/> with \n) or does it restitute the description unchanged ?

P.S. : Thanks for your projet :)

fnogatz commented 8 years ago

Were a little bit more changes than expected :)

The content of xs:annotation is now returned as string. Note that I added a new --whitespace={remove,preserve} flag to allow whitespace-sensitive markdown in the annotation tag.

The new version 1.6.0 is on npm and creates the result you had expected.