diff --git a/examples/go-union-type/__snapshots__/index.spec.ts.snap b/examples/go-union-type/__snapshots__/index.spec.ts.snap index 0bf56369a4..7ad83277a2 100644 --- a/examples/go-union-type/__snapshots__/index.spec.ts.snap +++ b/examples/go-union-type/__snapshots__/index.spec.ts.snap @@ -8,8 +8,7 @@ type AdditionalProperty struct { AdditionalPropertyOneOf_1 string float64 - ModelinaArrType []string - ModelinaArrType []Union + ModelinaArrType AdditionalPropertyOneOf_6 }", ] @@ -21,7 +20,7 @@ Array [ type Union struct { string float64 - ModelinaAnyType interface{} + ModelinaAnyType }", ] `; diff --git a/src/generators/go/presets/CommonPreset.ts b/src/generators/go/presets/CommonPreset.ts index 74f0805204..f6303116e6 100644 --- a/src/generators/go/presets/CommonPreset.ts +++ b/src/generators/go/presets/CommonPreset.ts @@ -66,5 +66,10 @@ export const GO_COMMON_PRESET: GoPreset = { return `${content}\n ${blocks.join('\n')}`; } + }, + union: { + field: ({ content }) => { + return `${content} \`json:"-,omitempty\``; + } } }; diff --git a/src/generators/go/renderers/UnionRenderer.ts b/src/generators/go/renderers/UnionRenderer.ts index 1c941fc25a..4b58ec6e64 100644 --- a/src/generators/go/renderers/UnionRenderer.ts +++ b/src/generators/go/renderers/UnionRenderer.ts @@ -82,13 +82,13 @@ export const GO_DEFAULT_UNION_PRESET: UnionPresetType = { const fieldType = field.type; if (fieldType === 'interface{}') { - return `${options.unionAnyModelName} ${fieldType}`; + return `${options.unionAnyModelName}`; } if (fieldType.includes('map')) { - return `${options.unionDictModelName} ${fieldType}`; + return `${options.unionDictModelName}`; } if (fieldType.includes('[]')) { - return `${options.unionArrModelName} ${fieldType}`; + return `${options.unionArrModelName}`; } return `${fieldType}`; }, diff --git a/test/generators/go/__snapshots__/GoGenerator.spec.ts.snap b/test/generators/go/__snapshots__/GoGenerator.spec.ts.snap index 1ce9dade56..92d13e9a3e 100644 --- a/test/generators/go/__snapshots__/GoGenerator.spec.ts.snap +++ b/test/generators/go/__snapshots__/GoGenerator.spec.ts.snap @@ -20,7 +20,7 @@ package some_package type Union struct { string float64 - ModelinaAnyType interface{} + ModelinaAnyType }" `; @@ -30,7 +30,7 @@ package some_package // AdditionalProperties represents a AdditionalProperties model. type AdditionalProperties struct { - ModelinaAnyType interface{} + ModelinaAnyType string }" `; @@ -88,7 +88,7 @@ package some_package type Union struct { string float64 - ModelinaAnyType interface{} + ModelinaAnyType }" `; @@ -98,7 +98,7 @@ package some_package // AdditionalProperties represents a AdditionalProperties model. type AdditionalProperties struct { - ModelinaAnyType interface{} + ModelinaAnyType string }" `; @@ -296,7 +296,7 @@ exports[`GoGenerator should render \`struct\` type 2`] = ` type Union struct { string float64 - ModelinaAnyType interface{} + ModelinaAnyType }" `; @@ -333,7 +333,7 @@ type Members struct { type Union struct { string float64 - ModelinaAnyType interface{} + ModelinaAnyType } // LocationAdditionalProperty represents a LocationAdditionalProperty model. type LocationAdditionalProperty struct {