-
Notifications
You must be signed in to change notification settings - Fork 129
Improve ergonomics when switching over Outputs #104
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
Comments
@clarkkent-superman thanks for filing this issue. As you noted, the API of the generated code is designed to be as expressive as the OpenAPI specification allows. This includes multiple response bodies. The spec for the response object specifies a response have headers and then a content map for various media types—i.e. the headers are shared across all possible content types for that response. You're correct: it does result in a verbose API for simple operations that have a single content type. However, our goal was to generate code that would evolve in a sensible way as the API evolves. For example, when an operation that has a single content type grows the ability to provide an additional body content type. The experience today is that clients will have another enum case to handle, which feels like an idiomatic mapping to Swift. While we want to retain the expressive API layer, we are definitely interested in adding some conveniences/sugar APIs on top if/when they make sense, and we'd definitely welcome a contribution in this area. However, we'd need to have a well-thought-out design first. Issue #22 has some ideas, which might overlap with this issue. Could you elaborate on the flattening you have in mind? Would we then need to duplicate the headers object into each of the response body type enum cases? //cc @czechboy0 |
Just to add to @simonjbeaumont - I think the generated base layer will continue to map the structure of OpenAPI (i.e., we likely won't duplicate the headers in every response enum case just to make the switching easier). However, we're very open to adding sugar on top of the generated base layer. We'd like to see examples of what folks think it should look like, and we can take it from there. Seeing specific ideas also helps us decide whether it should be part of the generated code, or if it should be a separate, e.g. macro package, that folks can explicitly opt-into to get the extra sugar, without growing the generated base layer. A lot of questions, so we need to see some ideas 🙂 |
Tagged as needing design – but feel free to add ideas in this issue until someone puts together a concrete proposal. |
❤️ Nice! |
### Motivation We'd like to run a proposal for generating additional API to simplify providing operation inputs and handling operation outputs for simple API calls with just one successful outcome. ### Modifications - Add SOAR-0007: Shorthand APIs for operation inputs and outputs (See the proposal itself for details)[^1] ### Result n/a ### Test Plan n/a ### Related Issues #22, #104, #105, #145 [^1]: https://github.com/apple/swift-openapi-generator/pull/291/files --------- Signed-off-by: Si Beaumont <[email protected]>
Getting down to the actual response model object requires drilling down through few layers of structs and enums:
I understand there is a requirement to handle multiple response types. If the payload could be flattened into just a body and headers, instead of a struct containing both of these, it would be possible to use the following syntax which would still support multiple response types.
The text was updated successfully, but these errors were encountered: