Skip to content

Commit

Permalink
Xsd import to handle type names with underscore (finos#849)
Browse files Browse the repository at this point in the history
* Xsd import to handle empty string

* formatting

* Add _ to regex

* Tidy up

* Rename

* update test
  • Loading branch information
hugohills-regnosys authored Sep 25, 2024
1 parent 14c7033 commit 9ff8e53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import org.xmlet.xsdparser.xsdelements.XsdSimpleType;

public class XsdUtil {

private static final String XSD_NAME_PARTS_REGEX = "[^a-zA-Z0-9_]";

private final Set<String> documentationSources = Set.of("Definition");

public final String XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance";
Expand Down Expand Up @@ -71,7 +74,7 @@ public boolean isEnumType(XsdSimpleType simpleType) {
}

public String toTypeName(String xsdName) {
String[] parts = xsdName.split("[^a-zA-Z0-9]");
String[] parts = xsdName.split(XSD_NAME_PARTS_REGEX);
StringBuilder builder = new StringBuilder();
for (String part : parts) {
if (Character.isUpperCase(part.charAt(0))) {
Expand All @@ -85,7 +88,7 @@ public String toTypeName(String xsdName) {
}

public String toAttributeName(String xsdName) {
String[] parts = xsdName.split("[^a-zA-Z0-9]");
String[] parts = xsdName.split(XSD_NAME_PARTS_REGEX);
StringBuilder builder = new StringBuilder();
builder.append(allFirstLowerIfNotAbbrevation(parts[0]));
Arrays.stream(parts).skip(1).forEach(part -> {
Expand All @@ -100,7 +103,7 @@ public String toAttributeName(String xsdName) {
}

public String toEnumValueName(String xsdName) {
String[] parts = xsdName.split("[^a-zA-Z0-9]");
String[] parts = xsdName.split(XSD_NAME_PARTS_REGEX);
String joined = String.join("_", parts).toUpperCase();
if (joined.matches("^[0-9].*")) {
return "_" + joined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typeAlias Max500Text: <"Specifies a character string with a maximum length of 50
typeAlias Max3Number: <"Number (max 999) of objects represented as an integer.">
int(digits: 3)

type Bar: <"Bar definition.">
type Bar__1: <"Bar definition.">

barStrAttr string (1..1) <"Bar string attribute definition.">

Expand All @@ -20,4 +20,4 @@ type Foo: <"Foo definition.">
fooDecimalWithRestrictionAttr Max3Number (0..1) <"FooDecimalWithRestrictionAttr definition.">
fooEnumAttr FooEnum (1..1) <"FooEnumAttr definition.">
fooStrListAttr string (0..*) <"FooStrListAttr definition.">
fooBarListAttr Bar (1..2) <"FooBarListAttr definition.">
fooBarListAttr Bar__1 (1..2) <"FooBarListAttr definition.">
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Bar">
<xs:complexType name="Bar__1">
<xs:annotation>
<xs:documentation source="Name" xml:lang="EN">BarName</xs:documentation>
<xs:documentation source="Definition" xml:lang="EN">Bar definition.</xs:documentation>
Expand Down Expand Up @@ -124,7 +124,7 @@
<xs:documentation source="Definition" xml:lang="EN">FooStrListAttr definition.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="FooBarListAttr" type="Bar" minOccurs="1" maxOccurs="2">
<xs:element name="FooBarListAttr" type="Bar__1" minOccurs="1" maxOccurs="2">
<xs:annotation>
<xs:documentation source="Name" xml:lang="EN">FooBarListAttrName</xs:documentation>
<xs:documentation source="Definition" xml:lang="EN">FooBarListAttr definition.</xs:documentation>
Expand Down

0 comments on commit 9ff8e53

Please sign in to comment.