-
Notifications
You must be signed in to change notification settings - Fork 129
Mark operation output and request/response body enums as @frozen #105
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
@PadraigK thanks for the suggestion. We do generate @czechboy0 might have some opinions here. Assuming there's no reason not to, is it something you'd want to work on? Footnotes
|
Yeah we should add it to all our enums, I don't think there are any downsides. |
Great, should be a simple change in |
@PadraigK I've opened a PR for this. I retitled the issue to make it a little clearer for posterity, because there's a bunch of enums we generate which don't have any cases (just namespace types). Thanks again for taking the time to try out the generator and for filing the issue! |
I discussed this some more with some folks and there's some feedback that we might not want to do this. To summarise, they highlighted that adopters should only be forced to add the As I highlighted earlier in this issue thread, we are currently already using I think we should take a consistent approach here. My PR moved us in the direction of consistent application of |
@PadraigK
Adding |
I'm for adding it everywhere, since it's a no-op to code not using library evolution, and solves a major usability issue for folks using library evolution. It's asymmetrical, so for pragmatic reasons here, I'd do the thing that unblocks a set of adopters, and doesn't hurt other adopters. That said, we should probably also add a paragraph to our docs about how to use generated code, and mention that the generated code is not designed for having a stable ABI (like we already call out the lack of a stable API). |
I don't think I agree with this. The problem is if we start adding annotations for library evolution such as However, adopters do have a way out of this. When they want to ship an ABI stable framework that uses generated code and the runtime they just need to make sure that all imports are marked with |
The argument makes sense, but it seems other Apple packages do exactly this – have
Based on the examples above, it seems okay to me to both not explicitly support a stable ABI, but also help eventual ABI maintainers convey the right meaning about allowed changes to types.
For the generated code, we explicitly warn against assuming stable API in our docs, and I proposed adding an explicit section about the ABI as well, removing any ambiguity. For the runtime library code, we also document the API stability guarantees here, and here too, we could add an explicit counter-promise of ABI stability.
I don't think it's about the warnings and errors, it's about having to cover codepaths that will never be taken at runtime, artificially increasing the cyclomatic complexity of every adopter who pulls in a library with LE enabled. Adopters can just as well add
That's correct, but more than the responsibility of every library, that's the responsibility of the author of the LE-enabled library. The author is responsible for maintaining a stable ABI, even if they republish types from their dependencies. For example, they could evolve their LE-enabled library in a way that they never update their dependencies within the same major version of their LE-enabled library, guaranteeing that only their hand-written code needs to be ABI-stable. We don't know, but as evidenced by the other Apple packages, I don't think the burden of enforcing this is on each library, but instead is on the LE-enabled library author. Re |
After talking with @czechboy0 about this offline. I am fine with us adopting the One suggestion though might be that we provide a configuration option which enables the generation of |
We've not really added any configuration options so far, but this is not the first issue that could justify adding one. I'd be open to us starting to use it more. |
I think we should think about how we could add configuration for cases where users genuinely need both options, in a backwards-compatible way. Here, I'm not sure it's needed yet, as always adding As you can imagine, the cost of each configuration option in the generator is adding a whole axis to the test matrix, so it's not cheap, and each of them need to be well justified. I'm not saying this one isn't, just that we should start without it (make the behavior consistent, add |
So where are we landing on this one? Should we merge #109 as-is (i.e. generating |
…ies (#109) ### Motivation The generated code contains several enum types. A lot of these are just namespaces (i.e. the enum has no cases), but some are "proper" enums that we expect adopters to switch over. For example the operation output, and the request and response bodies. To make using these types more ergonomic, we can annotate them as `@frozen`. This is something we already do for other generated enum types (e.g. OneOf and enum types declared in the OpenAPI document). ### Modifications - Add desired `@frozen` attributes to reference code - Generate `@frozen` enum for request bodies - Generate `@frozen` enum for response bodies - Generate `@frozen` enum for operation outputs ### Result Switching over operation outputs and request/response bodies is simpler. ### Resolves - Resolves #105. ### Test Plan Reference test updated. --------- Signed-off-by: Si Beaumont <[email protected]>
### 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]>
Since it's not expected that the generated code should support library evolution, we could add @Frozen to all of the generated enums. This would greatly improve the ergonomics of switching over enums in the generated code.
Borrowing an example from another issue:
would become
The text was updated successfully, but these errors were encountered: