From d8f468f5383998c8dda397a461e98b781d926a34 Mon Sep 17 00:00:00 2001 From: alpoi Date: Fri, 24 Jul 2026 11:20:44 +0200 Subject: [PATCH 1/3] feat(go): --enum-type-name-suffix to avoid same-package enum conflicts --- .../quicktype-core/src/language/Golang/GolangRenderer.ts | 6 +++--- packages/quicktype-core/src/language/Golang/language.ts | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/quicktype-core/src/language/Golang/GolangRenderer.ts b/packages/quicktype-core/src/language/Golang/GolangRenderer.ts index 37cbfaf5e4..960c77b8c7 100644 --- a/packages/quicktype-core/src/language/Golang/GolangRenderer.ts +++ b/packages/quicktype-core/src/language/Golang/GolangRenderer.ts @@ -222,8 +222,8 @@ export class GoRenderer extends ConvenienceRenderer { t instanceof ClassType ? this.collectClassImports(t) : t instanceof UnionType - ? this.collectUnionImports(t) - : undefined; + ? this.collectUnionImports(t) + : undefined; this.emitPackageDefinitons(true, imports); const unmarshalName = defined(this._topLevelUnmarshalNames.get(name)); @@ -303,7 +303,7 @@ export class GoRenderer extends ConvenienceRenderer { const columns: Sourcelike[][] = []; this.forEachEnumCase(e, "none", (name, jsonName) => { columns.push([ - [name, " "], + this._options.enumTypeNameSuffix ? [name, enumName, " "] : [name, " "], [enumName, ' = "', stringEscape(jsonName), '"'], ]); }); diff --git a/packages/quicktype-core/src/language/Golang/language.ts b/packages/quicktype-core/src/language/Golang/language.ts index 0a096e4ec6..556c2dc467 100644 --- a/packages/quicktype-core/src/language/Golang/language.ts +++ b/packages/quicktype-core/src/language/Golang/language.ts @@ -43,6 +43,11 @@ export const goOptions = { 'If set, all non-required objects will be tagged with ",omitempty"', false, ), + enumTypeNameSuffix: new BooleanOption( + "enum-type-name-suffix", + "Appends the type name to enum contracts", + false, + ), }; const golangLanguageConfig = { From 8a8bc3ddd20cd07d0e41b3a48a7083b2f10656e7 Mon Sep 17 00:00:00 2001 From: alpoi Date: Fri, 24 Jul 2026 11:29:52 +0200 Subject: [PATCH 2/3] style: format --- .../quicktype-core/src/language/Golang/GolangRenderer.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/quicktype-core/src/language/Golang/GolangRenderer.ts b/packages/quicktype-core/src/language/Golang/GolangRenderer.ts index 960c77b8c7..42ea08d512 100644 --- a/packages/quicktype-core/src/language/Golang/GolangRenderer.ts +++ b/packages/quicktype-core/src/language/Golang/GolangRenderer.ts @@ -222,8 +222,8 @@ export class GoRenderer extends ConvenienceRenderer { t instanceof ClassType ? this.collectClassImports(t) : t instanceof UnionType - ? this.collectUnionImports(t) - : undefined; + ? this.collectUnionImports(t) + : undefined; this.emitPackageDefinitons(true, imports); const unmarshalName = defined(this._topLevelUnmarshalNames.get(name)); @@ -303,7 +303,9 @@ export class GoRenderer extends ConvenienceRenderer { const columns: Sourcelike[][] = []; this.forEachEnumCase(e, "none", (name, jsonName) => { columns.push([ - this._options.enumTypeNameSuffix ? [name, enumName, " "] : [name, " "], + this._options.enumTypeNameSuffix + ? [name, enumName, " "] + : [name, " "], [enumName, ' = "', stringEscape(jsonName), '"'], ]); }); From 3344a8cf9c3bb98dc67c4e06494143bb4c0cc71e Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Fri, 24 Jul 2026 09:42:27 -0400 Subject: [PATCH 3/3] test(go): cover enum type name suffix option --- test/languages.ts | 1 + .../unit/golang-enum-type-name-suffix.test.ts | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/unit/golang-enum-type-name-suffix.test.ts diff --git a/test/languages.ts b/test/languages.ts index b6d1304b13..8992f3bb4a 100644 --- a/test/languages.ts +++ b/test/languages.ts @@ -581,6 +581,7 @@ export const GoLanguage: Language = { // fields preserve null instead of being omitted. ["omit-empty.json", { "omit-empty": "true" }], ["nullable-optional-one-of.schema", { "omit-empty": "true" }], + ["enum.schema", { "enum-type-name-suffix": "true" }], ], sourceFiles: ["src/language/Golang/index.ts"], }; diff --git a/test/unit/golang-enum-type-name-suffix.test.ts b/test/unit/golang-enum-type-name-suffix.test.ts new file mode 100644 index 0000000000..d10540b494 --- /dev/null +++ b/test/unit/golang-enum-type-name-suffix.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, test } from "vitest"; + +import { + InputData, + JSONSchemaInput, + quicktype, +} from "../../packages/quicktype-core/src/index.js"; + +async function renderGo(enumTypeNameSuffix: boolean): Promise { + const schemaInput = new JSONSchemaInput(undefined); + await schemaInput.addSource({ + name: "TreePart", + schema: JSON.stringify({ + type: "string", + enum: ["BARK", "LEAF", "ROOT"], + }), + }); + + const inputData = new InputData(); + inputData.addInput(schemaInput); + + const result = await quicktype({ + inputData, + lang: "go", + rendererOptions: { + "enum-type-name-suffix": enumTypeNameSuffix, + }, + }); + return result.lines.join("\n"); +} + +describe("Go enum-type-name-suffix", () => { + test("appends the enum type name to each constant when enabled", async () => { + const output = await renderGo(true); + + expect(output).toMatch(/BarkTreePart\s+TreePart = "BARK"/); + expect(output).toMatch(/LeafTreePart\s+TreePart = "LEAF"/); + expect(output).toMatch(/RootTreePart\s+TreePart = "ROOT"/); + }); +});