@@ -3216,12 +3216,15 @@ 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- // Identify nameless schemas by their toString.
3220- String schemaKey = Optional .ofNullable (refSchema .getName ()).orElseGet (refSchema ::toString );
3221- if (visitedSchemas .contains (schemaKey )) { // recursive schema definition found
3219+ ModelUtils .getSimpleRef (sc .get$ref ());
3220+ String schemaName = Optional .ofNullable (composedSchemaName )
3221+ .or (() -> Optional .ofNullable (refSchema .getName ()))
3222+ .or (() -> Optional .ofNullable (sc .get$ref ()).map (ModelUtils ::getSimpleRef ))
3223+ .orElseGet (sc ::toString );
3224+ if (visitedSchemas .contains (schemaName )) { // recursive schema definition found
32223225 return null ;
32233226 } else {
3224- visitedSchemas .add (schemaKey );
3227+ visitedSchemas .add (schemaName );
32253228 }
32263229
32273230 if (refSchema .getProperties () != null && refSchema .getProperties ().get (discPropName ) != null ) {
@@ -3242,7 +3245,8 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
32423245 if (composedSchema .getAllOf () != null ) {
32433246 // If our discriminator is in one of the allOf schemas break when we find it
32443247 for (Object allOf : composedSchema .getAllOf ()) {
3245- CodegenProperty cp = discriminatorFound (composedSchemaName , (Schema ) allOf , discPropName , visitedSchemas );
3248+ Schema allOfSchema = (Schema ) allOf ;
3249+ CodegenProperty cp = discriminatorFound (allOfSchema .getName (), allOfSchema , discPropName , visitedSchemas );
32463250 if (cp != null ) {
32473251 return cp ;
32483252 }
@@ -3252,8 +3256,9 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
32523256 // All oneOf definitions must contain the discriminator
32533257 CodegenProperty cp = new CodegenProperty ();
32543258 for (Object oneOf : composedSchema .getOneOf ()) {
3255- String modelName = ModelUtils .getSimpleRef (((Schema ) oneOf ).get$ref ());
3256- CodegenProperty thisCp = discriminatorFound (composedSchemaName , (Schema ) oneOf , discPropName , visitedSchemas );
3259+ Schema oneOfSchema = (Schema ) oneOf ;
3260+ String modelName = ModelUtils .getSimpleRef ((oneOfSchema ).get$ref ());
3261+ CodegenProperty thisCp = discriminatorFound (oneOfSchema .getName (), oneOfSchema , discPropName , visitedSchemas );
32573262 if (thisCp == null ) {
32583263 once (LOGGER ).warn (
32593264 "'{}' defines discriminator '{}', but the referenced OneOf schema '{}' is missing {}" ,
@@ -3275,8 +3280,9 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
32753280 // All anyOf definitions must contain the discriminator because a min of one must be selected
32763281 CodegenProperty cp = new CodegenProperty ();
32773282 for (Object anyOf : composedSchema .getAnyOf ()) {
3278- String modelName = ModelUtils .getSimpleRef (((Schema ) anyOf ).get$ref ());
3279- CodegenProperty thisCp = discriminatorFound (composedSchemaName , (Schema ) anyOf , discPropName , visitedSchemas );
3283+ Schema anyOfSchema = (Schema ) anyOf ;
3284+ String modelName = ModelUtils .getSimpleRef (anyOfSchema .get$ref ());
3285+ CodegenProperty thisCp = discriminatorFound (anyOfSchema .getName (), anyOfSchema , discPropName , visitedSchemas );
32803286 if (thisCp == null ) {
32813287 once (LOGGER ).warn (
32823288 "'{}' defines discriminator '{}', but the referenced AnyOf schema '{}' is missing {}" ,
0 commit comments