-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[swift5] Add support for oneOfs #8714
[swift5] Add support for oneOfs #8714
Conversation
Hey @allezxandre, thanks for this great contribution 👍 |
In the |
Looks like that's the implementation for |
I think it's still closer to the implementation of It was my understanding that a Swift implementation of struct FieldAnyOf {
var valueSchemaA: SchemaA?
var valueSchemaB: SchemaB?
// [...]
} Probably not the best implementation out there, but closer to |
I was not really sure how to do this, so I tried something in my last two commits that I just pushed. Tell me if this is what you had in mind. |
Looks good, although I don't know the different between The last commit added a lot o noise to the PR, is that commit needed? |
I also don't like that implementation a lot, but I can't think of a better one. |
I haven't found any hints in the |
I wasn't sure why there was that many files, so I just committed in a separate commit so we could drop it if it's useless. I just added the changes following instructions from the PR template:
Tell me if you want me to drop the commit |
PowerShell, C#, Java, Go, etc |
How will this model an array of oneOf? If I understood correctly the generator will output something like: enum OneOfAOrB {
case a(A)
case b(B)
} which makes sense when it's a property, but when you have an array like enum CollectionOfOneOfAOrB {
case a([A])
case b([B])
} Apologies if this is outside the scope of this PR, just trying to understand the change |
I think here you are confusing an array of oneOfs with a oneOf of arrays. A oneOf of arrays type (like An array of oneOfs (like I hope that answers your question |
@allezxandre Are you looking into it? |
Looking into what? This PR has a working implementation of As for the |
@allezxandre My point was that can you try merging it before the next release? I need it for my swift project too. |
@allezxandre could you please solve the merge conflicts? |
Yes, will do soon |
@allezxandre Hey, did you got a chance to look at the merge conflicts? Can I help in any way? 🙂 |
Sorry, completely forgot about this. I just dropped the commit that added samples not related to Swift, and fast-forwarded to master. |
Travis CI and CircleCI failures are not related to this PR.
Thanks for your help 🙂 |
Alright, let's hope this fixes it (I don't have access to CI logs so I can't be of much help unfortunately) |
Thanks, the remaining CI issues are not related to this PR 👍 |
Tested with 3.0 spec (with oneOf model definitions) and the CI tests passed via https://app.bitrise.io/build/a8f360b8da5fee0d#?tab=log |
* [swift5] Add support for oneOfs * Generate a sample Swift project with oneOfs * Update Swift Samples
@allezxandre plz add support code-generation for array type in OneOf..
in *.YAML - file:
|
@c-villain I don't remember exactly, but I believe this was supported. Can you add a test that breaks so I can see what you're expecting? |
@allezxandre look plz edited comment, no, its not supported |
@allezxandre added bug #9785 for this issue, tried on master (currently 5.2.0), confirmed that array in "one of" not supported |
@allezxandre this feature does not work with the |
This MR relates to issue #7549, and implements support for
oneOf
in Swift.anyOf
fields remain unsupported in this PR (despite the branch name).Given a
oneOf
field namedfield_name
, defined as:the generator will generate a model named
FieldNameOneOf
to hold the values. It is an enumeration with associated values that looks like follows:Usage then goes along something like:
oneOf
s are defined by the OpenAPI spec as:Currently, the generator does not implement validation that the value matches only one subschema, but it might be added in the future if need be.
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. → no change
master
,5.1.x
,6.0.x
→ I guess this is aimed at5.1.x
, but it seems 5.1 changes are integrated into master