-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling of entity tags "etag" #21
Comments
Can you share the OAS you're using with me? I haven't encountered the I can't really give you a timeline for this at the moment, but it'd be nice to add the support. I'm not sure if this could also be supported using the mappings file; I'd have to dig into the details to see if the headers could be dynamically updated by performing the required pre-request within a Dto. |
here is an OAS: {
"paths": {
"/api/v1/items/{item_id}": {
"delete": {
"description": "Delete a specific item",
"operationId": "deleteItem",
"parameters": [
{
"description": "Current ETag of a resource.",
"in": "header",
"name": "If-Match",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"204": {
"description": "No content"
},
"412": {
"description": "Precondition Failed: The provided etag did not match with the current resource"
}
},
"summary": "Delete item",
},
"get": {
"description": "Get an item by ID",
"operationId": "getItemById",
"responses": {
"200": {
"description": "successful operation",
"headers": {
"ETag": {
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"properties": {
"created_at": {
"format": "date-time",
"type": "string"
},
"id": {
"example": "72a8048c-35d2-4745-8af1-7670ef438105",
"format": "uuid",
"readOnly": true,
"type": "string"
},
"itemname": {
"minLength": 1,
"type": "string"
}
},
"type": "object"
}
}
}
},
"404": {
"description": "The resource does not exist"
}
},
"summary": "Get item by id",
},
"parameters": [
{
"description": "the uuid of the item",
"in": "path",
"name": "item_id",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
]
}
}
} The GET returns a string in the ETAG, and when doing the delete the if-match should match that ETAG otherwise a 412 is returned |
Note that it can also happen for POST requests |
Hello,
Some endpoints require an "If-Match" header, for which value comes from a previous request "Etag" header
This is mostly to to avoid concurrent update of a resource
This is used on the updating methods (UPDATE/PUT), and the Etag comes from a GET method
I suggest the algorithm as follow:
Also to be even cleaner there should be some consistency check on the OAS to ensure that the endpoint well has a matching GET, and that it contains an ETAG header, and a check on the response in case it does not contain that ETAG
There could also be a test to validate the 412 response as this is what is being replied in case the If-Match does not match the ETAG
The text was updated successfully, but these errors were encountered: