json patch dto conversion#1603
Conversation
| } | ||
|
|
||
| // Registers the shared JsonPatchOperation DTO and collects nested DTOs for object/array values. | ||
| private fun calculateDtoFromJsonPatch(gene: JsonPatchDocumentGene) { |
There was a problem hiding this comment.
replace comment with Javadoc
| private fun calculateDtoFromJsonPatch(gene: JsonPatchDocumentGene) { | ||
| val dtoName = GeneToDto.JSON_PATCH_OPERATION_DTO | ||
| val dtoClass = dtoCollector.computeIfAbsent(dtoName) { DtoClass(it) } | ||
| dtoClass.addField(GeneToDto.FIELD_OP, DtoField(GeneToDto.FIELD_OP, "String")) |
There was a problem hiding this comment.
replace "String" with constant value
| } | ||
|
|
||
| private fun anyType(): String { | ||
| return if (outputFormat.isJava()) "Object" else "Any" |
There was a problem hiding this comment.
replace "Object" and "Any" with constant values
| } | ||
|
|
||
| // Renders a JSON Patch document as a List<JsonPatchOperation>, one DTO per active operation. | ||
| private fun getJsonPatchDtoCall(gene: JsonPatchDocumentGene, counters: MutableList<Int>): DtoCall { |
There was a problem hiding this comment.
replace comment with Javadoc
| } | ||
|
|
||
| // Renders a single RFC 6902 operation as a JsonPatchOperation DTO with only its relevant fields set. | ||
| private fun getJsonPatchOperationCall(operation: JsonPatchOperationGene, counters: MutableList<Int>): DtoCall { |
There was a problem hiding this comment.
replace comment with Javadoc
| } | ||
|
|
||
| // Sets the "value" field: primitives are inlined as literals, objects/arrays delegate to DTO generation. | ||
| private fun setJsonPatchValue( |
There was a problem hiding this comment.
replace comment with Javadoc
|
JsonPatchObjectValueDtoEM: |
|
JsonPatchStringValueDtoEM: |
|
I created the two applications and tests, but not with POST, since the POST OpenAPI, lacking a body, would not have the schema to create the resource of a non-primitive object. i left this comment for our meeting, ty! |
|
Please edit your comments to write them in English. |
|
Hi @jgaleotti and @arcuri82! I wanted to flag the relationship between this PR and #1630 before the review continues. This PR (#1603) is the one that should be merged. It fully implements JSON Patch DTO conversion: when dtoForRequestPayload=true, the generated test renders the PATCH body as List instead of a raw JSON string. It includes unit tests and E2E tests covering both primitive and complex value scenarios. PR #1630 was created to address an earlier request from Andrea, proving that a POST (DTO) + PATCH (string) generated test compiles. At the time, JSON Patch DTO wasn't implemented yet, so PATCH silently fell back to string even with the flag ON — that was a limitation, not intended behavior. The assertion in #1630 (assertFalse { generatedCode.contains("JsonPatchOperation") }) now tests the wrong behavior and would fail after merging this PR. For the fallback case (flag OFF → raw string), that path was already implemented before either PR and remains untouched. TL;DR: This PR (#1603) implements the correct behavior we want to mantain. PR #1630 is superseded and can/should be closed. What do you think? I'm sorry for causing the conflict. |
| return Pair(klass, klass.createInstance()) | ||
| } | ||
|
|
||
| private fun assertProperty(klass: KClass<out Any>, instance: Any, propertyName: String, propertyValue: Any?) { |
There was a problem hiding this comment.
isn't this function copied&pasted from other test? avoid code duplication
There was a problem hiding this comment.
Hi @arcuri82, i extracted those functions into SpringTestBase.kt, and updated the tests that used it
In this pr we fix the TO-DO on json patch dtoWritter:
Idea: Create two separate applications and two end-to-end (E2E) tests, clearly documenting what is being tested. These tests should follow the format outlined in core-tests/e2e-tests/spring/spring-rest-openapi-v3/src/test/kotlin/org/evomaster/e2etests/spring/openapi/v3/dtoreflectiveassert/DtoReflectiveAssertEMTest.kt.
The first test should verify that Evomaster can generate the DTO for JSON patch when the values of its operations are primitive( and dtoForRequestPayload=true). The second test should verify that the DTO is generated when the object's value is complex, not primitive.
Additionally, the DTOs can be checked in the generated test suite files.