Add support for configurable comments in generated files#773
Merged
simonjbeaumont merged 1 commit intoapple:mainfrom May 23, 2025
Merged
Add support for configurable comments in generated files#773simonjbeaumont merged 1 commit intoapple:mainfrom
simonjbeaumont merged 1 commit intoapple:mainfrom
Conversation
Users want the ability to add custom comments to generated files. One concrete use case is adding directives like `swift-format-ignore-file` and `swiftlint:disable all` to prevent these tools from processing generated code. - Added `additionalFileComments` property to `Config` and `UserConfig` structs - Modified `FileTranslator` to include additional comments along with the do-not-edit comment - Added CLI support with `--additional-file-comment` option - Added config tests to confirm the option propagates and the default is empty - Added snippet tests to validate the actual rendering - Updated documentation with examples and usage instructions Users can now configure additional comments to be added to generated files using either the config file or a command line option. Fixes apple#738. - Added unit tests for `Config` - Added snippet tests for rendering - Manual tests of generator using config and CLI on real OpenAPI doc: ```console % swift run swift-openapi-generator generate openapi-documents/petstore.yaml \ --mode types \ --output-directory test-output-cli \ --additional-file-comment "hello world" \ --additional-file-comment "testing, testing, 1, 2, 3" Build of product 'swift-openapi-generator' complete! (3.27s) Swift OpenAPI Generator is running with the following configuration: - OpenAPI document path: /Users/Si/work/code/swift-openapi-workspace/packages/swift-openapi-generator/openapi-documents/petstore.yaml - Configuration path: <none> - Generator modes: types - Access modifier: internal - Naming strategy: defensive - Name overrides: <none> - Feature flags: <none> - Output file names: Types.swift - Output directory: /Users/Si/work/code/swift-openapi-workspace/packages/swift-openapi-generator/test-output-cli - Diagnostics output path: <none - logs to stderr> - Current directory: /Users/Si/work/code/swift-openapi-workspace/packages/swift-openapi-generator - Plugin source: <none> - Is dry run: false - Additional imports: <none> - Additional file comments: hello world, testing, testing, 1, 2, 3 Writing data to file Types.swift... % head -5 test-output-cli/Types.swift // Generated by swift-openapi-generator, do not modify. // hello world // testing, testing, 1, 2, 3 @_spi(Generated) import OpenAPIRuntime ```
Contributor
|
Looks great - could you also document this new option in https://github.com/apple/swift-openapi-generator/blob/main/Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md ? |
Collaborator
Author
I think this is already there: https://github.com/apple/swift-openapi-generator/pull/773/files#diff-40f1be5f76027ad80fcf014d589ac1091a42c714e11d03abae58a62bf8440471 |
czechboy0
approved these changes
May 23, 2025
Contributor
czechboy0
left a comment
There was a problem hiding this comment.
Sorry missed that you had already added the docs - lgtm!
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
Users want the ability to add custom comments to generated files. One concrete use case is adding directives like
swift-format-ignore-fileandswiftlint:disable allto prevent these tools from processing generated code.Modifications
additionalFileCommentsproperty toConfigandUserConfigstructsFileTranslatorto include additional comments along with the do-not-edit comment--additional-file-commentoptionResult
Users can now configure additional comments to be added to generated files using either the config file or a command line option.
Fixes #738.
Test plan
Config