Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Go] fix allOf with multiple ref and discriminator #18390

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading