Skip to content

Commit

Permalink
Go generate all of with multiple ref and discriminator (#18390)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rikotsev committed Apr 16, 2024
1 parent 81f576c commit 1471e7a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ var _ MappedNullable = &{{classname}}{}

// {{classname}} {{{description}}}{{^description}}struct for {{{classname}}}{{/description}}
type {{classname}} struct {
{{#parent}}
{{^isMap}}
{{#parentModel.name}}
{{^isArray}}
{{{parent}}}
{{{parentModel.name}}}
{{/isArray}}
{{/isMap}}
{{#isArray}}
Items {{{parent}}}
Items {{{parentModel.name}}}
{{/isArray}}
{{/parent}}
{{/parentModel.name}}
{{#vars}}
{{^-first}}
{{/-first}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,27 @@ public void verifyApiTestWithNullResponse() throws IOException {
"httpRes, err := apiClient.PetAPI.PetDelete(context.Background()).Execute()");
}

@Test
public void verifyApiWithAllOfMultipleRefAndDiscriminator() throws IOException {
File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();

final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("go")
.setGitUserId("OpenAPITools")
.setGitRepoId("openapi-generator")
.setInputSpec("src/test/resources/3_0/go/allof_multiple_ref_and_discriminator.yaml")
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));

DefaultGenerator generator = new DefaultGenerator();
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
files.forEach(File::deleteOnExit);

TestUtils.assertFileExists(Paths.get(output + "/model_final_item.go"));
TestUtils.assertFileContains(Paths.get(output + "/model_final_item.go"),
"BaseItem");
}

@Test
public void testAdditionalPropertiesWithGoMod() throws Exception {
File output = Files.createTempDirectory("test").toFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
openapi: 3.0.0
info:
title: Test
version: 1.0.0
paths: {}
components:
schemas:
FinalItem:
type: object
allOf:
- $ref: '#/components/schemas/BaseItem'
- $ref: '#/components/schemas/AdditionalData'
BaseItem:
type: object
properties:
title:
type: string
type:
type: string
enum:
- FINAL
example: FINAL
discriminator:
propertyName: type
mapping:
FINAL: '#/components/schemas/FinalItem'
required:
- title
- type
AdditionalData:
type: object
properties:
prop1:
type: string
quantity:
type: integer
format: int32
example: 1
minimum: 1
unitPrice:
type: number
format: double
example: 9.99
minimum: 0.0
totalPrice:
type: number
format: double
example: 9.99
minimum: 0.0
required:
- prop1
- quantity
- unitPrice
- totalPrice

0 comments on commit 1471e7a

Please sign in to comment.