Skip to content

Commit

Permalink
fix: [JAVA/SPRING] [#12692] fixed optional config property legacyDisc… (
Browse files Browse the repository at this point in the history
#12713)

* fix: [JAVA/SPRING] [#12692] fixed optional config property legacyDiscriminatorBehavior always being overwritten to false in spring codegen

* feat: [JAVA/SPRING] [#12692] spaces instead of tabs

* feat: [JAVA/SPRING] [#12692] spaces instead of tabs in test

* fix: [JAVA/SPRING] [#12692] added comment

* fix: [JAVA/SPRING] [#12692] spaces instead of tabs

* fix: [JAVA/SPRING] [#12692] spaces instead of tabs in test
  • Loading branch information
LubomirS authored Aug 8, 2022
1 parent d3dd676 commit 186ad25
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,12 @@ public void processOpts() {
LOGGER.info("Set base package to invoker package ({})", basePackage);
}

super.processOpts();
useOneOfInterfaces = true;
legacyDiscriminatorBehavior = false;

// Please refrain from updating values of Config Options after super.ProcessOpts() is called
super.processOpts();

if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
LOGGER.warn("The springfox documentation provider is deprecated for removal. Use the springdoc provider instead.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1473,4 +1473,30 @@ public void shouldHandleContentTypeWithSecondWildcardSubtype_issue12457() throws
"consumes", "{ \"application/octet-stream\", \"application/*\" }"
));
}

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

OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/bugs/issue_12692.yml", null, new ParseOptions()).getOpenAPI();
SpringCodegen codegen = new SpringCodegen();
codegen.setLibrary(SPRING_BOOT);
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR, "true");

ClientOptInput input = new ClientOptInput()
.openAPI(openAPI)
.config(codegen);

DefaultGenerator generator = new DefaultGenerator();
generator.opts(input).generate();

String jsonTypeInfo = "@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = \"type\", visible = true)";
String jsonSubType = "@JsonSubTypes({\n" +
" @JsonSubTypes.Type(value = Cat.class, name = \"cat\")" +
"})";
assertFileContains(Paths.get(output.getAbsolutePath() + "/src/main/java/org/openapitools/model/Pet.java"), jsonTypeInfo, jsonSubType);
}
}
45 changes: 45 additions & 0 deletions modules/openapi-generator/src/test/resources/bugs/issue_12692.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
openapi: 3.0.1
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
paths:
"/pets":
get:
operationId: listPets
responses:
'200':
description: description
content:
application/json:
schema:
type: array
items:
"$ref": "#/components/schemas/Pet"
components:
schemas:
Pet:
type: object
required:
- type
properties:
type:
type: string
discriminator:
propertyName: type
mapping:
cat: "#/components/schemas/Cat"
Cat:
allOf:
- "$ref": "#/components/schemas/Pet"
- type: object
required:
- type
properties:
type:
type: string
discriminator:
propertyName: type
mapping:
cat: "#/components/schemas/Cat"

0 comments on commit 186ad25

Please sign in to comment.