Skip to content

Commit 658bd13

Browse files
committed
test(golang): proof that enums can be dodged
1 parent 3f24026 commit 658bd13

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientCodegenTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,32 @@ public void testAdditionalPropertiesWithGoMod() throws Exception {
375375
TestUtils.assertFileExists(goSumFile);
376376
}
377377

378+
@Test
379+
public void testAdditionalPropertiesPrefixEnums() throws Exception {
380+
File output = Files.createTempDirectory("test").toFile();
381+
output.deleteOnExit();
382+
383+
final CodegenConfigurator configurator = new CodegenConfigurator()
384+
.setGeneratorName("go")
385+
.setInputSpec("src/test/resources/3_1/enum_collision.yaml")
386+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"))
387+
.addAdditionalProperty("enumClassPrefix", "true")
388+
.addInlineSchemaOption("RESOLVE_INLINE_ENUMS", "true");
389+
390+
DefaultGenerator generator = new DefaultGenerator();
391+
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
392+
System.out.println(files);
393+
files.forEach(File::deleteOnExit);
394+
395+
Path petFile = Paths.get(output + "/model_pet_status.go");
396+
TestUtils.assertFileExists(petFile);
397+
TestUtils.assertFileContains(petFile, "PETSTATUS_SOLD");
398+
399+
Path machineFile = Paths.get(output + "/model_machine_status.go");
400+
TestUtils.assertFileExists(machineFile);
401+
TestUtils.assertFileContains(machineFile, "MACHINESTATUS_SOLD");
402+
}
403+
378404
@Test
379405
public void testAdditionalPropertiesWithoutGoMod() throws Exception {
380406
File output = Files.createTempDirectory("test").toFile();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
openapi: 3.1.0
2+
info:
3+
title: TEST
4+
description: |-
5+
## TEST
6+
version: 1.0.0
7+
8+
servers:
9+
- url: /v3
10+
description: Major version of service
11+
12+
paths:
13+
/agreements:
14+
get:
15+
operationId: readAPet
16+
responses:
17+
"200":
18+
description: OK
19+
content:
20+
'*/*':
21+
schema:
22+
$ref: '#/components/schemas/Pet'
23+
components:
24+
schemas:
25+
Pet:
26+
title: a Pet
27+
description: A pet for sale in the pet store
28+
type: object
29+
properties:
30+
status:
31+
type: string
32+
description: pet status in the store
33+
enum:
34+
- available
35+
- pending
36+
- sold
37+
Machine:
38+
title: a Machine
39+
description: A machine for sale in the pet store
40+
type: object
41+
properties:
42+
status:
43+
type: string
44+
description: machine status in the store
45+
enum:
46+
- available
47+
- pending
48+
- sold

0 commit comments

Comments
 (0)