From 89cb8e214e0eea856f05c7309199537e19ab0a3e Mon Sep 17 00:00:00 2001 From: souvik Date: Thu, 23 May 2024 14:37:13 +0530 Subject: [PATCH 1/2] fix: bug with omitempty tag --- examples/go-json-tags/__snapshots__/index.spec.ts.snap | 4 ++-- src/generators/go/presets/CommonPreset.ts | 4 ++-- .../go/presets/__snapshots__/CommonPreset.spec.ts.snap | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/go-json-tags/__snapshots__/index.spec.ts.snap b/examples/go-json-tags/__snapshots__/index.spec.ts.snap index 3f1ddc2de8..fb55f5d97a 100644 --- a/examples/go-json-tags/__snapshots__/index.spec.ts.snap +++ b/examples/go-json-tags/__snapshots__/index.spec.ts.snap @@ -4,8 +4,8 @@ exports[`Should be able to render json-tags in struct and should log expected ou Array [ "// Root represents a Root model. type Root struct { - Cities *Cities \`json:\\"cities, omitempty\\"\` - Options *Options \`json:\\"options, omitempty\\"\` + Cities *Cities \`json:\\"cities,omitempty\\"\` + Options *Options \`json:\\"options,omitempty\\"\` }", ] `; diff --git a/src/generators/go/presets/CommonPreset.ts b/src/generators/go/presets/CommonPreset.ts index 248a7b5f6c..628b1b5d38 100644 --- a/src/generators/go/presets/CommonPreset.ts +++ b/src/generators/go/presets/CommonPreset.ts @@ -19,9 +19,9 @@ function renderJSONTag({ field.property instanceof ConstrainedDictionaryModel && field.property.serializationType === 'unwrap' ) { - return `json:"-"`; + return `json:"-",omitempty`; } - return `json:"${field.unconstrainedPropertyName}, omitempty"`; + return `json:"${field.unconstrainedPropertyName},omitempty"`; } function renderMarshallingFunctions({ diff --git a/test/generators/go/presets/__snapshots__/CommonPreset.spec.ts.snap b/test/generators/go/presets/__snapshots__/CommonPreset.spec.ts.snap index 6a1819d052..0d35ec5083 100644 --- a/test/generators/go/presets/__snapshots__/CommonPreset.spec.ts.snap +++ b/test/generators/go/presets/__snapshots__/CommonPreset.spec.ts.snap @@ -3,9 +3,9 @@ exports[`GO_COMMON_PRESET should render json tags for structs 1`] = ` "// Root represents a Root model. type Root struct { - StringProp string \`json:\\"stringProp, omitempty\\"\` - NumberProp float64 \`json:\\"numberProp, omitempty\\"\` - BooleanProp bool \`json:\\"booleanProp, omitempty\\"\` + StringProp string \`json:\\"stringProp,omitempty\\"\` + NumberProp float64 \`json:\\"numberProp,omitempty\\"\` + BooleanProp bool \`json:\\"booleanProp,omitempty\\"\` }" `; From 36197ab179fe5818223ff3b4f9a6a99128a0e644 Mon Sep 17 00:00:00 2001 From: souvik Date: Wed, 29 May 2024 09:08:38 +0530 Subject: [PATCH 2/2] fix: udpate additional property json tag --- modelina-cli/package-lock.json | 5 +++-- src/generators/go/presets/CommonPreset.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modelina-cli/package-lock.json b/modelina-cli/package-lock.json index 6a7b677f8d..36f2747e28 100644 --- a/modelina-cli/package-lock.json +++ b/modelina-cli/package-lock.json @@ -185,9 +185,10 @@ } }, "node_modules/@asyncapi/modelina": { - "version": "4.0.0-next.43", + "version": "4.0.0-next.44", "resolved": "file:scripts/modelina-package/asyncapi-modelina.tgz", - "integrity": "sha512-RbmOESkG0tnqiL7a+eL2NSCztzPEvSaxYYjsKOuAuIyT4+HrPKQTk6/jtXVh5eiElGuwQ3dYk8OBhQU0ETrUpg==", + "integrity": "sha512-1zCOYyu5+5+LvEbRk9eHL3KCw+e4IrTQLce1X/gGQ8s6QBBPj2A60KICkS4G4lcPjNFNTWpHhy6B64Fy9Laz0Q==", + "license": "Apache-2.0", "dependencies": { "@apidevtools/json-schema-ref-parser": "^11.1.0", "@apidevtools/swagger-parser": "^10.1.0", diff --git a/src/generators/go/presets/CommonPreset.ts b/src/generators/go/presets/CommonPreset.ts index 628b1b5d38..74f0805204 100644 --- a/src/generators/go/presets/CommonPreset.ts +++ b/src/generators/go/presets/CommonPreset.ts @@ -19,7 +19,7 @@ function renderJSONTag({ field.property instanceof ConstrainedDictionaryModel && field.property.serializationType === 'unwrap' ) { - return `json:"-",omitempty`; + return `json:"-,omitempty"`; } return `json:"${field.unconstrainedPropertyName},omitempty"`; }