Skip to content

Use the package access modifier for generated code #270

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

Closed
glbrntt opened this issue Sep 13, 2023 · 2 comments · Fixed by #393
Closed

Use the package access modifier for generated code #270

glbrntt opened this issue Sep 13, 2023 · 2 comments · Fixed by #393
Assignees
Labels
area/generator Affects: plugin, CLI, config file. kind/enhancement Improvements to existing feature. size/S Small task. (A couple of hours of work.) status/blocked Waiting for another issue.
Milestone

Comments

@glbrntt
Copy link
Contributor

glbrntt commented Sep 13, 2023

Swift 5.9 adds the new package access modifier (see the evolution proposal).

This is a very natural fit for the generated code as:

  • Users are encouraged to wrap the generated types rather than vending them directly as part of their package.
  • Users are encouraged to generate code for into separate modules per document.

However, it's likely that some users will still want to vend generated code.

I think the generator should provide a configuration option for visibility so that the user can decide. The default should likely be set to the new package access level.

@czechboy0
Copy link
Contributor

Agreed, we should offer:

  • package (new option, new default) - this will be a breaking change, so needs to happen e.g. in 0.3.0 or 1.0
  • public (old default)
  • internal (new option)

@czechboy0 czechboy0 added area/generator Affects: plugin, CLI, config file. kind/enhancement Improvements to existing feature. size/S Small task. (A couple of hours of work.) labels Sep 13, 2023
@czechboy0 czechboy0 added this to the 0.3.0 milestone Sep 13, 2023
@czechboy0
Copy link
Contributor

This is blocked on 5.9 adoption: #75

@czechboy0 czechboy0 added the status/blocked Waiting for another issue. label Sep 13, 2023
@czechboy0 czechboy0 modified the milestones: 0.3.0, 1.0 Sep 25, 2023
@czechboy0 czechboy0 self-assigned this Nov 27, 2023
czechboy0 added a commit that referenced this issue Nov 27, 2023
### Motivation

Fixes #270.

The `package` access modifier seems like the right default access
modifier for generated code, as it forces adopters to explicitly opt
into generated APIs leaking outside of their package. `internal` was too
limiting, as often you want to isolate generated code into a separate
module. Fortunately, Swift 5.9 provided that feature and since 1.0 will
ship with 5.9 as minimum Swift version, we can switch to `package` as
default.

### Modifications

- (Re)added the ability to customize the access modifier of the
generated code. You can do so from the config file and with a CLI
option.
- The default has changed from `public` to `package` (a breaking
change).
- Updated docs (some drive-by docs improvements as well for which
OpenAPI features are supported.)

### Result

Generated code uses the `package` access modifier by default, but the
user can change it to `public` or `internal`, if needed.

### Test Plan

Manually tested the CLI path, the config file path, updated tests, but
didn't actually change our fixtures, as there's no need. We just
explicitly override to `public`.

I also tried this branch on a real-world document using the generator
plugin, and tried all 3 access modifiers and verified all 3 worked (the
project built successfully).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/generator Affects: plugin, CLI, config file. kind/enhancement Improvements to existing feature. size/S Small task. (A couple of hours of work.) status/blocked Waiting for another issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants