From 658bd1304bbb0a53a27ef92103ffaa68ea777192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20R=C3=BChl?= Date: Thu, 4 Sep 2025 14:24:01 +0200 Subject: [PATCH] test(golang): proof that enums can be dodged --- .../codegen/go/GoClientCodegenTest.java | 26 ++++++++++ .../test/resources/3_1/enum_collision.yaml | 48 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_1/enum_collision.yaml diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java index 15140317d543..c8a9d889e3b3 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java @@ -375,6 +375,32 @@ public void testAdditionalPropertiesWithGoMod() throws Exception { TestUtils.assertFileExists(goSumFile); } + @Test + public void testAdditionalPropertiesPrefixEnums() throws Exception { + File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("go") + .setInputSpec("src/test/resources/3_1/enum_collision.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")) + .addAdditionalProperty("enumClassPrefix", "true") + .addInlineSchemaOption("RESOLVE_INLINE_ENUMS", "true"); + + DefaultGenerator generator = new DefaultGenerator(); + List files = generator.opts(configurator.toClientOptInput()).generate(); + System.out.println(files); + files.forEach(File::deleteOnExit); + + Path petFile = Paths.get(output + "/model_pet_status.go"); + TestUtils.assertFileExists(petFile); + TestUtils.assertFileContains(petFile, "PETSTATUS_SOLD"); + + Path machineFile = Paths.get(output + "/model_machine_status.go"); + TestUtils.assertFileExists(machineFile); + TestUtils.assertFileContains(machineFile, "MACHINESTATUS_SOLD"); + } + @Test public void testAdditionalPropertiesWithoutGoMod() throws Exception { File output = Files.createTempDirectory("test").toFile(); diff --git a/modules/openapi-generator/src/test/resources/3_1/enum_collision.yaml b/modules/openapi-generator/src/test/resources/3_1/enum_collision.yaml new file mode 100644 index 000000000000..d209534dd977 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_1/enum_collision.yaml @@ -0,0 +1,48 @@ +openapi: 3.1.0 +info: + title: TEST + description: |- + ## TEST + version: 1.0.0 + +servers: + - url: /v3 + description: Major version of service + +paths: + /agreements: + get: + operationId: readAPet + responses: + "200": + description: OK + content: + '*/*': + schema: + $ref: '#/components/schemas/Pet' +components: + schemas: + Pet: + title: a Pet + description: A pet for sale in the pet store + type: object + properties: + status: + type: string + description: pet status in the store + enum: + - available + - pending + - sold + Machine: + title: a Machine + description: A machine for sale in the pet store + type: object + properties: + status: + type: string + description: machine status in the store + enum: + - available + - pending + - sold \ No newline at end of file