Skip to content

[Generator] Stop generating an undocumented case for enums/oneOfs #205

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

Merged
merged 4 commits into from
Aug 17, 2023

Conversation

czechboy0
Copy link
Contributor

@czechboy0 czechboy0 commented Aug 16, 2023

Motivation

Fixes #204.

Depends on apple/swift-openapi-runtime#40.

Modifications

This introduces the feature flag closedEnumsAndOneOfs which stops generating the undocumented case for enums and oneOfs (no other places are affected, such as responses, and so on.). The default behavior in 0.1.x stays the same, but in 0.2.0 we'll stop generating undocumented cases unconditionally.

This fixes our divergence from the OpenAPI specification, as we treated enums and oneOfs as open, but they're closed by default.

I also added docs on this pattern to make it easier for adopters to know how to create open enums and oneOfs on purpose.

Result

We get closer to being spec-compliant.

Test Plan

Created new snippet tests to verify the new functionality, will adapt file-based tests when we're preparing 0.2.0.

@czechboy0 czechboy0 changed the title Stop generating an undocumented case for enums/oneOfs [Generator] Stop generating an undocumented case for enums/oneOfs Aug 17, 2023
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

LGTM. Helpful docs too!

czechboy0 added a commit to apple/swift-openapi-runtime that referenced this pull request Aug 17, 2023
[Runtime] Stop generating an undocumented case for enums/oneOfs

### Motivation

Runtime side of apple/swift-openapi-generator#205

### Modifications

Added a helper function that produces the right error.

### Result

Generated code can use this error to throw when an unknown case is encountered.

### Test Plan

Tested together with the generator.


Reviewed by: glbrntt

Builds:
     ✔︎ pull request validation (5.8) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (api breakage) - Build finished. 
     ✔︎ pull request validation (docc test) - Build finished. 
     ✔︎ pull request validation (integration test) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

#40
@czechboy0 czechboy0 enabled auto-merge (squash) August 17, 2023 13:58
@czechboy0 czechboy0 merged commit 269b31d into apple:main Aug 17, 2023
@czechboy0 czechboy0 deleted the hd-close-enums-and-oneOfs branch August 17, 2023 14:31
@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Aug 21, 2023
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.

Stop generating an undocumented case for enums/oneOfs
3 participants