Skip to content

Commit 1f8b90c

Browse files
Fix final warnings
1 parent aa78c38 commit 1f8b90c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3216,7 +3216,6 @@ protected void setAddProps(Schema schema, IJsonSchemaValidationProperties proper
32163216
*/
32173217
private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc, String discPropName, Set<String> visitedSchemas) {
32183218
Schema refSchema = ModelUtils.getReferencedSchema(openAPI, sc);
3219-
ModelUtils.getSimpleRef(sc.get$ref());
32203219
String schemaName = Optional.ofNullable(composedSchemaName)
32213220
.or(() -> Optional.ofNullable(refSchema.getName()))
32223221
.or(() -> Optional.ofNullable(sc.get$ref()).map(ModelUtils::getSimpleRef))
@@ -3258,7 +3257,9 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
32583257
for (Object oneOf : composedSchema.getOneOf()) {
32593258
Schema oneOfSchema = (Schema) oneOf;
32603259
String modelName = ModelUtils.getSimpleRef((oneOfSchema).get$ref());
3261-
CodegenProperty thisCp = discriminatorFound(oneOfSchema.getName(), oneOfSchema, discPropName, visitedSchemas);
3260+
// Must use a copied set as the oneOf schemas can point to the same discriminator.
3261+
Set<String> visitedSchemasCopy = new TreeSet<>(visitedSchemas);
3262+
CodegenProperty thisCp = discriminatorFound(oneOfSchema.getName(), oneOfSchema, discPropName, visitedSchemasCopy);
32623263
if (thisCp == null) {
32633264
once(LOGGER).warn(
32643265
"'{}' defines discriminator '{}', but the referenced OneOf schema '{}' is missing {}",
@@ -3282,7 +3283,9 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
32823283
for (Object anyOf : composedSchema.getAnyOf()) {
32833284
Schema anyOfSchema = (Schema) anyOf;
32843285
String modelName = ModelUtils.getSimpleRef(anyOfSchema.get$ref());
3285-
CodegenProperty thisCp = discriminatorFound(anyOfSchema.getName(), anyOfSchema, discPropName, visitedSchemas);
3286+
// Must use a copied set as the anyOf schemas can point to the same discriminator.
3287+
Set<String> visitedSchemasCopy = new TreeSet<>(visitedSchemas);
3288+
CodegenProperty thisCp = discriminatorFound(anyOfSchema.getName(), anyOfSchema, discPropName, visitedSchemasCopy);
32863289
if (thisCp == null) {
32873290
once(LOGGER).warn(
32883291
"'{}' defines discriminator '{}', but the referenced AnyOf schema '{}' is missing {}",

modules/openapi-generator/src/test/resources/3_0/enum_discriminator_inheritance.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ info:
55
paths:
66
"/animal":
77
get:
8+
operationId: animalGet
89
responses:
910
'200':
1011
description: OK

0 commit comments

Comments
 (0)