Skip to content

Commit 66f97a3

Browse files
Merge branch 'main' into error_handling
2 parents 71eb331 + 759c30b commit 66f97a3

Some content is hidden

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

41 files changed

+1373
-125
lines changed

.github/workflows/pull_request.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@ 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
13-
broken_symlink_check_enabled: true
14-
docs_check_enabled: true
15-
format_check_enabled: true
16-
license_header_check_enabled: true
12+
api_breakage_check_enabled: false
1713
license_header_check_project_name: "SwiftOpenAPIGenerator"
18-
shell_check_enabled: true
19-
unacceptable_language_check_enabled: true
14+
yamllint_check_enabled: false
2015

2116
unit-tests:
2217
name: Unit tests
2318
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
2419
with:
25-
linux_5_8_enabled: false
2620
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
2721
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
22+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
2823
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
2924
linux_nightly_main_enabled: false
3025

@@ -34,7 +29,6 @@ jobs:
3429
with:
3530
name: "Integration test"
3631
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"
37-
matrix_linux_5_8_enabled: false
3832
matrix_linux_nightly_main_enabled: false
3933

4034
compatibility-test:
@@ -62,7 +56,6 @@ jobs:
6256
with:
6357
name: "Example packages"
6458
matrix_linux_command: "./scripts/test-examples.sh"
65-
matrix_linux_5_8_enabled: false
6659
matrix_linux_nightly_main_enabled: false
6760

6861
swift-6-language-mode:

.github/workflows/scheduled.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
name: Unit tests
1010
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
1111
with:
12-
linux_5_8_enabled: false
1312
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
1413
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
14+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
1515
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
1616
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
1717

@@ -21,12 +21,10 @@ jobs:
2121
with:
2222
name: "Integration test"
2323
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"
24-
matrix_linux_5_8_enabled: false
2524

2625
example-packages:
2726
name: Example packages
2827
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
2928
with:
3029
name: "Example packages"
3130
matrix_linux_command: "./scripts/test-examples.sh"
32-
matrix_linux_5_8_enabled: false

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let package = Package(
5151
.package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0"),
5252

5353
// Read OpenAPI documents
54-
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.1.2"),
54+
.package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.3.0"),
5555
.package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"6.0.0"),
5656

5757
// CLI Tool

Sources/_OpenAPIGeneratorCore/Diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public struct StdErrPrintingDiagnosticCollector: DiagnosticCollector, Sendable {
322322
/// Emits a diagnostic message to standard error.
323323
///
324324
/// - Parameter diagnostic: The diagnostic message to emit.
325-
public func emit(_ diagnostic: Diagnostic) { stdErrHandle.write(diagnostic.description) }
325+
public func emit(_ diagnostic: Diagnostic) { stdErrHandle.write(diagnostic.description + "\n") }
326326
}
327327

328328
/// A no-op collector, silently ignores all diagnostics.

Sources/_OpenAPIGeneratorCore/Hooks/FilteredDocument.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ private extension FilteredDocumentBuilder {
313313
guard predicate(endpoint) else { continue }
314314
if requiredEndpoints[path] == nil { requiredEndpoints[path] = Set() }
315315
if requiredEndpoints[path]!.insert(endpoint.method).inserted {
316+
for parameter in originalPathItem.parameters { try includeParameter(parameter) }
316317
try includeComponentsReferencedBy(endpoint.operation)
317318
}
318319
}

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/Parser/YamsParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public struct YamsParser: ParserProtocol {
7070
do {
7171
let document: OpenAPIKit.OpenAPI.Document
7272
switch openAPIVersion {
73-
case "3.0.0", "3.0.1", "3.0.2", "3.0.3":
73+
case "3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.0.4":
7474
let openAPI30Document = try decoder.decode(OpenAPIKit30.OpenAPI.Document.self, from: input.contents)
7575
document = openAPI30Document.convert(to: .v3_1_0)
76-
case "3.1.0": document = try decoder.decode(OpenAPIKit.OpenAPI.Document.self, from: input.contents)
76+
case "3.1.0", "3.1.1": document = try decoder.decode(OpenAPIKit.OpenAPI.Document.self, from: input.contents)
7777
default:
7878
throw Diagnostic.openAPIVersionError(
7979
versionString: "openapi: \(openAPIVersion)",

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/Responses/translateResponseOutcome.swift

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ extension TypesFileTranslator {
2323
/// - operation: The OpenAPI operation.
2424
/// - operationJSONPath: The JSON path to the operation in the OpenAPI
2525
/// document.
26-
/// - Returns: A declaration of the enum case and a declaration of the
26+
/// - Returns: A tuple containing a declaration of the enum case, a declaration of the
2727
/// structure unique to the response that contains the response headers
28-
/// and a body payload.
28+
/// and a body payload, a declaration of a throwing getter and, an optional convenience static property.
2929
/// - Throws: An error if there's an issue generating the declarations, such
3030
/// as unsupported response types or invalid definitions.
3131
func translateResponseOutcomeInTypes(
3232
_ outcome: OpenAPI.Operation.ResponseOutcome,
3333
operation: OperationDescription,
3434
operationJSONPath: String
35-
) throws -> (payloadStruct: Declaration?, enumCase: Declaration, throwingGetter: Declaration) {
36-
35+
) throws -> (
36+
payloadStruct: Declaration?, enumCase: Declaration, staticMember: Declaration?, throwingGetter: Declaration
37+
) {
3738
let typedResponse = try typedResponse(from: outcome, operation: operation)
3839
let responseStructTypeName = typedResponse.typeUsage.typeName
3940
let responseKind = outcome.status.value.asKind
@@ -55,14 +56,36 @@ extension TypesFileTranslator {
5556
}
5657
associatedValues.append(.init(type: .init(responseStructTypeName)))
5758

58-
let enumCaseDesc = EnumCaseDescription(name: enumCaseName, kind: .nameWithAssociatedValues(associatedValues))
59-
let enumCaseDecl: Declaration = .commentable(
60-
responseKind.docComment(
61-
userDescription: typedResponse.response.description,
62-
jsonPath: operationJSONPath + "/responses/" + responseKind.jsonPathComponent
63-
),
64-
.enumCase(enumCaseDesc)
59+
let enumCaseDocComment = responseKind.docComment(
60+
userDescription: typedResponse.response.description,
61+
jsonPath: operationJSONPath + "/responses/" + responseKind.jsonPathComponent
6562
)
63+
let enumCaseDesc = EnumCaseDescription(name: enumCaseName, kind: .nameWithAssociatedValues(associatedValues))
64+
let enumCaseDecl: Declaration = .commentable(enumCaseDocComment, .enumCase(enumCaseDesc))
65+
66+
let staticMemberDecl: Declaration?
67+
let responseHasNoHeaders = typedResponse.response.headers?.isEmpty ?? true
68+
let responseHasNoContent = typedResponse.response.content.isEmpty
69+
if responseHasNoContent && responseHasNoHeaders && !responseKind.wantsStatusCode {
70+
let staticMemberDesc = VariableDescription(
71+
accessModifier: config.access,
72+
isStatic: true,
73+
kind: .var,
74+
left: .identifier(.pattern(enumCaseName)),
75+
type: .member(["Self"]),
76+
getter: [
77+
.expression(
78+
.functionCall(
79+
calledExpression: .dot(enumCaseName),
80+
arguments: [.functionCall(calledExpression: .dot("init"))]
81+
)
82+
)
83+
]
84+
)
85+
staticMemberDecl = .commentable(enumCaseDocComment, .variable(staticMemberDesc))
86+
} else {
87+
staticMemberDecl = nil
88+
}
6689

6790
let throwingGetterDesc = VariableDescription(
6891
accessModifier: config.access,
@@ -113,7 +136,7 @@ extension TypesFileTranslator {
113136
)
114137
let throwingGetterDecl = Declaration.commentable(throwingGetterComment, .variable(throwingGetterDesc))
115138

116-
return (responseStructDecl, enumCaseDecl, throwingGetterDecl)
139+
return (responseStructDecl, enumCaseDecl, staticMemberDecl, throwingGetterDecl)
117140
}
118141
}
119142

Sources/_OpenAPIGeneratorCore/Translator/TypesTranslator/translateOperations.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ extension TypesFileTranslator {
143143
let documentedMembers: [Declaration] = documentedOutcomes.flatMap {
144144
inlineResponseDecl,
145145
caseDecl,
146-
throwingGetter in [inlineResponseDecl, caseDecl, throwingGetter].compactMap { $0 }
146+
staticDecl,
147+
throwingGetter in [inlineResponseDecl, caseDecl, staticDecl, throwingGetter].compactMap { $0 }
147148
}
148149

149150
let allMembers: [Declaration]

0 commit comments

Comments
 (0)