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 API protocols based on tags #285

Closed
olejnjak opened this issue Sep 19, 2023 · 5 comments
Closed

Generate API protocols based on tags #285

olejnjak opened this issue Sep 19, 2023 · 5 comments
Labels
area/generator Affects: plugin, CLI, config file. kind/enhacement Improvements to existing feature. status/needs-design Needs further discussion and a concrete proposal.
Milestone

Comments

@olejnjak
Copy link

Currently OpenAPI generator generates a single APIProtocol for all client calls.

It would be a good improvement if it would be possible to generate a protocol based on tags in the spec. So given the following spec, two protocols would be generated PetsAPIProtocol & StoreAPIProtocol.

paths:
  /pet/findByStatus:
    get:
      summary: Finds pets by Status
      tags:
        - pets
      ...
  /pet:
    post:
      summary: Adds a new pet to the store
      tags:
        - pets
      ...
  /store/inventory:
    get:
      summary: Returns pet inventories
      tags:
        - store
      ...

Based on https://x.com/czechboy0/status/1703869135682195838?s=20

@czechboy0
Copy link
Collaborator

I think that's a good idea. Would help with large documents, and even when implementing servers, it could help break up the API handler a bit.

This should be doable even in a backwards compatible way, as we could continue to generate

protocol APIProtocol: PetsAPIProtocol, StoreAPIProtocol {} so those who still want to just use a single object for everything could continue to do so.

Still, this should go through a proposal, but should be considered before 1.0 in case we choose to do it in an API-breaking way.

If anyone wants to take it on and go through the proposal and implementation process, that'd be great. We can help guide you through the process.

@czechboy0 czechboy0 added area/generator Affects: plugin, CLI, config file. status/needs-design Needs further discussion and a concrete proposal. kind/enhacement Improvements to existing feature. labels Sep 19, 2023
@czechboy0 czechboy0 added this to the 1.0 milestone Sep 19, 2023
@olejnjak
Copy link
Author

Proposal in #287

@simonjbeaumont
Copy link
Collaborator

@olejnjak Thanks for taking the time to file this and to write up the proposal!

As it happens, we've been considering adding support for pruning the OpenAPI document to just the things a user wants to use. We were considering a more expressive approach that extends beyond the OpenAPI tags. For example, you could ask to generate:

  • A list of operations by operation ID, (path, method) pair, or tag.
  • (Maybe) A list of schemas by name.

The feature would then prune the OpenAPI document before generation to only include these items and the transitive closure of all those items dependencies. Generation would then proceed as it does today, on this subset.

The missing part from the proposal above is that we would not make changes to the generated namespaces—we would still have APIProtocol.

Would this fit your use case?

@czechboy0
Copy link
Collaborator

Just to add to Si, you could then generate all the operations for one tag into one module, making the fully qualified protocol name ModuleA.APIProtocol, other tag into another module (ModuleB.APIProtocol), etc, allowing splitting a large doc into several smaller parts.

@simonjbeaumont
Copy link
Collaborator

@olejnjak Just a heads up that SOAR-0008 proposal is up in #303, which might go some way to meet your requirements.

@olejnjak olejnjak closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
simonjbeaumont added a commit that referenced this issue Oct 19, 2023
### Motivation

We'd like to run a proposal for filtering the OpenAPI document for just
the required parts prior to generating.

### Modifications

- Add SOAR-0008: OpenAPI document filtering

(See the proposal itself for details)[^1]

### Result

n/a

### Test Plan

n/a

### Related Issues

#285

[^1]: https://github.com/apple/swift-openapi-generator/pull/303/files

---------

Signed-off-by: Si Beaumont <beaumont@apple.com>
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/enhacement Improvements to existing feature. status/needs-design Needs further discussion and a concrete proposal.
Projects
None yet
Development

No branches or pull requests

3 participants