Skip to content

Commit d4f8103

Browse files
authored
Merge branch 'main' into type-substitutions
2 parents 73cc059 + 09ed6c4 commit d4f8103

File tree

40 files changed

+137
-34
lines changed

40 files changed

+137
-34
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
name: Unit tests
1212
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1313
with:
14-
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
1514
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
1615
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
1716
linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"

.github/workflows/pull_request.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
name: Unit tests
1818
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1919
with:
20-
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
2120
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
2221
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
2322
linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"

Examples/auth-client-middleware-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/auth-server-middleware-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/bidirectional-event-streams-client-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/bidirectional-event-streams-server-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/command-line-client-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/curated-client-library-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/event-streams-client-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/event-streams-server-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/hello-world-async-http-client-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/hello-world-hummingbird-server-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9.2
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/hello-world-urlsession-client-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/hello-world-vapor-server-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9.2
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/logging-middleware-oslog-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/logging-middleware-swift-log-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/manual-generation-generator-cli-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/manual-generation-package-plugin-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/metrics-middleware-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/postgres-database-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/retrying-middleware-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/shared-types-client-server-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/streaming-chatgpt-proxy/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(

Examples/swagger-ui-endpoint-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/tracing-middleware-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/various-content-types-client-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Examples/various-content-types-server-example/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9.2
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

IntegrationTest/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:5.10
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the SwiftOpenAPIGenerator open source project
@@ -46,7 +46,7 @@ let package = Package(
4646

4747
// Read OpenAPI documents
4848
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.3.0"),
49-
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"6.0.0"),
49+
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"7.0.0"),
5050

5151
// CLI Tool
5252
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),

Sources/_OpenAPIGeneratorCore/Config.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public struct Config: Sendable {
4646
/// Additional imports to add to each generated file.
4747
public var additionalImports: [String]
4848

49+
/// Additional comments to add to the top of each generated file.
50+
public var additionalFileComments: [String]
51+
4952
/// Filter to apply to the OpenAPI document before generation.
5053
public var filter: DocumentFilter?
5154

@@ -71,6 +74,7 @@ public struct Config: Sendable {
7174
/// - mode: The mode to use for generation.
7275
/// - access: The access modifier to use for generated declarations.
7376
/// - additionalImports: Additional imports to add to each generated file.
77+
/// - additionalFileComments: Additional comments to add to the top of each generated file.
7478
/// - filter: Filter to apply to the OpenAPI document before generation.
7579
/// - namingStrategy: The naming strategy to use for deriving Swift identifiers from OpenAPI identifiers.
7680
/// Defaults to `defensive`.
@@ -82,6 +86,7 @@ public struct Config: Sendable {
8286
mode: GeneratorMode,
8387
access: AccessModifier,
8488
additionalImports: [String] = [],
89+
additionalFileComments: [String] = [],
8590
filter: DocumentFilter? = nil,
8691
namingStrategy: NamingStrategy,
8792
nameOverrides: [String: String] = [:],
@@ -91,6 +96,7 @@ public struct Config: Sendable {
9196
self.mode = mode
9297
self.access = access
9398
self.additionalImports = additionalImports
99+
self.additionalFileComments = additionalFileComments
94100
self.filter = filter
95101
self.namingStrategy = namingStrategy
96102
self.nameOverrides = nameOverrides

Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/ClientTranslator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct ClientFileTranslator: FileTranslator {
3232

3333
let doc = parsedOpenAPI
3434

35-
let topComment: Comment = .inline(Constants.File.topComment)
35+
let topComment = self.topComment
3636

3737
let imports =
3838
Constants.File.clientServerImports + config.additionalImports.map { ImportDescription(moduleName: $0) }

Sources/_OpenAPIGeneratorCore/Translator/FileTranslator.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ extension FileTranslator {
8383
)
8484
return TranslatorContext(safeNameGenerator: overridingGenerator)
8585
}
86+
87+
/// Creates a top comment that includes the default "do not modify" comment
88+
/// and any additional file comments from the configuration.
89+
var topComment: Comment {
90+
.inline(([Constants.File.topComment] + config.additionalFileComments).joined(separator: "\n"))
91+
}
8692
}
8793

8894
/// A set of configuration values for concrete file translators.

Sources/_OpenAPIGeneratorCore/Translator/ServerTranslator/ServerTranslator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct ServerFileTranslator: FileTranslator {
3030

3131
let doc = parsedOpenAPI
3232

33-
let topComment: Comment = .inline(Constants.File.topComment)
33+
let topComment = self.topComment
3434

3535
let imports =
3636
Constants.File.clientServerImports + config.additionalImports.map { ImportDescription(moduleName: $0) }

Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/TypesFileTranslator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct TypesFileTranslator: FileTranslator {
3232

3333
let doc = parsedOpenAPI
3434

35-
let topComment: Comment = .inline(Constants.File.topComment)
35+
let topComment = self.topComment
3636

3737
let imports = Constants.File.imports + config.additionalImports.map { ImportDescription(moduleName: $0) }
3838

Sources/swift-openapi-generator/Documentation.docc/Articles/Configuring-the-generator.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The configuration file has the following keys:
3535
- `package`: Generated API is accessible from other modules within the same package or project.
3636
- `internal` (default): Generated API is accessible from the containing module only.
3737
- `additionalImports` (optional): array of strings. Each string value is a Swift module name. An import statement will be added to the generated source files for each module.
38+
- `additionalFileComments` (optional): array of strings. Each string value is a comment that will be added to the top of each generated file (after the do-not-edit comment). Useful for adding directives like `swift-format-ignore-file` or `swiftlint:disable all`.
3839
- `filter` (optional): Filters to apply to the OpenAPI document before generation.
3940
- `operations`: Operations with these operation IDs will be included in the filter.
4041
- `tags`: Operations tagged with these tags will be included in the filter.
@@ -95,6 +96,18 @@ additionalImports:
9596
accessModifier: public
9697
```
9798

99+
To add file comments to exclude generated files from formatting tools:
100+
101+
```yaml
102+
generate:
103+
- types
104+
- client
105+
namingStrategy: idiomatic
106+
additionalFileComments:
107+
- "swift-format-ignore-file"
108+
- "swiftlint:disable all"
109+
```
110+
98111
### Document filtering
99112

100113
The generator supports filtering the OpenAPI document prior to generation, which can be useful when

Sources/swift-openapi-generator/GenerateOptions+runGenerator.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extension _GenerateOptions {
3232
let sortedModes = try resolvedModes(config)
3333
let resolvedAccessModifier = resolvedAccessModifier(config)
3434
let resolvedAdditionalImports = resolvedAdditionalImports(config)
35+
let resolvedAdditionalFileComments = resolvedAdditionalFileComments(config)
3536
let resolvedNamingStragy = resolvedNamingStrategy(config)
3637
let resolvedNameOverrides = resolvedNameOverrides(config)
3738
let resolvedTypeOverrides = resolvedTypeOverrides(config)
@@ -41,6 +42,7 @@ extension _GenerateOptions {
4142
mode: $0,
4243
access: resolvedAccessModifier,
4344
additionalImports: resolvedAdditionalImports,
45+
additionalFileComments: resolvedAdditionalFileComments,
4446
filter: config?.filter,
4547
namingStrategy: resolvedNamingStragy,
4648
nameOverrides: resolvedNameOverrides,
@@ -72,6 +74,7 @@ extension _GenerateOptions {
7274
- Plugin source: \(pluginSource?.rawValue ?? "<none>")
7375
- Is dry run: \(isDryRun)
7476
- Additional imports: \(resolvedAdditionalImports.isEmpty ? "<none>" : resolvedAdditionalImports.joined(separator: ", "))
77+
- Additional file comments: \(resolvedAdditionalFileComments.isEmpty ? "<none>" : resolvedAdditionalFileComments.joined(separator: ", "))
7578
"""
7679
)
7780
do {

Sources/swift-openapi-generator/GenerateOptions.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct _GenerateOptions: ParsableArguments {
4040

4141
@Option(help: "Additional import to add to all generated files.") var additionalImport: [String] = []
4242

43+
@Option(help: "Additional file comment to add to all generated files.") var additionalFileComment: [String] = []
44+
4345
@Option(help: "Pre-release feature to enable. Options: \(FeatureFlag.prettyListing).") var featureFlag:
4446
[FeatureFlag] = []
4547

@@ -81,6 +83,17 @@ extension _GenerateOptions {
8183
return []
8284
}
8385

86+
/// Returns a list of additional file comments requested by the user.
87+
/// - Parameter config: The configuration specified by the user.
88+
/// - Returns: A list of additional file comments requested by the user.
89+
func resolvedAdditionalFileComments(_ config: _UserConfig?) -> [String] {
90+
if !additionalFileComment.isEmpty { return additionalFileComment }
91+
if let additionalFileComments = config?.additionalFileComments, !additionalFileComments.isEmpty {
92+
return additionalFileComments
93+
}
94+
return []
95+
}
96+
8497
/// Returns the naming strategy requested by the user.
8598
/// - Parameter config: The configuration specified by the user.
8699
/// - Returns: The naming strategy requestd by the user.

Sources/swift-openapi-generator/UserConfig.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ struct _UserConfig: Codable {
3030
/// generated Swift file.
3131
var additionalImports: [String]?
3232

33+
/// A list of additional comments that are added to the top of every
34+
/// generated Swift file.
35+
var additionalFileComments: [String]?
36+
3337
/// Filter to apply to the OpenAPI document before generation.
3438
var filter: DocumentFilter?
3539

@@ -54,6 +58,7 @@ struct _UserConfig: Codable {
5458
case generate
5559
case accessModifier
5660
case additionalImports
61+
case additionalFileComments
5762
case filter
5863
case namingStrategy
5964
case nameOverrides

Tests/OpenAPIGeneratorCoreTests/Test_Config.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,17 @@ import OpenAPIKit
1717

1818
final class Test_Config: Test_Core {
1919
func testDefaultAccessModifier() { XCTAssertEqual(Config.defaultAccessModifier, .internal) }
20+
func testAdditionalFileComments() {
21+
let config = Config(
22+
mode: .types,
23+
access: .public,
24+
additionalFileComments: ["swift-format-ignore-file", "swiftlint:disable all"],
25+
namingStrategy: .defensive
26+
)
27+
XCTAssertEqual(config.additionalFileComments, ["swift-format-ignore-file", "swiftlint:disable all"])
28+
}
29+
func testEmptyAdditionalFileComments() {
30+
let config = Config(mode: .types, access: .public, namingStrategy: .defensive)
31+
XCTAssertEqual(config.additionalFileComments, [])
32+
}
2033
}

0 commit comments

Comments
 (0)