Skip to content

Commit 5c2cebf

Browse files
author
Timo Rohrberg
committed
Fix issue #654: Set discriminator for oneOf mapping correctly.
With the changes of PR #620, the generation of the Type-Info-Annotation for the POJO model classes is broken in case there is a oneOf discriminator mapping in the OpenAPI model. This commit re-introduces the correct generation for those annotation. (cherry picked from commit 3149424c1ea1fbe7447266aeb9b91a1306380900)
1 parent c1ab184 commit 5c2cebf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,17 @@ else if (schema instanceof ComposedSchema) {
13761376
}
13771377
}
13781378
}
1379+
1380+
final List<Schema> oneOf = composed.getOneOf();
1381+
if (oneOf != null && !oneOf.isEmpty()) {
1382+
if (schema.getDiscriminator() != null) {
1383+
codegenModel.discriminator = schema.getDiscriminator();
1384+
if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) {
1385+
codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName()));
1386+
}
1387+
}
1388+
}
1389+
13791390
if (parent != null) {
13801391
codegenModel.parentSchema = parentName;
13811392
codegenModel.parent = toModelName(parentName);

0 commit comments

Comments
 (0)