Skip to content
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 @@ -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 @@ -1432,4 +1432,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"