OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.59k stars 6.29k forks source link

[REQ][Kotlin][Jackson] Add support to enable/disable Jackson's features #11776

Open hpedrorodrigues opened 2 years ago

hpedrorodrigues commented 2 years ago

Is your feature request related to a problem? Please describe.

I'm using the OpenAPI generator to generate a Kotlin client with Jackson as a serialization library, but I cannot customize the object mapper with the generator. If I want to customize it, I need to import the Serializer object and customize it using the property jacksonObjectMapper.

Describe the solution you'd like

I'd like to enable/disable Jackson's features using the generator's config file.

Describe alternatives you've considered

I changed the object mapper directly, accessing Serializer#jacksonObjectMapper.

Additional context

Also, we have some defaults for Java that we're not applying for Kotlin. Is there a specific reason we're not using the same defaults?

Reference:

iaroslav42 commented 2 years ago

+1 for this issue. Currently it's not possible to make it generate Jackson ObjectMapper with FAIL_ON_UNKNOWN_PROPERTIES = false like it's done in Java | Api Client. That makes this generator (when using Jackson) unusable for many (most?) use cases, because the client will be breaking on e.g. adding new fields to API responses (which technically is not a breaking API change).

Is there a specific reason we're not using the same defaults?

Also wondering about that. I guess changing the defaults now would be a breaking change, but to me it feels like the current defaults are kinda wrong (i.e. failing on unknown JSON properties) and inconsistent with Java client generator 🤔

jasenkoh commented 1 year ago

Is there any update on this issue?

AlessandroBagnoli commented 11 months ago

+1 for this issue. Currently it's not possible to make it generate Jackson ObjectMapper with FAIL_ON_UNKNOWN_PROPERTIES = false like it's done in Java | Api Client. That makes this generator (when using Jackson) unusable for many (most?) use cases, because the client will be breaking on e.g. adding new fields to API responses (which technically is not a breaking API change).

Is there a specific reason we're not using the same defaults?

Also wondering about that. I guess changing the defaults now would be a breaking change, but to me it feels like the current defaults are kinda wrong (i.e. failing on unknown JSON properties) and inconsistent with Java client generator 🤔

the breaking on adding new fields to API responses can be avoided with this option in your config.yaml: additionalModelTypeAnnotations: "@com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true)" However, the problem persists whenever new enum values are added to an API. Would be great to have the enumUnknownDefaultCase option available for the Java generator