-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java: allow aliased types to have custom mappings #4182
Conversation
Fixes OpenAPITools#2858 This will allow `kubernetes-client-java` to switch to openapi-generator, since the kubernetes API swagger spec has types aliased to primitive types (e.g. intstr.IntOrString => string) that need to be mapped to custom types (and not be treated as a primitive type).
Thank you for figuring this out!!! |
awesome! politely bump @wing328 for a review! |
Looks good but I'll need to test it locally tomorrow (as it's 1am here ...) before merging it into master |
Please hold on merging. I suspect there's more involved here. |
I believe this is now good to be merged. I did some more digging, and found that From
With the changes in this PR I was able to tweak code generation for |
The tweaks to the configuration, and rewriting of the spec I had to do are here: yue9944882/gen#1 |
great, i will rebase kubernetes-client/gen#117 after this pull is merged&released |
@yue9944882 we will also need #4226 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the update. I'll review and run some tests locally. |
@fabiokung I tested it locally but no luck getting it working locally. Here is how I tested with fake petstore spec:
I also tested with https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json but no luck with Am I testing the change correctly? |
@wing328 I think I misunderstood how aliases are supposed to work, and this patch may not be necessary anymore (the term My conclusion is that this PR was not the root cause of why In the end, I made the custom type mapping work (yue9944882/gen#1) by forcing all types that needed a mapping to have a diff --git a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
index 73d734f75f..9028469cd2 100644
--- a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
+++ b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
@@ -1729,6 +1729,7 @@ definitions:
type: number
OuterString:
type: string
+ format: outerStringFormat
OuterBoolean:
type: boolean
x-codegen-body-parameter-name: boolean_post_body Then:
I'd still say all definitions should be able to have a custom |
I take that back, the changes are not going to be trivial. For some reason I will leave that up to others that are more familiar with the codebase. @wing328 feel free to close and track improvements to type mappings in a different GH issue. |
@wing328 @fabiokung thank you for the deep insight. iiuc, tweaking a custom format is not supported in openapi specification, so the |
@fabiokung @yue9944882 I think I may have a better solution to come up with something you guys need. Will share later today when I've the details. |
The following seems to work for me to meet your requirement mapping IntOrString (schema) to something else and do a proper import accordingly:
Can you plesae give it a try? |
@wing328 This seems to be exactly what I did already - #4182 (comment), unless I’m missing something?
|
@yue9944882 yes, I believe the changes I sent you through yue9944882/gen#1 fixes kubernetes-client/java#721, this PR is not needed because it relies on the custom format. |
I edited the original PR description to make it clear this PR per-se is not fixing anything, and while I think it improves the code a bit, it is not really necessary. |
Thanks for the clarification. I'll let others take a look and see if they've any comments on the change. |
@yue9944882 I got a notification from your comment saying you couldn't make custom type mappings work with kubernetes-client/gen#117, but the comment seems to have gone away. Were you able to make it work? |
Closing as this is not really needed, and ended up just being a red herring and suggestion for improvements to the code. |
Fixes #2858.UPDATE: I was wrong and misundertood the code, this PR does not fix the issue, but #4182 (comment) discusses an alternative on how to accomplish the same. I'd still consider the original issue to be a bug, it should be possible to define type mappings for any type definition in the spec.This will allow
kubernetes-client-java
to switch to openapi-generator (kubernetes-client/java#709).The kubernetes API swagger spec has types aliased to primitive types, e.g.:
However, these types need to be mapped to custom types in the Java client, so we can have custom serialization for them. The generator is being invoked with the following options:
Without changes in this PR,
type-mappings
gets ignored, sinceIntOrString
is first resolved to its alias (string
), before mappings are evaluated.cc @wing328 @brendandburns @yue9944882