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

Add support for filtering OpenAPI document #319

Merged
merged 22 commits into from Oct 13, 2023

Conversation

simonjbeaumont
Copy link
Collaborator

@simonjbeaumont simonjbeaumont commented Oct 3, 2023

Motivation

When generating client code, Swift OpenAPI Generator generates code for the entire OpenAPI document, even if the user only makes use of a subset of its types and operations.

Generating code that is unused constitutes overhead for the adopter:

  • The overhead of generating code for unused types and operations
  • The overhead of compiling the generated code
  • The overhead of unused code in the users codebase (AOT generation)

This is particularly noticeable when working with a small subset of a large API, which can result in O(100k) lines of unused code and long generation and compile times.

For a more detailed motivation and design, see the proposal in #303.

Modifications

  • Add document filter to the generator config.
  • Run filter as a post-transition hook in the generator pipeline after parsing the document.
  • Provide a CLI command that outputs the filtered document to stdout.

Result

Users can filter a document before code-generation. For large APIs, this can result in >90% speedup (see proposal).

Test Plan

  • Unit tests.

Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
@simonjbeaumont simonjbeaumont marked this pull request as ready for review October 10, 2023 12:18
Copy link
Collaborator

@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.

Looks great overall, just a few small suggestions.

Sources/_OpenAPIGeneratorCore/Hooks/DocumentFilter.swift Outdated Show resolved Hide resolved
Sources/_OpenAPIGeneratorCore/Hooks/FilteredDocument.swift Outdated Show resolved Hide resolved
Sources/_OpenAPIGeneratorCore/Hooks/FilteredDocument.swift Outdated Show resolved Hide resolved
Sources/_OpenAPIGeneratorCore/Hooks/FilteredDocument.swift Outdated Show resolved Hide resolved
Sources/swift-openapi-generator/FilterCommand.swift Outdated Show resolved Hide resolved
@czechboy0 czechboy0 added this to the 1.0 milestone Oct 11, 2023
Copy link
Collaborator

@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.

A few more comments, otherwise looks great.

simonjbeaumont and others added 2 commits October 13, 2023 10:29
Co-authored-by: Honza Dvorsky <honza@apple.com>
Signed-off-by: Si Beaumont <beaumont@apple.com>
Copy link
Collaborator

@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.

:shipit:

@simonjbeaumont simonjbeaumont merged commit 4c8ed5c into apple:main Oct 13, 2023
8 checks passed
@czechboy0 czechboy0 added the semver/patch No public API change. label Oct 19, 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.

None yet

2 participants