Skip to content

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.

@simonjbeaumont simonjbeaumont marked this pull request as ready for review October 10, 2023 12:18
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.

Looks great overall, just a few small suggestions.

@czechboy0 czechboy0 added this to the 1.0 milestone Oct 11, 2023
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.

A few more comments, otherwise looks great.

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.

:shipit:

@simonjbeaumont simonjbeaumont merged commit 4c8ed5c into apple:main Oct 13, 2023
@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.

2 participants