Skip to content

Commit 39319d6

Browse files
authored
Merge branch 'main' into proposal/generate-server-variable-enums
2 parents 9db3c2f + ef6d07f commit 39319d6

File tree

57 files changed

+911
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+911
-226
lines changed

.github/workflows/pull_request.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ on:
77
jobs:
88
soundness:
99
name: Soundness
10-
uses: apple/swift-nio/.github/workflows/soundness.yml@main
10+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
1111
with:
12-
api_breakage_check_enabled: true
12+
api_breakage_check_enabled: false
1313
broken_symlink_check_enabled: true
1414
docs_check_enabled: true
1515
format_check_enabled: true
1616
license_header_check_enabled: true
1717
license_header_check_project_name: "SwiftOpenAPIGenerator"
1818
shell_check_enabled: true
1919
unacceptable_language_check_enabled: true
20+
yamllint_check_enabled: false
2021

2122
unit-tests:
2223
name: Unit tests
@@ -33,7 +34,7 @@ jobs:
3334
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
3435
with:
3536
name: "Integration test"
36-
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && ./scripts/run-integration-test.sh"
37+
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${GITHUB_WORKSPACE} ./scripts/run-integration-test.sh"
3738
matrix_linux_5_8_enabled: false
3839
matrix_linux_nightly_main_enabled: false
3940

.github/workflows/scheduled.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
2121
with:
2222
name: "Integration test"
23-
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && ./scripts/run-integration-test.sh"
23+
matrix_linux_command: "apt-get update -yq && apt-get install -yq jq && SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${GITHUB_WORKSPACE} ./scripts/run-integration-test.sh"
2424
matrix_linux_5_8_enabled: false
2525

2626
example-packages:

Sources/_OpenAPIGeneratorCore/Layers/StructuredSwiftRepresentation.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,9 +1628,15 @@ extension KeywordKind {
16281628
}
16291629

16301630
extension Declaration {
1631+
/// Returns a new deprecated variant of the declaration if the provided `description` is not `nil`.
1632+
func deprecate(if description: DeprecationDescription?) -> Self {
1633+
if let description { return .deprecated(description, self) }
1634+
return self
1635+
}
1636+
16311637
/// Returns a new deprecated variant of the declaration if `shouldDeprecate` is true.
1632-
func deprecate(if shouldDeprecate: Bool) -> Self {
1633-
if shouldDeprecate { return .deprecated(.init(), self) }
1638+
func deprecate(if shouldDeprecate: Bool, description: @autoclosure () -> DeprecationDescription = .init()) -> Self {
1639+
if shouldDeprecate { return .deprecated(description(), self) }
16341640
return self
16351641
}
16361642

Sources/_OpenAPIGeneratorCore/Translator/ClientTranslator/ClientTranslator.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ struct ClientFileTranslator: FileTranslator {
3737
let imports =
3838
Constants.File.clientServerImports + config.additionalImports.map { ImportDescription(moduleName: $0) }
3939

40-
let clientMethodDecls =
41-
try OperationDescription.all(from: doc.paths, in: components, asSwiftSafeName: swiftSafeName)
40+
let clientMethodDecls = try OperationDescription.all(from: doc.paths, in: components, context: context)
4241
.map(translateClientMethod(_:))
4342

4443
let clientStructPropertyDecl: Declaration = .commentable(

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/SwiftSafeNames.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414
import Foundation
1515

16-
extension FileTranslator {
17-
18-
/// Returns a copy of the string modified to be a valid Swift identifier.
19-
///
20-
/// - Parameter string: The string to convert to be safe for Swift.
21-
/// - Returns: A Swift-safe version of the input string.
22-
func swiftSafeName(for string: String) -> String { string.safeForSwiftCode }
23-
}
24-
25-
fileprivate extension String {
16+
extension String {
2617

2718
/// Returns a string sanitized to be usable as a Swift identifier.
2819
///

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateAllAnyOneOf.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extension TypesFileTranslator {
6464
parent: typeName
6565
)
6666
let associatedDeclarations: [Declaration]
67-
if TypeMatcher.isInlinable(schema) {
67+
if typeMatcher.isInlinable(schema) {
6868
associatedDeclarations = try translateSchema(
6969
typeName: propertyType.typeName,
7070
schema: schema,
@@ -78,10 +78,10 @@ extension TypesFileTranslator {
7878
originalName: key,
7979
typeUsage: propertyType,
8080
associatedDeclarations: associatedDeclarations,
81-
asSwiftSafeName: swiftSafeName
81+
context: context
8282
)
8383
var referenceStack = ReferenceStack.empty
84-
let isKeyValuePairSchema = try TypeMatcher.isKeyValuePair(
84+
let isKeyValuePairSchema = try typeMatcher.isKeyValuePair(
8585
schema,
8686
referenceStack: &referenceStack,
8787
components: components
@@ -173,7 +173,7 @@ extension TypesFileTranslator {
173173
parent: typeName
174174
)
175175
let associatedDeclarations: [Declaration]
176-
if TypeMatcher.isInlinable(schema) {
176+
if typeMatcher.isInlinable(schema) {
177177
associatedDeclarations = try translateSchema(
178178
typeName: childType.typeName,
179179
schema: schema,
@@ -183,7 +183,7 @@ extension TypesFileTranslator {
183183
associatedDeclarations = []
184184
}
185185
var referenceStack = ReferenceStack.empty
186-
let isKeyValuePair = try TypeMatcher.isKeyValuePair(
186+
let isKeyValuePair = try typeMatcher.isKeyValuePair(
187187
schema,
188188
referenceStack: &referenceStack,
189189
components: components
@@ -209,7 +209,7 @@ extension TypesFileTranslator {
209209
let decoder: Declaration
210210
if let discriminator {
211211
let originalName = discriminator.propertyName
212-
let swiftName = swiftSafeName(for: originalName)
212+
let swiftName = context.asSwiftSafeName(originalName)
213213
codingKeysDecls = [
214214
.enum(
215215
accessModifier: config.access,

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateObjectStruct.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extension TypesFileTranslator {
8585
parent: typeName
8686
)
8787
let associatedDeclarations: [Declaration]
88-
if TypeMatcher.isInlinable(value) {
88+
if typeMatcher.isInlinable(value) {
8989
associatedDeclarations = try translateSchema(
9090
typeName: propertyType.typeName,
9191
schema: value,
@@ -100,7 +100,7 @@ extension TypesFileTranslator {
100100
originalName: key,
101101
typeUsage: propertyType,
102102
associatedDeclarations: associatedDeclarations,
103-
asSwiftSafeName: swiftSafeName
103+
context: context
104104
)
105105
}
106106

@@ -153,7 +153,7 @@ extension TypesFileTranslator {
153153
components: components,
154154
inParent: parent
155155
)
156-
if TypeMatcher.isInlinable(schema) {
156+
if typeMatcher.isInlinable(schema) {
157157
associatedDeclarations = try translateSchema(
158158
typeName: valueTypeUsage.typeName,
159159
schema: schema,
@@ -175,7 +175,7 @@ extension TypesFileTranslator {
175175
default: .emptyInit,
176176
isSerializedInTopLevelDictionary: false,
177177
associatedDeclarations: associatedDeclarations,
178-
asSwiftSafeName: swiftSafeName
178+
context: context
179179
)
180180
return (.allowingAdditionalProperties, extraProperty)
181181
}

Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateStringEnum.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ extension FileTranslator {
4949
// In nullable enum schemas, empty strings are parsed as Void.
5050
// This is unlikely to be fixed, so handling that case here.
5151
// https://github.com/apple/swift-openapi-generator/issues/118
52-
if isNullable && anyValue is Void { return (swiftSafeName(for: ""), .string("")) }
52+
if isNullable && anyValue is Void { return (context.asSwiftSafeName(""), .string("")) }
5353
guard let rawValue = anyValue as? String else {
5454
throw GenericError(message: "Disallowed value for a string enum '\(typeName)': \(anyValue)")
5555
}
56-
let caseName = swiftSafeName(for: rawValue)
56+
let caseName = context.asSwiftSafeName(rawValue)
5757
return (caseName, .string(rawValue))
5858
case .integer:
5959
let rawValue: Int

Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/Constants.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ enum Constants {
5656

5757
/// The prefix of each generated method name.
5858
static let propertyPrefix: String = "server"
59+
/// The name of each generated static function.
60+
static let urlStaticFunc: String = "url"
61+
62+
/// The prefix of the namespace that contains server specific variables.
63+
static let serverNamespacePrefix: String = "Server"
64+
65+
/// Constants related to the OpenAPI server variable object.
66+
enum Variable {
67+
68+
/// The types that the protocol conforms to.
69+
static let conformances: [String] = [TypeName.string.fullyQualifiedSwiftName, "Sendable"]
70+
}
5971
}
6072

6173
/// Constants related to the configuration type, which is used by both

Sources/_OpenAPIGeneratorCore/Translator/CommonTypes/DiscriminatorExtensions.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ extension FileTranslator {
7979
/// component.
8080
/// - Parameter type: The `OneOfMappedType` for which to determine the case name.
8181
/// - Returns: A string representing the safe Swift name for the specified `OneOfMappedType`.
82-
func safeSwiftNameForOneOfMappedType(_ type: OneOfMappedType) -> String { swiftSafeName(for: type.rawNames[0]) }
82+
func safeSwiftNameForOneOfMappedType(_ type: OneOfMappedType) -> String {
83+
context.asSwiftSafeName(type.rawNames[0])
84+
}
8385
}
8486

8587
extension OpenAPI.Discriminator {

0 commit comments

Comments
 (0)