@@ -3404,36 +3404,16 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
34043404 CodegenProperty df = DiscriminatorUtils .discriminatorFound (openAPI , composedSchemaName , sc , discPropName , new TreeSet <String >());
34053405 String modelName = ModelUtils .getSimpleRef (ref );
34063406 if (df == null || !df .isString || !df .required ) {
3407- String msgSuffix = "" ;
3408- if (df == null ) {
3409- msgSuffix += discPropName + " is missing from the schema, define it as required and type string" ;
3410- } else {
3411- if (!df .isString ) {
3412- msgSuffix += "invalid type for " + discPropName + ", set it to string" ;
3413- }
3414- if (!df .required ) {
3415- String spacer = "" ;
3416- if (msgSuffix .length () != 0 ) {
3417- spacer = ". " ;
3418- }
3419- msgSuffix += spacer + "invalid optional definition of " + discPropName + ", include it in required" ;
3420- }
3421- }
3422- once (LOGGER ).warn ("'{}' defines discriminator '{}', but the referenced schema '{}' is incorrect. {}" ,
3423- composedSchemaName , discPropName , modelName , msgSuffix );
3407+ once (LOGGER ).warn (getDiscriminatorSchemaError (df , discPropName , modelName , composedSchemaName ));
34243408 }
3425- MappedModel mm = new MappedModel (modelName , toModelName ( modelName ) , modelName , false );
3409+ MappedModel mm = new MappedModel (modelName , modelName , modelName , false );
34263410 descendentSchemas .add (mm );
34273411 Schema cs = ModelUtils .getSchema (openAPI , modelName );
34283412 if (cs == null ) { // cannot lookup the model based on the name
34293413 once (LOGGER ).error ("Failed to lookup the schema '{}' when processing oneOf/anyOf. Please check to ensure it's defined properly." , modelName );
34303414 } else {
3431- Map <String , Object > vendorExtensions = cs .getExtensions ();
3432- if (vendorExtensions != null && !vendorExtensions .isEmpty () && vendorExtensions .containsKey (X_DISCRIMINATOR_VALUE )) {
3433- String xDiscriminatorValue = (String ) vendorExtensions .get (X_DISCRIMINATOR_VALUE );
3434- mm = new MappedModel (xDiscriminatorValue , toModelName (modelName ), modelName , true );
3435- descendentSchemas .add (mm );
3436- }
3415+ discriminatorVendorExtensionValue (cs )
3416+ .ifPresent (discriminatorValue -> descendentSchemas .add (new MappedModel (discriminatorValue , modelName , modelName , true )));
34373417 }
34383418 }
34393419 }
@@ -3483,13 +3463,9 @@ protected List<MappedModel> getAllOfDescendants(String thisSchemaName) {
34833463 }
34843464 currentSchemaName = queue .remove (0 );
34853465 Schema cs = schemas .get (currentSchemaName );
3486- Map <String , Object > vendorExtensions = cs .getExtensions ();
3487- String mappingName =
3488- Optional .ofNullable (vendorExtensions )
3489- .map (ve -> ve .get (X_DISCRIMINATOR_VALUE ))
3490- .map (discriminatorValue -> (String ) discriminatorValue )
3466+ String mappingName = discriminatorVendorExtensionValue (cs )
34913467 .orElse (currentSchemaName );
3492- MappedModel mm = new MappedModel (mappingName , toModelName ( currentSchemaName ) , currentSchemaName , !mappingName .equals (currentSchemaName ));
3468+ MappedModel mm = new MappedModel (mappingName , currentSchemaName , currentSchemaName , !mappingName .equals (currentSchemaName ));
34933469 descendentSchemas .add (mm );
34943470 }
34953471 return descendentSchemas ;
@@ -3560,7 +3536,8 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
35603536 boolean legacyUseCase = (this .getLegacyDiscriminatorBehavior () && uniqueDescendants .isEmpty ());
35613537 if (!this .getLegacyDiscriminatorBehavior () || legacyUseCase ) {
35623538 // for schemas that allOf inherit from this schema, add those descendants to this discriminator map
3563- List <MappedModel > otherDescendants = getAllOfDescendants (schemaName );
3539+ List <MappedModel > otherDescendants =
3540+ adjustModelNames (getAllOfDescendants (schemaName ));
35643541 for (MappedModel otherDescendant : otherDescendants ) {
35653542 // add only if the mapping names are not the same and the model names are not the same
35663543 boolean matched = false ;
@@ -3579,7 +3556,8 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
35793556 }
35803557 // if there are composed oneOf/anyOf schemas, add them to this discriminator
35813558 if (ModelUtils .isComposedSchema (schema ) && !this .getLegacyDiscriminatorBehavior ()) {
3582- List <MappedModel > otherDescendants = getOneOfAnyOfDescendants (schemaName , discriminatorPropertyName , schema );
3559+ List <MappedModel > otherDescendants =
3560+ adjustModelNames (getOneOfAnyOfDescendants (schemaName , discriminatorPropertyName , schema ));
35833561 for (MappedModel otherDescendant : otherDescendants ) {
35843562 // add only if the model names are not the same
35853563 if (uniqueDescendants .stream ().map (MappedModel ::getModelName ).noneMatch (it -> it .equals (otherDescendant .getModelName ()))) {
@@ -8820,4 +8798,16 @@ protected void handleConstantParams(CodegenOperation operation) {
88208798 }
88218799 }
88228800 }
8801+
8802+ /**
8803+ * Adjust the model name of the list of {@link MappedModel} to ensure that the names are consistent with the
8804+ * language specific model name expressed in the {@link CodegenConfig#toModelName(String)} method.
8805+ * @param mappedModels The {@link MappedModel}
8806+ * @return The {@link MappedModel} with the modelName adjusted to the language specific model name.
8807+ */
8808+ private List <MappedModel > adjustModelNames (List <MappedModel > mappedModels ) {
8809+ return mappedModels .stream ()
8810+ .peek (mappedModel -> mappedModel .setModelName (toModelName (mappedModel .getSchemaName ())))
8811+ .collect (Collectors .toList ());
8812+ }
88238813}
0 commit comments