Skip to content
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

Generate @frozen enums for operation outputs and request/response bodies #109

Merged
merged 5 commits into from
Jul 12, 2023

Conversation

simonjbeaumont
Copy link
Collaborator

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

Test Plan

Reference test updated.

@simonjbeaumont simonjbeaumont added the 🆕 semver/minor Adds new public API. label Jul 10, 2023
@simonjbeaumont simonjbeaumont requested a review from czechboy0 July 10, 2023 09:20
@simonjbeaumont
Copy link
Collaborator Author

I'm going to move this to draft and mark as blocked for now because there's some more discussion that maybe this is the wrong direction to be moving in for the generated code.

@simonjbeaumont simonjbeaumont marked this pull request as draft July 10, 2023 10:50
Copy link
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm on the implementation, but as you say, this is still being discussed elsewhere.

@czechboy0
Copy link
Contributor

@swift-server-bot test this please

@simonjbeaumont simonjbeaumont marked this pull request as ready for review July 12, 2023 09:07
@simonjbeaumont simonjbeaumont enabled auto-merge (squash) July 12, 2023 09:08
@simonjbeaumont simonjbeaumont merged commit f048771 into apple:main Jul 12, 2023
simonjbeaumont added a commit to simonjbeaumont/swift-openapi-generator that referenced this pull request Jul 12, 2023
@czechboy0 czechboy0 added 🔨 semver/patch No public API change. and removed 🆕 semver/minor Adds new public API. labels Jul 17, 2023
@czechboy0
Copy link
Contributor

Updated from semver/minor to semver/patch, as this isn't a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark operation output and request/response body enums as @frozen
2 participants