Skip to content

Commit 837e6ed

Browse files
committed
Formatting
1 parent 4cb7b14 commit 837e6ed

File tree

5 files changed

+61
-70
lines changed

5 files changed

+61
-70
lines changed

Sources/_OpenAPIGeneratorCore/Translator/TypeAssignment/TypeAssigner.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -546,16 +546,15 @@ struct TypeAssigner {
546546
let params = contentType.lowercasedParameterPairs
547547
guard !params.isEmpty else { return prefix }
548548
let safedParams =
549-
params.map { pair in
550-
pair
551-
.split(separator: "=")
552-
.map { component in
553-
let safedComponent = context.asSwiftSafeName(String(component), .noncapitalized)
554-
return capitalizeNonFirstWords ? safedComponent.uppercasingFirstLetter : safedComponent
555-
}
556-
.joined(separator: componentSeparator)
557-
}
558-
.joined(separator: componentSeparator)
549+
params.map { pair in
550+
pair.split(separator: "=")
551+
.map { component in
552+
let safedComponent = context.asSwiftSafeName(String(component), .noncapitalized)
553+
return capitalizeNonFirstWords ? safedComponent.uppercasingFirstLetter : safedComponent
554+
}
555+
.joined(separator: componentSeparator)
556+
}
557+
.joined(separator: componentSeparator)
559558
return prefix + componentSeparator + safedParams
560559
}
561560
}

Tests/OpenAPIGeneratorCoreTests/Extensions/Test_SwiftSafeNames.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ final class Test_SwiftSafeNames: Test_Core {
3434
("Retry-After", "Retry_hyphen_After", "RetryAfter", "retryAfter"),
3535

3636
// All uppercase
37-
("HELLO_WORLD", "HELLO_WORLD", "HelloWorld", "helloWorld"),
38-
("HELLO", "HELLO", "Hello", "hello"),
37+
("HELLO_WORLD", "HELLO_WORLD", "HelloWorld", "helloWorld"), ("HELLO", "HELLO", "Hello", "hello"),
3938

4039
// Acronyms
4140
("HTTPProxy", "HTTPProxy", "HTTPProxy", "httpProxy"),

Tests/OpenAPIGeneratorCoreTests/Translator/Operations/Test_OperationDescription.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ final class Test_OperationDescription: Test_Core {
144144
endpoint: endpoint,
145145
pathParameters: pathItem.parameters,
146146
components: .init(),
147-
context: .init(
148-
asSwiftSafeName: { string, _ in string },
149-
namingStrategy: .defensive
150-
)
147+
context: .init(asSwiftSafeName: { string, _ in string }, namingStrategy: .defensive)
151148
)
152149
}
153150
}

Tests/OpenAPIGeneratorCoreTests/Translator/TypeAssignment/Test_TypeAssigner.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,14 @@ class Test_TypeAssigner: Test_Core {
112112
// Short names.
113113
("application/json", "json", "json"),
114114
("application/x-www-form-urlencoded", "urlEncodedForm", "urlEncodedForm"),
115-
("multipart/form-data", "multipartForm", "multipartForm"),
116-
("text/plain", "plainText", "plainText"),
117-
("*/*", "any", "any"),
118-
("application/xml", "xml", "xml"),
119-
("application/octet-stream", "binary", "binary"),
120-
("text/html", "html", "html"),
121-
("application/yaml", "yaml", "yaml"),
122-
("text/csv", "csv", "csv"),
123-
("image/png", "png", "png"),
124-
("application/pdf", "pdf", "pdf"),
125-
("image/jpeg", "jpeg", "jpeg"),
115+
("multipart/form-data", "multipartForm", "multipartForm"), ("text/plain", "plainText", "plainText"),
116+
("*/*", "any", "any"), ("application/xml", "xml", "xml"), ("application/octet-stream", "binary", "binary"),
117+
("text/html", "html", "html"), ("application/yaml", "yaml", "yaml"), ("text/csv", "csv", "csv"),
118+
("image/png", "png", "png"), ("application/pdf", "pdf", "pdf"), ("image/jpeg", "jpeg", "jpeg"),
126119

127120
// Generic names.
128121
("application/myformat+json", "application_myformat_plus_json", "applicationMyformatJson"),
129-
("foo/bar", "foo_bar", "fooBar"),
130-
("text/event-stream", "text_event_hyphen_stream", "textEventStream"),
122+
("foo/bar", "foo_bar", "fooBar"), ("text/event-stream", "text_event_hyphen_stream", "textEventStream"),
131123

132124
// Names with a parameter.
133125
("application/foo", "application_foo", "applicationFoo"),
@@ -136,8 +128,16 @@ class Test_TypeAssigner: Test_Core {
136128
]
137129
for (string, defensiveName, idiomaticName) in cases {
138130
let contentType = try XCTUnwrap(ContentType(string: string))
139-
XCTAssertEqual(defensiveNameMaker(contentType), defensiveName, "Case \(string) failed for defensive strategy")
140-
XCTAssertEqual(idiomaticNameMaker(contentType), idiomaticName, "Case \(string) failed for idiomatic strategy")
131+
XCTAssertEqual(
132+
defensiveNameMaker(contentType),
133+
defensiveName,
134+
"Case \(string) failed for defensive strategy"
135+
)
136+
XCTAssertEqual(
137+
idiomaticNameMaker(contentType),
138+
idiomaticName,
139+
"Case \(string) failed for idiomatic strategy"
140+
)
141141
}
142142
}
143143
}

Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,53 +2309,52 @@ final class SnippetBasedReferenceTests: XCTestCase {
23092309

23102310
func testSynthesizedOperationId_defensive() throws {
23112311
let paths = """
2312-
/pets/{petId}/notifications:
2313-
parameters:
2314-
- name: petId
2315-
in: path
2316-
required: true
2317-
schema:
2318-
type: string
2319-
get:
2320-
responses:
2321-
'204':
2322-
description: A success response.
2323-
"""
2312+
/pets/{petId}/notifications:
2313+
parameters:
2314+
- name: petId
2315+
in: path
2316+
required: true
2317+
schema:
2318+
type: string
2319+
get:
2320+
responses:
2321+
'204':
2322+
description: A success response.
2323+
"""
23242324
try self.assertPathsTranslation(
23252325
paths,
2326-
"""
2327-
public protocol APIProtocol: Sendable {
2328-
func get_sol_pets_sol__lcub_petId_rcub__sol_notifications(_ input: Operations.get_sol_pets_sol__lcub_petId_rcub__sol_notifications.Input) async throws -> Operations.get_sol_pets_sol__lcub_petId_rcub__sol_notifications.Output
2329-
}
2330-
"""
2326+
"""
2327+
public protocol APIProtocol: Sendable {
2328+
func get_sol_pets_sol__lcub_petId_rcub__sol_notifications(_ input: Operations.get_sol_pets_sol__lcub_petId_rcub__sol_notifications.Input) async throws -> Operations.get_sol_pets_sol__lcub_petId_rcub__sol_notifications.Output
2329+
}
2330+
"""
23312331
)
23322332
}
23332333

23342334
func testSynthesizedOperationId_idiomatic() throws {
23352335
let paths = """
2336-
/pets/{petId}/notifications:
2337-
parameters:
2338-
- name: petId
2339-
in: path
2340-
required: true
2341-
schema:
2342-
type: string
2343-
get:
2344-
responses:
2345-
'204':
2346-
description: A success response.
2347-
"""
2336+
/pets/{petId}/notifications:
2337+
parameters:
2338+
- name: petId
2339+
in: path
2340+
required: true
2341+
schema:
2342+
type: string
2343+
get:
2344+
responses:
2345+
'204':
2346+
description: A success response.
2347+
"""
23482348
try self.assertPathsTranslation(
23492349
paths,
23502350
namingStrategy: .idiomatic,
2351-
"""
2352-
public protocol APIProtocol: Sendable {
2353-
func getPetsPetIdNotifications(_ input: Operations.GetPetsPetIdNotifications.Input) async throws -> Operations.GetPetsPetIdNotifications.Output
2354-
}
2355-
"""
2351+
"""
2352+
public protocol APIProtocol: Sendable {
2353+
func getPetsPetIdNotifications(_ input: Operations.GetPetsPetIdNotifications.Input) async throws -> Operations.GetPetsPetIdNotifications.Output
2354+
}
2355+
"""
23562356
)
23572357
}
2358-
23592358
func testServerRegisterHandlers_oneOperation() throws {
23602359
try self.assertServerRegisterHandlers(
23612360
"""
@@ -6140,10 +6139,7 @@ extension SnippetBasedReferenceTests {
61406139
file: StaticString = #filePath,
61416140
line: UInt = #line
61426141
) throws {
6143-
let translator = try makeTypesTranslator(
6144-
namingStrategy: namingStrategy,
6145-
componentsYAML: componentsYAML
6146-
)
6142+
let translator = try makeTypesTranslator(namingStrategy: namingStrategy, componentsYAML: componentsYAML)
61476143
let paths = try YAMLDecoder().decode(OpenAPI.PathItem.Map.self, from: pathsYAML)
61486144
let translation = try translator.translateAPIProtocol(paths)
61496145
try XCTAssertSwiftEquivalent(translation, expectedSwift, file: file, line: line)

0 commit comments

Comments
 (0)