forked from loafle/openapi-generator-original
* 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
This commit is contained in:
parent
d3dd676960
commit
186ad25cee
@ -297,10 +297,12 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
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.");
|
||||
}
|
||||
|
@ -1473,4 +1473,30 @@ public class SpringCodegenTest {
|
||||
"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);
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
Loading…
x
Reference in New Issue
Block a user