Skip to content

Add SOAR-0016: Attached macros on generated declarations - #964

Open
mackoj wants to merge 2 commits into
apple:mainfrom
mackoj:soar-0016-proposal
Open

mackoj wants to merge 2 commits into
apple:mainfrom
mackoj:soar-0016-proposal

Conversation

@mackoj

@mackoj mackoj commented Oct 5, 2026 •

Copy link
Copy Markdown

Motivation

There's no way to put a macro on a generated declaration today, because generated code is rewritten on every build. Adopters either post-process the output or fork the generator.

Use cases from #383 include protocol conformances on every operation output, Combine variants of client methods, mocks generated from APIProtocol (e.g. Mockable), and @DependencyClient wrappers from swift-dependencies.

As discussed in #383, this proposal comes before the implementation.

Modifications

  • Add SOAR-0016.md, proposing an attachedMacros configuration key.
  • List it in Proposals.md.

The proposal follows the design agreed in #383:

  • components (schemas, parameters, requestBodies, responses, headers), operations (input, output, clientMethod), apiProtocol, client, and server. server targets registerHandlers.
  • Rules use case-sensitive regular expressions matched against OpenAPI names.
  • Macro names are written without the @.
  • Arguments are a list of label and value entries, where value is Swift source emitted verbatim.

One change from the thread: rules are a list (- match: "^Pet$") instead of a mapping keyed by regex. Decoding a YAML mapping doesn't preserve key order, so the order of macros on a declaration wouldn't be deterministic otherwise. @czechboy0, happy to discuss.

Result

Once implemented, adopters can attach macros to generated declarations from the config file, for example:

attachedMacros:
  apiProtocol:
    - name: Mockable

Without the key, the generated code is unchanged.

Test Plan

This PR only adds the proposal. A follow-up PR will add the implementation, with reference tests for each target.

@mackoj
mackoj marked this pull request as ready for review October 8, 2026 07:24
@czechboy0
czechboy0 self-requested a review October 8, 2026 17:02

@czechboy0 czechboy0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, @mackoj 🙏

Just a few minor comments, once we settle these, this is ready for a wide review.

- Rename the `match` key of rules to `filter`.
- Omitting `filter` matches everything.
- Add the `operations[].operation` target for the `Operations.<Op>` namespace.
@mackoj
mackoj force-pushed the soar-0016-proposal branch from 56c6f2c to 321a66d Compare October 14, 2026 23:21
@czechboy0
czechboy0 self-requested a review October 15, 2026 07:17

@czechboy0 czechboy0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thank you @mackoj, let me kick off the review now

@czechboy0
czechboy0 self-requested a review October 15, 2026 12:26
@czechboy0

Copy link
Copy Markdown
Contributor

Kicked off: https://forums.swift.org/t/proposal-soar-0016-attached-macros-on-generated-declarations/90100

@czechboy0 czechboy0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dismissing my review until the review concludes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants