-
-
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
add oneOf-default-case option for swift5 #19094
Conversation
Hi, thanks for creating this PR. |
For context, this is the PR that contains the flag that I was talking about #11078 |
@4brunu components:
schemas:
Item1:
type: object
required:
- type
properties:
type:
type: string
enum:
- item_1
similar-value:
type: string
Item2:
type: object
required:
- type
properties:
type:
type: string
enum:
- item_2
similar-value:
type: string
SomeOneOfItem:
oneOf:
- $ref: '#/components/schemas/Item1'
- $ref: '#/components/schemas/Item2'
discriminator:
propertyName: type
mapping:
item_1: '#/components/schemas/Item1'
item_2: '#/components/schemas/Item2' Tool will generate this swift representation for out items: public struct Item1: Codable, Hashable {
public enum ModelType: String, Codable, CaseIterable, CaseIterableDefaultsLast {
case item1 = "item_1"
case unknownDefaultOpenApi = "unknown_default_open_api"
}
...
}
public struct Item2: Codable, Hashable {
public enum ModelType: String, Codable, CaseIterable, CaseIterableDefaultsLast {
case item2 = "item_2"
case unknownDefaultOpenApi = "unknown_default_open_api"
}
...
} What makes decoding errors possible (as an example, we can send json like this)
And it is decoded without errors into any of the Item1 or Item2 structures So to be safe, I usually turn this flag off. If this is not a strong contradiction for you, it seems to me much more convenient to separate these flags If I'm wrong somewhere, please correct me. |
Hi, I see. And I would like this to have a more similar name to the other feature, because it's trying to archive the same thing but on a different context. Would we have conflicts if we give it the same name? What do you think of this? |
Hey @Erokha did you had a chance to look into this? |
I will merge this as is and do some small tweaks in a different PR. Thanks for creating this PR 👍 |
#19753 here is the PR with the changes that we talked above. |
Hi, thanks for your tool, it's amazing!
After using it for a while I found out that I need a flag for generating additional default unknown case in OneOf (for client
backward compatibility to avoid decoding fail in earlier client version)
So this is my vision of how it can be done
PR checklist
Commit all changed files.
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*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)