@@ -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 {}" ,
0 commit comments