-
Notifications
You must be signed in to change notification settings - Fork 130
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
Support oneOf
required
sections
#739
Comments
Hi @philippzagar, that's right, the generator currently doesn't support "merging" JSON schemas from multiple places (in this instance, merging the This won't be a trivial fix. If I'm reading it correctly, a simplified version of the above would be: type: object
properties:
a:
type: string
b:
type: integer
oneOf:
- required: [a]
- required: [b] In other words, it expresses that there's an object with properties What Swift code would you want generated for this pattern? |
Hey @czechboy0, thanks for the quick answer! Yep, your minimal example is correct! struct Object: Codable, Hashable, Sendable {
var a: String?
var b: Int?
init(a: String, b: Int?) { self.a = a; self.b = b }
init(a: String?, b: Int) { self.a = a; self.b = b } // Parameter order might violate common Swift pattern of having optional parameters last
} Of course, this isn't a perfect representation of the OpenAPI pattern in Swift, but I guess it's the best we'll get? I imagine this might require some additional effort to get right, but it could be worthwhile to adjust the generator to at least not emit warnings (is there a non-ugly fix?), regardless of any changes to code generation. |
# OpenAPI spec preprocessing ## ♻️ Current situation & Problem The OpenAI OpenAPI specification contains the following issues that require preprocessing before code generation: - **Incorrect `required` Property**: A non-existent property is incorrectly marked as `required` (see [`openai-openapi#421`](openai/openai-openapi#421)). - **Unsupported `oneOf` Syntax**: The `swift-openapi-generator` does not fully support `oneOf` with `required` properties (see [`swift-openapi-generator#739`](apple/swift-openapi-generator#739)). - **Deprecation Warnings**: `deprecated` markings in the OpenAPI spec trigger warnings in the generated Swift code (see [`swift-openapi-generator#106`](apple/swift-openapi-generator#106) and [`swift-openapi-generator#715`](apple/swift-openapi-generator#715)). Without preprocessing, these issues result in unnecessary warnings during the Swift code generation and in the resulting Swift client code. ## ⚙️ Release Notes - Add OpenAPI spec preprocessing script - Preprocess OpenAPI OpenAI spec ## 📚 Documentation README for proper motivation for the need of preprocessing and usage instructions. ## ✅ Testing Local testing ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
Pragmatically, the easiest way to remove the warnings is to pre-process the OpenAPI doc and remove the
struct Object: Codable, Hashable, Sendable {
var a: String?
var b: Int?
init(a: String, b: Int?) { self.a = a; self.b = b }
init(a: String?, b: Int) { self.a = a; self.b = b } // Parameter order might violate common Swift pattern of having optional parameters last
} All types generated today by Swift OpenAPI are usable both on the request and response side, so have to enforce rules both on serialization and deserialization paths. In the example above, the payload This is a very reasonable feature request, but I'll also be honest by saying that it's non-trivial amount of work, and will require some creative design here 🙂 |
That's exactly what we're doing right now to prevent warnings being emitted. I understand that this the best pragmatic solution for now, but I feel that long-term the generator should support specs like the popular (and valid) OpenAI spec without emitting warnings :)
Thanks for the clarification and context here! I just laid out a very minimalistic envisioned Swift code, there will be some more complications along the way for sure!
Thank you for looking into that! Will follow this issue closely! Please let me know if I can be of any help 🚀 |
If you'd like to investigate potential paths forward here, that'd be appreciated. It's unlikely we'll have time to invest into this in the short term. But I agree that long term, we'd like to support this feature. I suspect the next steps are:
|
Description
As described in openai/openai-openapi#391, the OpenAI OpenAPI specification contains the following
oneOf
required
definitions:While not wrong in OpenAPI 3.0 or 3.1, the
swift-openapi-generator
doesn't properly recognize thatrequired
definition and produces the following warnings:The
swift-openapi-generator
should support this valid syntax.Reproduction
The usage of the following OpenAI OpenAPI spec results in the
swift-openapi-generator
not properly recognizing therequired
definition and produces warnings.A small excerpt of the relevant piece of the OpenAI OpenAPI spec:
Swift Generator config:
Results in the following warnings:
Package version(s)
Expected behavior
The
oneOf
required definition should be properly recognized by the generator and used for the Swift output generation.Environment
Additional information
No response
The text was updated successfully, but these errors were encountered: