-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[Typescript] Fix oneOf #9628
[Typescript] Fix oneOf #9628
Conversation
Any updates on this? |
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.
Thanks for your contribution! The fix looks good to me - as far as I can see what it does.
Could you please add unit tests, both to demonstrate the fix working and to prevent regressions in future?
And if you even feel like going an extra mile here - it would be super beneficial (and highly appreciated! :) ) to add a sample with oneOf/allOf (looks like no existing typescript samples use a spec with this feature - #5335)
@@ -144,10 +147,12 @@ public TypeScriptClientCodegen() { | |||
typeMapping.put("object", "any"); | |||
typeMapping.put("integer", "number"); | |||
typeMapping.put("Map", "any"); | |||
typeMapping.put("map", "any"); |
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.
why do we need this?
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.
Thanks for your contribution! The fix looks good to me - as far as I can see what it does.
Could you please add unit tests, both to demonstrate the fix working and to prevent regressions in future?And if you even feel like going an extra mile here - it would be super beneficial (and highly appreciated! :) ) to add a sample with oneOf/allOf (looks like no existing typescript samples use a spec with this feature - #5335)
Hi
there is only oneOf but after this fix It would be much easy to add allOf
I don’t know about unit tests but I'll try to look
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.
I added
typeMapping.put("map", "any");
because I saw it in codegen
import { ModelMap } from './ModelMap';
it was adding to every model
I researched how it was fixed at typescript-node
and done the same
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.
Lines 163 to 164 in 46f8a67
typeMapping.put("Map", "any"); | |
typeMapping.put("map", "any"); |
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.
@amakhrov ^^
Hi |
I have spent some time thinking about how to "properly" implement oneOf/anyOf/allOf in the context of the generator. I believe the current solution is not sufficient, due to 2 reasons
Fixing this will be quite a bit of effort, as we need to
as |
Frankly, accurately representing Also for the purpose of (de)serialization, we don't have to be type strict. Whatever properties are present in the input, we deserialize then to a corresponding type, assuming there is no conflicting props between A/B/C. And it's a job for the validator to ensure no conflicts, not a job for the serializer. Imo :) |
I agree with @amakhrov :-) Both CI failures are unrelated (1 due to pull rate limit, 1 due to CSharp Generator Tests). Let me try if we can get at least that other one to work. |
Alright. Merging this :-). Thank you for the PR!
|
#9305
Doesn’t work "oneOf"
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x