Skip to content

Enabling support for additionalProperties#1449

Open
Pgarrett wants to merge 9 commits intomasterfrom
phg/supportAddProps
Open

Enabling support for additionalProperties#1449
Pgarrett wants to merge 9 commits intomasterfrom
phg/supportAddProps

Conversation

@Pgarrett
Copy link
Collaborator

@Pgarrett Pgarrett commented Feb 12, 2026

Adding support for additionalProperties containing objects. If the target DTO contains additionalProperties, then the generated DTO will contain code like:

@JsonIgnore
private val additionalProperties: MutableMap<String, ChildSchema> = mutableMapOf()

@JsonAnyGetter
fun getAdditionalProperties(): MutableMap<String, ChildSchema> {
    return additionalProperties
}

@JsonAnySetter
fun addAdditionalProperty(name: String, value: ChildSchema) {
    additionalProperties[name] = value
}

Where ChildSchema is the nested object represented in the additionalProperties.

@Pgarrett Pgarrett changed the title Phg/support add props Enabling support for additionalProperties Feb 12, 2026
@Pgarrett Pgarrett marked this pull request as ready for review February 12, 2026 17:58
@Pgarrett Pgarrett requested a review from arcuri82 February 12, 2026 17:59

fun addField(field: DtoField) {
if (field !in fields) fields.add(field)
lateinit var additionalPropertiesDtoName: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... having a lateinit public field that is not initialized on construction (ie in an init{} block) might give issues later on.

}

private fun addAdditionalProperties(dtoClass: DtoClass, additionalProperties: List<PairGene<Gene, Gene>>) {
if (additionalProperties.isNotEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a rule of thumb, we should avoid deep nesting. if you have a function, where most/all of its code is inside an if statement, then the condition should be negated and return from function. eg:

if(additionalProperties.isEmpty()) {
   return
}
//rest of the code here

this makes code much easier to read

}
if (dtoClass.hasAdditionalProperties) {
lines.indented {
lines.add("@JsonIgnore")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain in a comment the need for @JsonIgnore here

}
if (dtoClass.hasAdditionalProperties) {
lines.indented {
lines.add("@JsonAnyGetter")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain in a comment the need for @JsonAnyGetter here

path.toFile().appendText(testFileContent)
}

fun capitalizeFirstChar(word: String) : String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this kind of function should be in a utility class, as can be re-used throughout the codebase. for example, before writing something like this, should check what available in org.evomaster.core.utils... there, you can find StringUtils.capitalization() :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants