Add configurable Swift attributes for generated APIProtocol#915
Closed
farzadshbfn wants to merge 1 commit into
Closed
Add configurable Swift attributes for generated APIProtocol#915farzadshbfn wants to merge 1 commit into
farzadshbfn wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Generated client and server code often needs Swift attributes on the
APIProtocoltype and its operation requirements—for example@MainActorfor concurrency isolation or macro-driven attributes such as@Mockable. Today there is no supported way to express those attributes in generator configuration, so adopters must post-process generatedTypes.swiftor maintain local forks.Modifications
AttributeConfigurationandAttributeDescriptionto model optional Swift attributes in config.Config,_UserConfig, and CLIGenerateOptionswith anattributesfield.attributes:usingprotocolandmethodskeys (each a list of attribute names or quoted strings with arguments).APIProtocoland its method requirements inTypes.swift; OpenAPI-driven@available(*, deprecated, …)remains unchanged and is still applied from operation metadata.Package.swift, macro plugins, andadditionalImportswhen attributes reference external types or macros.Result
Adopters can configure attributes in
openapi-generator-config.yaml(or equivalent) and regenerateTypes.swiftwith the requested@attributes onAPIProtocoland each operation requirement, without manual edits to generated output.Example:
Test Plan
Test_AttributeConfigurationfor YAML decoding ofprotocol/methods, including quoted attribute arguments.Test_Configto cover the new configuration surface.testPaths_withConfiguredAttributessnippet reference test for generatedAPIProtocoloutput.swift test --filter OpenAPIGeneratorCoreTests(116 tests, all passing).Related issues
APIProtocoland its operation requirements.MainActorisolation; configuring@MainActoron generatedAPIProtocoland methods is a supported way to align generated code with project concurrency settings.