Skip to content

http oracle partial update put#1471

Open
omursahin wants to merge 9 commits intomasterfrom
oracle-partial-update-put
Open

http oracle partial update put#1471
omursahin wants to merge 9 commits intomasterfrom
oracle-partial-update-put

Conversation

@omursahin
Copy link
Copy Markdown
Collaborator

No description provided.

@omursahin omursahin requested a review from arcuri82 April 3, 2026 07:24
* PUT /path -> 2xx (successful update/create with body B)
* GET /path -> 2xx (must return exactly the fields that were PUT)
*
* Returns true if any field sent in the PUT body has a different value
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is partial. you need also to check that GET is not returning fields not used in the PUT. or, if those are returned, if they are null

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also, need to check the differences in what declared in the schema, eg, the resource might have fields that are not supposed to be changed via a PUT (eg timestamps or ids)

val putBody = extractRequestBody(put)
val getBody = resGet.getBody()

if (putBody.isNullOrEmpty() || getBody.isNullOrEmpty()) return false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if putBody is empty, but getBody is not, then we got a bug

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I also added this statement: if putBody is not empty, but getBody is. What do you think about that? Is that correct or lead to false positives?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@omursahin hi, yes, should be fine, i guess shouldn't harm. but, anyway, those cases should still be handled when looking at fields one by one, isn't it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

For this,
if (putBody.isNullOrEmpty() && !getBody.isNullOrEmpty()) return true
yes, you are right. I am updating it now.

But I guess we don't need to check fields for this statement:
if (!putBody.isNullOrEmpty() && getBody.isNullOrEmpty()) return true
Because if we send any value with put, we expect that it should be returned in the get body, right?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yep, if send with PUT, we expect in GET.


if (putBody.isNullOrEmpty() || getBody.isNullOrEmpty()) return false

val fieldNames = extractModifiedFieldNames(put)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

here it should rather check the field names of what declared in the schema of the PUT. i have added some more discussion and examples to 2026/httporacles/notes.txt

@omursahin omursahin requested a review from arcuri82 April 14, 2026 17:08

if (!StatusGroup.G_2xx.isInGroup(resPut.getStatusCode())) return false
// if put returned 2xx but entity does not exist afterwards
if (resGet.getStatusCode() == 404) return true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

that's a good point... can you update 2026/httporacles/notes.txt mentioning it? it will be helpful in few weeks/months when we are going to use those notes as starting point for a paper :)

if (!StatusGroup.G_2xx.isInGroup(resGet.getStatusCode())) return false

val bodyParam = put.parameters.find { it is BodyParam } as BodyParam?
if (bodyParam != null && !bodyParam.isJson() && !bodyParam.isXml() && !bodyParam.isForm()) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add a comment, specifying that for now we only deal with JSON/XML/FORM. also, clarify what would happen when bodyParam is null


// PUT sent content but GET body is empty -> sent fields definitely missing
if (!putBody.isNullOrEmpty() && getBody.isNullOrEmpty()) return true
if (getBody.isNullOrEmpty()) return false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

refactor for clarity, eg, something like:

if (getBody.isNullOrEmpty()) {
     return !putBody.isNullOrEmpty()
}

private fun isWipedFieldStillPresent(value: String?): Boolean {
if (value == null) return false
if (value.isEmpty()) return false
if (value == "null") return false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i m a bit unsure about this "null" check. are you sure that you can properly distinguish between:

{"x": null} (empty value)

and

{"x": "null"} (value is present, ie., a string with 4 characters)

make sure to have at least 1 test case to check this

return objectGene.fields.map { it.name }.toSet()
}

// Extract only the field names that were actually sent in the request body.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

for method comments, remember to use JavaDoc styel /** */ and not //


val gene = bodyParam.primaryGene()
val objectGene = gene.getWrappedGene(ObjectGene::class.java) as ObjectGene?
return gene.getWrappedGene(ObjectGene::class.java) as ObjectGene?
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

keep in mind that a body could be optional (ie, not marked as required), and so inside an OptionalGene. if this latter is off (ie, not active), then nothing is sent. should check this

* Returns the property names from the PUT request body schema in the OpenAPI spec.
* Used as a fallback to determine writable fields when no BodyParam is present on the action.
*/
internal fun extractPutRequestSchemaFields(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this feels like a general function... could be extracted in a utility class, as could be re-used in other places as well

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe in SchemaUtils?

SchemaUtils.getReferenceSchema(schema, schema.main, it, mutableListOf())
} ?: rawSchema

return resolved.properties?.keys?.toSet() ?: emptySet()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

schema analysis is very TRICKY... as you could have $ref at each point in the tree... and those override any sibling node :( need more checks and unit tests for this

RestCallAction is created based on content of schema, but taint analysis could had been involved... so still make sense to look at original schema for these checks

*/
internal fun extractGetResponseSchemaFields(
schema: RestSchema,
get: RestCallAction
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

as the other function, could be refactored into SchemaUtils

val op = pathItem.get ?: return emptySet()

// pick the first 2xx response, falling back to "default"
val response = op.responses?.entries
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

as for other function, need to check for the presence of $ref at each point in the tree where it can be present

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