ogen icon indicating copy to clipboard operation
ogen copied to clipboard

Allow content-type `application/merge-patch+json`

Open uga-rosa opened this issue 1 year ago • 3 comments

Description

First, thank you for a great generation tool!

In a patch request, there is a meaningful difference between setting a field to null and a field being missing, but handling this in Go can be challenging. I was looking for projects that are seriously addressing this issue.

https://ogen.dev/docs/types/optional/

However, despite such excellent efforts, I realized that it is not possible to use the content-type application/merge-patch+json.

The internal processing should be almost the same as JSON, so the necessary implementation can be kept to a minimum. I would appreciate your support.

References

uga-rosa avatar Nov 23 '24 03:11 uga-rosa

Same is probably true for e.g. application/problem+json (see).

AndreasBergmeier6176 avatar Mar 26 '25 11:03 AndreasBergmeier6176

Or application/scim+json (https://datatracker.ietf.org/doc/html/rfc7644). Basically, +json should be accepted for custom mime types. Alternatively: a config setting to specify custom mime types and how to treat them.

aksdb avatar Apr 03 '25 12:04 aksdb

We can use the content_type_aliases option to support these types, like this:

  content_type_aliases:
    application/problem+json: "application/json"
    application/merge-patch+json: "application/json"

ref. https://github.com/ogen-go/ogen/blob/72cb51bbb505cc9472bec11ca93a26c9e1e8c1e4/gen/options.go#L173-L174

It might be helpful to include this in the documentation or examples, since supporting custom MIME types is a fairly common need.

thara avatar Jul 12 '25 11:07 thara