Skip to content

Commit

Permalink
Add javadocs to introduced methods
Browse files Browse the repository at this point in the history
  • Loading branch information
david-marconis committed Jan 2, 2025
1 parent 1f8b90c commit f8ebac1
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,19 @@ public CodegenModel fromModel(String name, Schema schema) {
return m;
}

/**
* Sets the default value for an enum discriminator property in the provided {@link CodegenModel}.
* <p>
* If the model's discriminator is defined, this method identifies the discriminator properties among the model's
* variables and assigns the default value to reflect the corresponding enum value for the model type.
* </p>
* <p>
* Example: If the discriminator is for type `Animal`, and the model is `Cat`, the default value
* will be set to `Animal.Cat` for the properties that have the same name as the discriminator.
* </p>
*
* @param model the {@link CodegenModel} whose discriminator property default value is to be set
*/
protected static void setEnumDiscriminatorDefaultValue(CodegenModel model) {
if (model.discriminator == null) {
return;
Expand All @@ -3125,6 +3138,19 @@ protected static void setEnumDiscriminatorDefaultValue(CodegenModel model) {
.forEach(v -> v.defaultValue = getEnumValueForProperty(model.schemaName, model.discriminator, v));
}

/**
* Retrieves the appropriate default value for an enum discriminator property based on the model name.
* <p>
* If the discriminator has a mapping defined, it attempts to find a mapping for the model name.
* Otherwise, it defaults to one of the allowable enum value associated with the property.
* If no suitable value is found, the original default value of the property is returned.
* </p>
*
* @param modelName the name of the model to determine the default value for
* @param discriminator the {@link CodegenDiscriminator} containing the mapping and enum details
* @param var the {@link CodegenProperty} representing the discriminator property
* @return the default value for the enum discriminator property, or its original default value if none is found
*/
protected static String getEnumValueForProperty(
String modelName, CodegenDiscriminator discriminator, CodegenProperty var) {
if (!discriminator.getIsEnum() && !var.isEnum) {
Expand Down

0 comments on commit f8ebac1

Please sign in to comment.