Skip to content

Commit 1471e7a

Browse files
authored
Go generate all of with multiple ref and discriminator (#18390)
* feat(go): Generate compiling stubs for allOf with multiple refs and discriminator * feat(go): Generate compiling stubs for allOf with multiple refs and discriminator * feat(go): Generate compiling stubs for allOf with multiple refs and discriminator
1 parent 81f576c commit 1471e7a

3 files changed

Lines changed: 79 additions & 6 deletions

File tree

modules/openapi-generator/src/main/resources/go/model_simple.mustache

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ var _ MappedNullable = &{{classname}}{}
33

44
// {{classname}} {{{description}}}{{^description}}struct for {{{classname}}}{{/description}}
55
type {{classname}} struct {
6-
{{#parent}}
7-
{{^isMap}}
6+
{{#parentModel.name}}
87
{{^isArray}}
9-
{{{parent}}}
8+
{{{parentModel.name}}}
109
{{/isArray}}
11-
{{/isMap}}
1210
{{#isArray}}
13-
Items {{{parent}}}
11+
Items {{{parentModel.name}}}
1412
{{/isArray}}
15-
{{/parent}}
13+
{{/parentModel.name}}
1614
{{#vars}}
1715
{{^-first}}
1816
{{/-first}}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,27 @@ public void verifyApiTestWithNullResponse() throws IOException {
291291
"httpRes, err := apiClient.PetAPI.PetDelete(context.Background()).Execute()");
292292
}
293293

294+
@Test
295+
public void verifyApiWithAllOfMultipleRefAndDiscriminator() throws IOException {
296+
File output = Files.createTempDirectory("test").toFile();
297+
output.deleteOnExit();
298+
299+
final CodegenConfigurator configurator = new CodegenConfigurator()
300+
.setGeneratorName("go")
301+
.setGitUserId("OpenAPITools")
302+
.setGitRepoId("openapi-generator")
303+
.setInputSpec("src/test/resources/3_0/go/allof_multiple_ref_and_discriminator.yaml")
304+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
305+
306+
DefaultGenerator generator = new DefaultGenerator();
307+
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
308+
files.forEach(File::deleteOnExit);
309+
310+
TestUtils.assertFileExists(Paths.get(output + "/model_final_item.go"));
311+
TestUtils.assertFileContains(Paths.get(output + "/model_final_item.go"),
312+
"BaseItem");
313+
}
314+
294315
@Test
295316
public void testAdditionalPropertiesWithGoMod() throws Exception {
296317
File output = Files.createTempDirectory("test").toFile();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Test
4+
version: 1.0.0
5+
paths: {}
6+
components:
7+
schemas:
8+
FinalItem:
9+
type: object
10+
allOf:
11+
- $ref: '#/components/schemas/BaseItem'
12+
- $ref: '#/components/schemas/AdditionalData'
13+
BaseItem:
14+
type: object
15+
properties:
16+
title:
17+
type: string
18+
type:
19+
type: string
20+
enum:
21+
- FINAL
22+
example: FINAL
23+
discriminator:
24+
propertyName: type
25+
mapping:
26+
FINAL: '#/components/schemas/FinalItem'
27+
required:
28+
- title
29+
- type
30+
AdditionalData:
31+
type: object
32+
properties:
33+
prop1:
34+
type: string
35+
quantity:
36+
type: integer
37+
format: int32
38+
example: 1
39+
minimum: 1
40+
unitPrice:
41+
type: number
42+
format: double
43+
example: 9.99
44+
minimum: 0.0
45+
totalPrice:
46+
type: number
47+
format: double
48+
example: 9.99
49+
minimum: 0.0
50+
required:
51+
- prop1
52+
- quantity
53+
- unitPrice
54+
- totalPrice

0 commit comments

Comments
 (0)