-
Notifications
You must be signed in to change notification settings - Fork 29
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
Non-optional enum properties with only variant should set a default value #169
Comments
Thanks for the request! A quick question before digging deeper... Does the ASC schema happen to specify a I guess the first question that came to my mind was that maybe we could just expand the behaviour of this option by opening it up to strings/enums and other types? CreateAPI/Sources/CreateAPI/Generator/Generator+Schemas.swift Lines 690 to 695 in 2084450
This flag relies on the schema to have defined the |
The ASC schema does not specify a default in the spec itself, unfortunately. It would've made sense if they had though. My thinking was, considering these values must be set and can canonically only ever have one possible value, it would be practical to follow that logic to its inevitable conclusion and save users the trouble. I will defer to you on how you want this implemented. |
I haven't thought about it too much, but I think it seems like it would be acceptable for
As long as we describe that in the documentation, I think thats a good approach. How does it sound to you? Would you be up for implementing default values from the schema for |
That sounds like a reasonable approach. I'll let you know if I have any more questions! |
In your opinion, if a default value is provided or derived through your approach, how should that affect the optionality of the property? Looking at the edgecases example: public struct Animal: Codable {
...
public var color: String?
public init(... color: String? = nil) {
We provide a default value of "red" in the spec. Another way we could write this is: public struct Animal: Codable {
...
public var color: String
public init(... color: String = "red") {
...but this comes with a different meaning. Should |
If I understand correctly think nullable/optional properties will need to retain their presence because the schema/entity could be used in both requests and responses, and while a So with a that, I'd imagine the generated code for public struct Animal: Codable {
...
public var color: String?
public init(... color: String? = "red") {
|
Hello – I'm working on an App Store Connect API client and have found your library very useful for processing the OpenAPI schema. One thing I've noticed that I believe would improve things for my library users would be to simplify these kinds of cases:
Here we have a struct with a non-optional property, referencing an enum with only variant. As a library author and user I would like to minimize the amount of repetition at the callsite, and one way to do that would be to add a default value for this variant in the initializer. Something like this:
Is that a reasonable enhancement request? I may submit a patch if it isn't too difficult to do.
The text was updated successfully, but these errors were encountered: