ogen-go / ogen

OpenAPI v3 code generator for go
https://ogen.dev
Apache License 2.0
1.42k stars 83 forks source link

Feature Request: A way to generate a map[string]any #1313

Open veqryn opened 1 month ago

veqryn commented 1 month ago

Description

Right now in my OpenAPI yaml, we have a component with a field that is marked as follows:

type: object
additionalProperties: true

This results in a generated object like this: map[string]jx.Raw, where jx.Raw is a []byte under the hood. That is pretty hard to use. I'd have to manually json marshal every single property, rather than just setting them all and letting the whole thing be json marshalled.

I've tried 3 other OpenAPI code generators, and they all give me a map[string]any, letting us use this field for any key-value pairs (this is our desired goal).

This change should be backwards compatible, as jx.Raw counts as an any.

The ogen server/client should take care of marshalling the any value into json. I also don't think that ogen should be exposing jx, as that is an implementation detail.

dejanzele commented 1 month ago

Hi all,

As we use ogen extensively in our project, this option would also benefit us.

I'd be willing to submit a PR for it if the maintainers agree or maybe even give some guidelines.