krasa / krasa-jaxb-tools

XJC / JAXB plugin for generation of Bean Validation Annotations (JSR-303) and replacing primitive types
Apache License 2.0
60 stars 49 forks source link

Pattern Validation for enums. At the moment Krasa supports only String type for Patterns #48

Closed rohanmukesh closed 3 years ago

rohanmukesh commented 8 years ago

At the moment Krasa only supports pattern for Strings. We have a business scenario where we have Enum which consists of 10 values and There are many complex types which refer to enum but then we need it to be restricted to use only 2 enum values or 3 instead of all of them.

Here is a business case for this :: ActionEnum:

 <xsd:simpleType name="ActionValues">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Flights"/>
            <xsd:enumeration value="Delta"/>
            <xsd:enumeration value="FareValue"/>
 </xsd:restriction>
    </xsd:simpleType>

complex type:

<xsd:complexType name="FlightsDeltaAction">
        <xsd:sequence>
            <xsd:element name="name">
                <xsd:simpleType>
                    <xsd:restriction base="ActionValues">
                        <xsd:pattern value="Flights"/>
                        <xsd:pattern value ="Delta"/>
                    </xsd:restriction>
                </xsd:simpleType>

I can see from the sourcecode that there is below code: else if (simpleType.getFacet("pattern") != null) { String pattern = simpleType.getFacet("pattern").getValue().value; if ("String".equals(field.type().name()) Can we have this extended to have restrictions for Enums as well?

Thanks, Rohan

krasa commented 8 years ago

Pull request welcomed

krasa commented 3 years ago

I think it was fixed by #60 and #69