Skip to content

Commit 77906ef

Browse files
committed
Use description from child schema for ComposedSchema
1 parent 8a4246c commit 77906ef

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,6 +2820,9 @@ protected void updateModelForComposedSchema(CodegenModel m, Schema schema, Map<S
28202820

28212821
// includes child's properties (all, required) in allProperties, allRequired
28222822
addProperties(allProperties, allRequired, component, new HashSet<>());
2823+
2824+
// use description from child schema
2825+
m.description = escapeText(component.getDescription());
28232826
}
28242827
// in 7.0.0 release, we comment out below to allow more than 1 child schemas in allOf
28252828
//break; // at most one child only

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/KotlinClientCodegenModelTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,36 @@ public void emptyModelKotlinxSerializationTest() throws IOException {
675675
TestUtils.assertFileNotContains(modelKt, "data class EmptyModel");
676676
}
677677

678+
@Test(description = "provide description in kdoc of polymorphic type")
679+
public void testDescriptionOnPolymorphicType() throws IOException {
680+
File output = Files.createTempDirectory("test").toFile();
681+
output.deleteOnExit();
682+
683+
final CodegenConfigurator configurator = new CodegenConfigurator()
684+
.setGeneratorName("kotlin")
685+
.setLibrary("jvm-okhttp4")
686+
.setAdditionalProperties(new HashMap<>() {{
687+
put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson");
688+
put(CodegenConstants.MODEL_PACKAGE, "xyz.abcdef.model");
689+
}})
690+
.setInputSpec("src/test/resources/3_0/kotlin/polymorphism-description.yaml")
691+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
692+
693+
final ClientOptInput clientOptInput = configurator.toClientOptInput();
694+
DefaultGenerator generator = new DefaultGenerator();
695+
List<File> files = generator.opts(clientOptInput).generate();
696+
697+
Assert.assertEquals(files.size(), 28);
698+
699+
final Path animalKt = Paths.get(output + "/src/main/kotlin/xyz/abcdef/model/Animal.kt");
700+
// base has description
701+
TestUtils.assertFileContains(animalKt, "Description on supertype");
702+
703+
final Path birdKt = Paths.get(output + "/src/main/kotlin/xyz/abcdef/model/Bird.kt");
704+
// derived has description
705+
TestUtils.assertFileContains(birdKt, "Description on subtype");
706+
}
707+
678708
private static class ModelNameTest {
679709
private final String expectedName;
680710
private final String expectedClassName;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Example
4+
version: '0.1'
5+
servers:
6+
- url: http://example.org
7+
paths:
8+
'/v1/bird':
9+
get:
10+
responses:
11+
'200':
12+
description: OK
13+
content:
14+
application/json:
15+
schema:
16+
$ref: '#/components/schemas/bird'
17+
operationId: get-bird
18+
components:
19+
schemas:
20+
animal:
21+
type: object
22+
properties:
23+
id:
24+
type: string
25+
required:
26+
- id
27+
discriminator:
28+
propertyName: discriminator
29+
description: 'Description on supertype'
30+
bird:
31+
type: object
32+
allOf:
33+
- $ref: '#/components/schemas/animal'
34+
- properties:
35+
featherType:
36+
type: string
37+
required:
38+
- featherType
39+
description: 'Description on subtype'

0 commit comments

Comments
 (0)