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.51k stars 6.27k forks source link

To fix how the deserializer interacts with its parent class #18976

Closed qbuzzdaan closed 3 days ago

qbuzzdaan commented 1 week ago

Changes how an StdDeserializer<A> of a specific type A deserializes into an A. We noticed the static block filling the mappings passed to the JSON.registerDiscriminator(A.class, "type", mappings) was only called after the first call to the deserializer, causing the first result to have an setActualInstance call of the wrong subtype of A. This is because the static block is part of A, while the StdDeserializer<A> is a static subclass of A. Changing the reference to A.class into an actual instance of A by the new A().getClass() causes the static block to be called on time.

to fix #18975

PR checklist

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)

wing328 commented 1 week ago

thanks for the PR.

please follow step 3 to update the samples so that the CI can verify the change.

qbuzzdaan commented 1 week ago

First commit/PR here, trying my best to follow the steps/guidelines etc :) Ran the commands of steps 3, there are no changes in the samples as it seems.

wing328 commented 5 days ago

can you please share a spec to reproduce the issue?

qbuzzdaan commented 5 days ago

I've added the issue_18975.yaml spec. Running step 3 again again didn't yield any changes in my repository.

wing328 commented 3 days ago

tested locally and the output copmiles without issue. let's give it a try

i'll add a test after merging this PR

thanks again for the PR