AWeber-Imbi / imbi

An operational management platform for medium to large environments
BSD 3-Clause "New" or "Revised" License
2 stars 12 forks source link

Fix editing of project notes #76

Closed dave-shawley closed 2 years ago

dave-shawley commented 2 years ago

The imbi-ui is sending a PATCH request with a application/json-patch+json document and it is failing with a 415 Unsupported Media Type. It should work based on https://github.com/AWeber-Imbi/imbi-api/blob/c03a33f1ec16f82a595e801d285a96c4bb268e97/imbi/app.py#L68-L70

PATCH /projects/796/notes/6 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 58
Content-Type: application/json-patch+json
Cookie: _ga=GA1.2.1485090374.1630681772; session=2|1:0|10:1666097067|7:session|48:Y2I1NWVkNjAtZDMxNy00ZjViLTg0NmItZTI1NDQ5ODc5ZjEz|36d21091f82347723b5fcffea5a2e2797cfbe0cf297cdab09676a451fe60a2af
Host: imbi.example.com
Origin: https://imbi.example.com
Pragma: no-cache
Referer: https://imbi.example.com/ui/projects/796/notes
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
sec-ch-ua: "Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"

[{"op":"replace","path":"/content","value":"# delete me"}]
HTTP/1.1 415 Unsupported Media Type
Date: Tue, 18 Oct 2022 15:07:12 GMT
Content-Type: application/problem+json
Content-Length: 179
Connection: keep-alive
Server: imbi/0.16.2
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://imbi.example.com
Vary: Origin, Accept-Encoding
Strict-Transport-Security: max-age=15724800; includeSubDomains

{"type": "https://imbi.example.com/#unsupported-media-type", "status": 415, "title": "Unsupported Media Type", "detail": "application/json-patch+json is not a supported media type"}
in-op commented 2 years ago

Perhaps the openapi needs to specify application/json-patch+json instead of application/json?

https://github.com/AWeber-Imbi/imbi-openapi/blob/main/src/endpoints/project_notes.yaml#L109

dave-shawley commented 2 years ago

It was certainly the former ... good 👀

I created the jsonPatch Request component and jsonPatch Schema component to handle the recursive type stuff. It uses a simple top-level recursiveType schema object which recursively references itself based on some github issue on some project (sorry ... that is about as good as my memory gets these days).

dave-shawley commented 2 years ago

Closed with https://github.com/AWeber-Imbi/imbi-openapi/pull/10