Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ jobs:
- name: Test
run: go test -v -timeout 60m -coverprofile='coverage.txt' -covermode=atomic ./

- name: Check that generated files are up to date
run: |
cd cmd/xgen && \
go install && \
cd ../.. &&
xgen -i ./test/xsd/base64.xsd -o ./test/c/base64.xsd.h -l C && \
xgen -i ./test/xsd/base64.xsd -o ./test/go/base64.xsd.go -l Go && \
xgen -i ./test/xsd/base64.xsd -o ./test/java/base64.xsd.java -l Java && \
xgen -i ./test/xsd/base64.xsd -o ./test/rs/base64.xsd.rs -l Rust && \
xgen -i ./test/xsd/base64.xsd -o ./test/ts/base64.xsd.ts -l TypeScript && \
git diff --exit-code

- name: Codecov
uses: codecov/codecov-action@v5
env:
Expand Down
11 changes: 7 additions & 4 deletions genGo.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,22 @@ func (gen *CodeGenerator) GoComplexType(v *ComplexType) {
}

for _, element := range v.Elements {
var plural string
fieldType := genGoFieldType(getBasefromSimpleType(trimNSPrefix(element.Type), gen.ProtoTree))

if element.Plural {
plural = "[]"
fieldType = "[]" + fieldType
}
var optional string
if element.Optional {
optional = `,omitempty`
if !element.Plural && !strings.HasPrefix(fieldType, `*`) {
fieldType = "*" + fieldType
}
}
fieldType := genGoFieldType(getBasefromSimpleType(trimNSPrefix(element.Type), gen.ProtoTree))
if fieldType == "time.Time" {
gen.ImportTime = true
}
content += fmt.Sprintf("\t%s\t%s%s\t`xml:\"%s%s\"`\n", genGoFieldName(element.Name, false), plural, fieldType, element.Name, optional)
content += fmt.Sprintf("\t%s\t%s\t`xml:\"%s%s\"`\n", genGoFieldName(element.Name, false), fieldType, element.Name, optional)
}
if len(v.Base) > 0 {
// If the type is a built-in type, generate a Value field as chardata.
Expand Down
6 changes: 5 additions & 1 deletion genJava.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ func (gen *CodeGenerator) JavaComplexType(v *ComplexType) {
if element.Plural {
fieldType = fmt.Sprintf("List<%s>", fieldType)
}
content += fmt.Sprintf("\t@XmlElement(required = true, name = \"%s\")\n\tprotected %s %s;\n", element.Name, fieldType, genJavaFieldName(element.Name, false))
required := `required = true, `
if element.Optional {
required = ""
}
content += fmt.Sprintf("\t@XmlElement(%sname = \"%s\")\n\tprotected %s %s;\n", required, element.Name, fieldType, genJavaFieldName(element.Name, false))
}

if len(v.Base) > 0 && isBuiltInJavaType(v.Base) {
Expand Down
6 changes: 5 additions & 1 deletion genTypeScript.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func (gen *CodeGenerator) TypeScriptComplexType(v *ComplexType) {

for _, element := range v.Elements {
fieldType := genTypeScriptFieldType(getBasefromSimpleType(trimNSPrefix(element.Type), gen.ProtoTree), element.Plural)
content += fmt.Sprintf("\t%s: %s;\n", genTypeScriptFieldName(element.Name, false), fieldType)
fieldName := genTypeScriptFieldName(element.Name, false)
if element.Optional {
fieldName += `?`
}
content += fmt.Sprintf("\t%s: %s;\n", fieldName, fieldType)
}

if len(v.Base) > 0 && isBuiltInTypeScriptType(v.Base) {
Expand Down
1 change: 1 addition & 0 deletions test/c/base64.xsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ typedef struct {
char Title;
char Blob[];
char Timestamp;
char Metadata;
} MyType4;

// MyType5 ...
Expand Down
1 change: 1 addition & 0 deletions test/go/base64.xsd.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion test/java/base64.xsd.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class MyType4 {
protected List<Byte> Blob;
@XmlElement(required = true, name = "timestamp")
protected String Timestamp;
@XmlElement(name = "metadata")
protected String Metadata;
}

// MyType5 ...
Expand Down Expand Up @@ -92,7 +94,7 @@ public class TopLevel extends MyType6 {
protected Float CostAttr;
@XmlAttribute(name = "LastUpdated")
protected String LastUpdatedAttr;
@XmlElement(required = true, name = "nested")
@XmlElement(name = "nested")
protected MyType7 Nested;
@XmlElement(required = true, name = "myType1")
protected List<List<Byte>> MyType1;
Expand Down
2 changes: 2 additions & 0 deletions test/rs/base64.xsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct MyType4 {
pub blob: String,
#[serde(rename = "timestamp")]
pub timestamp: u8,
#[serde(rename = "metadata")]
pub metadata: Option<String>,
}


Expand Down
3 changes: 2 additions & 1 deletion test/ts/base64.xsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class MyType4 {
Title: string;
Blob: Uint8Array;
Timestamp: string;
Metadata?: string;
}

// MyType5 ...
Expand Down Expand Up @@ -56,7 +57,7 @@ export class MyType10 {
export class TopLevel extends MyType6 {
CostAttr: number | null;
LastUpdatedAttr: string | null;
Nested: MyType7;
Nested?: MyType7;
MyType1: Uint8Array;
MyType2: Array<MyType2>;
}
1 change: 1 addition & 0 deletions test/xsd/base64.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<element name="title" type="string"/>
<element name="blob" type="base64Binary"/>
<element name="timestamp" type="dateTime"/>
<element name="metadata" type="string" minOccurs="0"/>
</sequence>
</complexType>

Expand Down