mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
105 stars 76 forks source link

References to simpletypes are created without namespace prefix (schemagen) #146

Open umefjord opened 4 years ago

umefjord commented 4 years ago

When running schemagen for a project with enum types the generated XSD contains no namespace prefix in the elements with references to these types. As no default namespace is declared in the root xjc will not accept the generated XSD.

Example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vh="http://schemas.acme.com/vehicles" elementFormDefault="qualified" targetNamespace="http://schemas.acme.com/vehicles" version="1.0">

    <xs:simpleType name="CarType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="SEDAN"/>
            <xs:enumeration value="STATION_WAGON"/>
            <xs:enumeration value="SUV"/>
            <xs:enumeration value="HATCHBACK"/>
            <xs:enumeration value="CABRIOLET"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="Car">
        <xs:sequence>
            <xs:element ref="CarType"/>
        </xs:sequence>
    </xs:complexType>

</xs:schema>

Since contains no namespace prefix (i.e. "vh:CarType") and the root element contains no default namespace declaration, the XJC-command will fail with:

src-resolve.4.1: Error resolving component 'CarType'. It was detected that 'CarType' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/...'. If 'CarType' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'CarType' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/...'.