Skip to content

Commit

Permalink
fix: add missing fieldtypes for go union types (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Souvikns authored Jun 25, 2024
1 parent efd127a commit 7b2701d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions examples/go-union-type/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ type AdditionalProperty struct {
AdditionalPropertyOneOf_1
string
float64
ModelinaArrType
ModelinaArrType []string
ModelinaArrType []Union
AdditionalPropertyOneOf_6
}",
]
Expand All @@ -20,7 +21,7 @@ Array [
type Union struct {
string
float64
ModelinaAnyType
ModelinaAnyType interface{}
}",
]
`;
Expand Down
6 changes: 3 additions & 3 deletions src/generators/go/renderers/UnionRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ export const GO_DEFAULT_UNION_PRESET: UnionPresetType<GoOptions> = {
const fieldType = field.type;

if (fieldType === 'interface{}') {
return `${options.unionAnyModelName}`;
return `${options.unionAnyModelName} ${fieldType}`;
}
if (fieldType.includes('map')) {
return `${options.unionDictModelName}`;
return `${options.unionDictModelName} ${fieldType}`;
}
if (fieldType.includes('[]')) {
return `${options.unionArrModelName}`;
return `${options.unionArrModelName} ${fieldType}`;
}
return `${fieldType}`;
},
Expand Down
12 changes: 6 additions & 6 deletions test/generators/go/__snapshots__/GoGenerator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package some_package
type Union struct {
string
float64
ModelinaAnyType
ModelinaAnyType interface{}
}"
`;

Expand All @@ -30,7 +30,7 @@ package some_package
// AdditionalProperties represents a AdditionalProperties model.
type AdditionalProperties struct {
ModelinaAnyType
ModelinaAnyType interface{}
string
}"
`;
Expand Down Expand Up @@ -88,7 +88,7 @@ package some_package
type Union struct {
string
float64
ModelinaAnyType
ModelinaAnyType interface{}
}"
`;

Expand All @@ -98,7 +98,7 @@ package some_package
// AdditionalProperties represents a AdditionalProperties model.
type AdditionalProperties struct {
ModelinaAnyType
ModelinaAnyType interface{}
string
}"
`;
Expand Down Expand Up @@ -296,7 +296,7 @@ exports[`GoGenerator should render \`struct\` type 2`] = `
type Union struct {
string
float64
ModelinaAnyType
ModelinaAnyType interface{}
}"
`;

Expand Down Expand Up @@ -333,7 +333,7 @@ type Members struct {
type Union struct {
string
float64
ModelinaAnyType
ModelinaAnyType interface{}
}
// LocationAdditionalProperty represents a LocationAdditionalProperty model.
type LocationAdditionalProperty struct {
Expand Down

0 comments on commit 7b2701d

Please sign in to comment.