fnogatz / xsd2json

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

Missing JSON definition of complexType if does contain simpleContent #58

Closed celestino closed 7 years ago

celestino commented 7 years ago

The complextType someType will not be added to the JSON definition output. Looks like the simpleContent element is not recorginzed by the translator.

input

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns="http://example.local"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://example.local"
           elementFormDefault="qualified">
    <xs:element name="test" type="someType" />

    <xs:complexType name="someType">
        <xs:simpleContent>
            <xs:extension base="someRestrictionType">
                <xs:attribute name="id" type="xs:ID" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="someRestrictionType">
        <xs:restriction base="xs:double">
            <xs:minInclusive value="0" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

output

{
  "definitions": {
    "someRestrictionType": {
      "type":"number",
      "minimum":0,
      "exclusiveMinimum":false
    }
  },
  "allOf": [
    {
      "$ref":"#/definitions/someType"
    }
  ]
}
fnogatz commented 7 years ago

Thank you for the bug report. I have added support for xs:simpleContent definitions. Your example schema now returns the following:

{
  "definitions": {
    "someRestrictionType": {
      "type":"number",
      "minimum":0,
      "exclusiveMinimum":false
    },
    "someType": {
      "properties": {
        "id": {
          "type":"string"
        },
        "value": {
          "$ref":"#/definitions/someRestrictionType"
        }
      },
      "type":"object",
      "required": [
        "value"
      ]
    }
  },
  "allOf": [
    {
      "$ref":"#/definitions/someType"
    }
  ]
}
fnogatz commented 7 years ago

The updated version is on npm as 1.9.0.