Skip to content

Commit 8f4cfa3

Browse files
authored
[swift] fix typos, minor code format enhancement (OpenAPITools#20387)
* fix typo in swift option, minor code format enhancement * fix uuid typo in swift codegen and template * fix typo minium
1 parent 93158ea commit 8f4cfa3

File tree

38 files changed

+265
-226
lines changed

38 files changed

+265
-226
lines changed

docs/generators/swift5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5656
|useCustomDateWithoutTime|Uses a custom type to decode and encode dates without time information to support OpenAPIs date format (default: false)| |false|
5757
|useJsonEncodable|Make models conform to JSONEncodable protocol (default: true)| |true|
5858
|useSPMFileStructure|Use SPM file structure and set the source path to Sources/{{projectName}} (default: false).| |null|
59-
|validatable|Make validation rules and validator for model properies (default: true)| |true|
59+
|validatable|Make validation rules and validator for model properties (default: true)| |true|
6060

6161
## IMPORT MAPPING
6262

docs/generators/swift6.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5858
|useCustomDateWithoutTime|Uses a custom type to decode and encode dates without time information to support OpenAPIs date format (default: false)| |false|
5959
|useJsonEncodable|Make models conform to JSONEncodable protocol (default: true)| |true|
6060
|useSPMFileStructure|Use SPM file structure and set the source path to Sources/{{projectName}} (default: true).| |null|
61-
|validatable|Make validation rules and validator for model properies (default: true)| |true|
61+
|validatable|Make validation rules and validator for model properties (default: true)| |true|
6262

6363
## IMPORT MAPPING
6464

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,43 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
8484
protected static final String RESPONSE_LIBRARY_COMBINE = "Combine";
8585
protected static final String RESPONSE_LIBRARY_ASYNC_AWAIT = "AsyncAwait";
8686
protected static final String[] RESPONSE_LIBRARIES = {RESPONSE_LIBRARY_PROMISE_KIT, RESPONSE_LIBRARY_RX_SWIFT, RESPONSE_LIBRARY_RESULT, RESPONSE_LIBRARY_COMBINE, RESPONSE_LIBRARY_ASYNC_AWAIT};
87-
@Setter protected String projectName = "OpenAPIClient";
88-
@Setter protected boolean nonPublicApi = false;
89-
@Setter protected boolean objcCompatible = false;
90-
@Setter protected boolean readonlyProperties = false;
91-
@Setter protected boolean swiftUseApiNamespace = false;
92-
@Setter protected boolean useSPMFileStructure = false;
93-
@Setter protected String swiftPackagePath = "Classes" + File.separator + "OpenAPIs";
94-
@Setter protected boolean oneOfUnknownDefaultCase = false;
95-
@Setter protected boolean useClasses = false;
96-
@Setter protected boolean useBacktickEscapes = false;
97-
@Setter protected boolean generateModelAdditionalProperties = true;
98-
@Setter protected boolean hashableModels = true;
99-
@Setter protected boolean identifiableModels = true;
100-
@Setter protected boolean useJsonEncodable = true;
101-
@Getter @Setter
87+
@Setter
88+
protected String projectName = "OpenAPIClient";
89+
@Setter
90+
protected boolean nonPublicApi = false;
91+
@Setter
92+
protected boolean objcCompatible = false;
93+
@Setter
94+
protected boolean readonlyProperties = false;
95+
@Setter
96+
protected boolean swiftUseApiNamespace = false;
97+
@Setter
98+
protected boolean useSPMFileStructure = false;
99+
@Setter
100+
protected String swiftPackagePath = "Classes" + File.separator + "OpenAPIs";
101+
@Setter
102+
protected boolean oneOfUnknownDefaultCase = false;
103+
@Setter
104+
protected boolean useClasses = false;
105+
@Setter
106+
protected boolean useBacktickEscapes = false;
107+
@Setter
108+
protected boolean generateModelAdditionalProperties = true;
109+
@Setter
110+
protected boolean hashableModels = true;
111+
@Setter
112+
protected boolean identifiableModels = true;
113+
@Setter
114+
protected boolean useJsonEncodable = true;
115+
@Getter
116+
@Setter
102117
protected boolean mapFileBinaryToData = false;
103-
@Setter protected boolean useCustomDateWithoutTime = false;
104-
@Setter protected boolean validatable = true;
105-
@Setter protected String[] responseAs = new String[0];
118+
@Setter
119+
protected boolean useCustomDateWithoutTime = false;
120+
@Setter
121+
protected boolean validatable = true;
122+
@Setter
123+
protected String[] responseAs = new String[0];
106124
protected String sourceFolder = swiftPackagePath;
107125
protected HashSet objcReservedWords;
108126
protected String apiDocPath = "docs/";
@@ -322,7 +340,7 @@ public Swift5ClientCodegen() {
322340
.defaultValue(Boolean.FALSE.toString()));
323341

324342
cliOptions.add(new CliOption(VALIDATABLE,
325-
"Make validation rules and validator for model properies (default: true)")
343+
"Make validation rules and validator for model properties (default: true)")
326344
.defaultValue(Boolean.TRUE.toString()));
327345

328346
supportedLibraries.put(LIBRARY_URLSESSION, "[DEFAULT] HTTP client: URLSession");
@@ -1189,7 +1207,7 @@ public void postProcessFile(File file, String fileType) {
11891207
}
11901208
// only process files with swift extension
11911209
if ("swift".equals(FilenameUtils.getExtension(file.toString()))) {
1192-
this.executePostProcessor(new String[] {swiftPostProcessFile, file.toString()});
1210+
this.executePostProcessor(new String[]{swiftPostProcessFile, file.toString()});
11931211
}
11941212
}
11951213

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift6ClientCodegen.java

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,48 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
8686
protected static final String RESPONSE_LIBRARY_COMBINE = "Combine";
8787
protected static final String RESPONSE_LIBRARY_ASYNC_AWAIT = "AsyncAwait";
8888
protected static final String RESPONSE_LIBRARY_OBJC_BLOCK = "ObjcBlock";
89-
protected static final String[] RESPONSE_LIBRARIES = { RESPONSE_LIBRARY_ASYNC_AWAIT, RESPONSE_LIBRARY_COMBINE, RESPONSE_LIBRARY_RESULT, RESPONSE_LIBRARY_RX_SWIFT, RESPONSE_LIBRARY_OBJC_BLOCK, RESPONSE_LIBRARY_PROMISE_KIT };
90-
@Setter protected String projectName = "OpenAPIClient";
91-
@Setter protected boolean nonPublicApi = false;
92-
@Setter protected boolean objcCompatible = false;
93-
@Setter protected boolean readonlyProperties = false;
94-
@Setter protected boolean swiftUseApiNamespace = false;
95-
@Setter protected boolean useSPMFileStructure = true;
96-
@Setter protected String swiftPackagePath = "Sources" + File.separator + projectName;
97-
@Setter protected boolean oneOfUnknownDefaultCase = false;
98-
@Setter protected boolean useClasses = false;
99-
@Setter protected boolean useBacktickEscapes = false;
100-
@Setter protected boolean generateModelAdditionalProperties = true;
101-
@Setter protected boolean hashableModels = true;
102-
@Setter protected boolean identifiableModels = true;
103-
@Setter protected boolean useJsonEncodable = true;
104-
@Getter @Setter protected boolean mapFileBinaryToData = false;
105-
@Setter protected boolean useCustomDateWithoutTime = false;
106-
@Setter protected boolean validatable = true;
107-
@Setter protected boolean apiStaticMethod = true;
108-
@Setter protected boolean combineDeferred = true;
109-
@Setter protected String[] responseAs = { RESPONSE_LIBRARY_ASYNC_AWAIT };
89+
protected static final String[] RESPONSE_LIBRARIES = {RESPONSE_LIBRARY_ASYNC_AWAIT, RESPONSE_LIBRARY_COMBINE, RESPONSE_LIBRARY_RESULT, RESPONSE_LIBRARY_RX_SWIFT, RESPONSE_LIBRARY_OBJC_BLOCK, RESPONSE_LIBRARY_PROMISE_KIT};
90+
@Setter
91+
protected String projectName = "OpenAPIClient";
92+
@Setter
93+
protected boolean nonPublicApi = false;
94+
@Setter
95+
protected boolean objcCompatible = false;
96+
@Setter
97+
protected boolean readonlyProperties = false;
98+
@Setter
99+
protected boolean swiftUseApiNamespace = false;
100+
@Setter
101+
protected boolean useSPMFileStructure = true;
102+
@Setter
103+
protected String swiftPackagePath = "Sources" + File.separator + projectName;
104+
@Setter
105+
protected boolean oneOfUnknownDefaultCase = false;
106+
@Setter
107+
protected boolean useClasses = false;
108+
@Setter
109+
protected boolean useBacktickEscapes = false;
110+
@Setter
111+
protected boolean generateModelAdditionalProperties = true;
112+
@Setter
113+
protected boolean hashableModels = true;
114+
@Setter
115+
protected boolean identifiableModels = true;
116+
@Setter
117+
protected boolean useJsonEncodable = true;
118+
@Getter
119+
@Setter
120+
protected boolean mapFileBinaryToData = false;
121+
@Setter
122+
protected boolean useCustomDateWithoutTime = false;
123+
@Setter
124+
protected boolean validatable = true;
125+
@Setter
126+
protected boolean apiStaticMethod = true;
127+
@Setter
128+
protected boolean combineDeferred = true;
129+
@Setter
130+
protected String[] responseAs = {RESPONSE_LIBRARY_ASYNC_AWAIT};
110131
protected String sourceFolder = swiftPackagePath;
111132
protected HashSet objcReservedWords;
112133
protected String apiDocPath = "docs/";
@@ -326,7 +347,7 @@ public Swift6ClientCodegen() {
326347
.defaultValue(Boolean.FALSE.toString()));
327348

328349
cliOptions.add(new CliOption(VALIDATABLE,
329-
"Make validation rules and validator for model properies (default: true)")
350+
"Make validation rules and validator for model properties (default: true)")
330351
.defaultValue(Boolean.TRUE.toString()));
331352

332353
cliOptions.add(new CliOption(API_STATIC_METHOD,
@@ -1222,7 +1243,7 @@ public void postProcessFile(File file, String fileType) {
12221243
}
12231244
// only process files with swift extension
12241245
if ("swift".equals(FilenameUtils.getExtension(file.toString()))) {
1225-
this.executePostProcessor(new String[] {swiftPostProcessFile, file.toString()});
1246+
this.executePostProcessor(new String[]{swiftPostProcessFile, file.toString()});
12261247
}
12271248
}
12281249

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftCombineClientCodegen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,8 @@ protected void addVendorExtensions(CodegenParameter cp, CodegenOperation operati
746746
CodegenModel baseModel = modelMaps.get(cp.items.dataType);
747747
boolean isBaseTypeEnum = cp.items.isEnum || cp.isEnum || (baseModel != null && baseModel.isEnum);
748748
cp.vendorExtensions.put("x-swift-is-base-type-enum", isBaseTypeEnum);
749-
boolean isBaseTypeUdid = cp.items.isUuid || cp.isUuid;
750-
cp.vendorExtensions.put("x-swift-is-base-type-udid", isBaseTypeUdid);
749+
boolean isBaseTypeUuid = cp.items.isUuid || cp.isUuid;
750+
cp.vendorExtensions.put("x-swift-is-base-type-uuid", isBaseTypeUuid);
751751

752752
boolean useEncoder = !isBaseTypeEnum && !cp.items.isString || (baseModel != null && !baseModel.isString);
753753
cp.vendorExtensions.put("x-swift-use-encoder", useEncoder);

modules/openapi-generator/src/main/resources/swift-combine/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ open class {{classname}} {
7474
/// - defaultResponse: {{.}}{{/defaultResponse}}
7575
{{#authMethods}}
7676
/// - {{#isBasicBasic}}BASIC{{/isBasicBasic}}{{#isOAuth}}OAuth{{/isOAuth}}{{#isApiKey}}API Key{{/isApiKey}}:
77-
/// - type: {{type}}{{#keyParamName}} {{keyParamName}} {{#isKeyInQuery}}(QUERY){{/isKeyInQuery}}{{#isKeyInHeaer}}(HEADER){{/isKeyInHeaer}}{{/keyParamName}}
77+
/// - type: {{type}}{{#keyParamName}} {{keyParamName}} {{#isKeyInQuery}}(QUERY){{/isKeyInQuery}}{{#isKeyInHeader}}(HEADER){{/isKeyInHeader}}{{/keyParamName}}
7878
/// - name: {{name}}
7979
{{/authMethods}}
8080
{{#hasResponseHeaders}}
@@ -212,4 +212,4 @@ open class {{classname}} {
212212
}
213213
{{/operation}}
214214
}
215-
{{/operations}}
215+
{{/operations}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isDateTime}}OpenISO8601DateFormatter.shared.string(from: {{paramName}}){{/isDateTime}}{{#vendorExtensions.x-swift-use-encoder}}String(data: try self.encoder.encode({{paramName}}), encoding: .utf8) ?? ""{{/vendorExtensions.x-swift-use-encoder}}{{^vendorExtensions.x-swift-use-encoder}}{{#isArray}}{{paramName}}{{#vendorExtensions.x-swift-is-base-type-udid}}.map { $0.uuidString }{{/vendorExtensions.x-swift-is-base-type-udid}}{{#vendorExtensions.x-swift-is-base-type-enum}}.map { $0.rawValue }{{/vendorExtensions.x-swift-is-base-type-enum}}.joined(separator: ","){{/isArray}}{{^isArray}}{{#vendorExtensions.x-swift-is-enum-type}}{{paramName}}.rawValue{{/vendorExtensions.x-swift-is-enum-type}}{{^isEnum}}{{#isString}}{{#isUuid}}{{paramName}}.uuidString{{/isUuid}}{{^isUuid}}{{paramName}}{{/isUuid}}{{/isString}}{{#isInteger}}"\({{paramName}})"{{/isInteger}}{{#isDouble}}"\({{paramName}})"{{/isDouble}}{{#isFloat}}"\({{paramName}})"{{/isFloat}}{{#isNumber}}"\({{paramName}})"{{/isNumber}}{{#isLong}}"\({{paramName}})"{{/isLong}}{{#isBoolean}}{{paramName}} ? "true" : "false"{{/isBoolean}}{{/isEnum}}{{/isArray}}{{/vendorExtensions.x-swift-use-encoder}}
1+
{{#isDateTime}}OpenISO8601DateFormatter.shared.string(from: {{paramName}}){{/isDateTime}}{{#vendorExtensions.x-swift-use-encoder}}String(data: try self.encoder.encode({{paramName}}), encoding: .utf8) ?? ""{{/vendorExtensions.x-swift-use-encoder}}{{^vendorExtensions.x-swift-use-encoder}}{{#isArray}}{{paramName}}{{#vendorExtensions.x-swift-is-base-type-uuid}}.map { $0.uuidString }{{/vendorExtensions.x-swift-is-base-type-uuid}}{{#vendorExtensions.x-swift-is-base-type-enum}}.map { $0.rawValue }{{/vendorExtensions.x-swift-is-base-type-enum}}.joined(separator: ","){{/isArray}}{{^isArray}}{{#vendorExtensions.x-swift-is-enum-type}}{{paramName}}.rawValue{{/vendorExtensions.x-swift-is-enum-type}}{{^isEnum}}{{#isString}}{{#isUuid}}{{paramName}}.uuidString{{/isUuid}}{{^isUuid}}{{paramName}}{{/isUuid}}{{/isString}}{{#isInteger}}"\({{paramName}})"{{/isInteger}}{{#isDouble}}"\({{paramName}})"{{/isDouble}}{{#isFloat}}"\({{paramName}})"{{/isFloat}}{{#isNumber}}"\({{paramName}})"{{/isNumber}}{{#isLong}}"\({{paramName}})"{{/isLong}}{{#isBoolean}}{{paramName}} ? "true" : "false"{{/isBoolean}}{{/isEnum}}{{/isArray}}{{/vendorExtensions.x-swift-use-encoder}}

modules/openapi-generator/src/main/resources/swift5/Validation.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ import Foundation
7777
/// - Throws: `ValidationError<NumericValidationErrorKind>` if the numeric is invalid against the rule.
7878
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func validate<T: Comparable & BinaryInteger>(_ numeric: T, against rule: NumericRule<T>) throws -> T {
7979
var error = ValidationError<NumericValidationErrorKind>(kinds: [])
80-
if let minium = rule.minimum {
81-
if !rule.exclusiveMinimum, minium > numeric {
80+
if let minimum = rule.minimum {
81+
if !rule.exclusiveMinimum, minimum > numeric {
8282
error.kinds.insert(.minimum)
8383
}
84-
if rule.exclusiveMinimum, minium >= numeric {
84+
if rule.exclusiveMinimum, minimum >= numeric {
8585
error.kinds.insert(.minimum)
8686
}
8787
}
@@ -109,11 +109,11 @@ import Foundation
109109
/// - Throws: `ValidationError<NumericValidationErrorKind>` if the numeric is invalid against the rule.
110110
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func validate<T: Comparable & FloatingPoint>(_ numeric: T, against rule: NumericRule<T>) throws -> T {
111111
var error = ValidationError<NumericValidationErrorKind>(kinds: [])
112-
if let minium = rule.minimum {
113-
if !rule.exclusiveMinimum, minium > numeric {
112+
if let minimum = rule.minimum {
113+
if !rule.exclusiveMinimum, minimum > numeric {
114114
error.kinds.insert(.minimum)
115115
}
116-
if rule.exclusiveMinimum, minium >= numeric {
116+
if rule.exclusiveMinimum, minimum >= numeric {
117117
error.kinds.insert(.minimum)
118118
}
119119
}

modules/openapi-generator/src/main/resources/swift6/Validation.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ extension NumericRule: Sendable where T: Sendable {}
7878
/// - Throws: `ValidationError<NumericValidationErrorKind>` if the numeric is invalid against the rule.
7979
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func validate<T: Comparable & BinaryInteger>(_ numeric: T, against rule: NumericRule<T>) throws -> T {
8080
var error = ValidationError<NumericValidationErrorKind>(kinds: [])
81-
if let minium = rule.minimum {
82-
if !rule.exclusiveMinimum, minium > numeric {
81+
if let minimum = rule.minimum {
82+
if !rule.exclusiveMinimum, minimum > numeric {
8383
error.kinds.insert(.minimum)
8484
}
85-
if rule.exclusiveMinimum, minium >= numeric {
85+
if rule.exclusiveMinimum, minimum >= numeric {
8686
error.kinds.insert(.minimum)
8787
}
8888
}
@@ -110,11 +110,11 @@ extension NumericRule: Sendable where T: Sendable {}
110110
/// - Throws: `ValidationError<NumericValidationErrorKind>` if the numeric is invalid against the rule.
111111
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func validate<T: Comparable & FloatingPoint>(_ numeric: T, against rule: NumericRule<T>) throws -> T {
112112
var error = ValidationError<NumericValidationErrorKind>(kinds: [])
113-
if let minium = rule.minimum {
114-
if !rule.exclusiveMinimum, minium > numeric {
113+
if let minimum = rule.minimum {
114+
if !rule.exclusiveMinimum, minimum > numeric {
115115
error.kinds.insert(.minimum)
116116
}
117-
if rule.exclusiveMinimum, minium >= numeric {
117+
if rule.exclusiveMinimum, minimum >= numeric {
118118
error.kinds.insert(.minimum)
119119
}
120120
}

samples/client/petstore/swift-combine/client/PetstoreOpenAPI/Sources/APIs/PetAPI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ open class PetAPI {
273273
/// - GET /pet/{petId}
274274
/// - Returns a single pet
275275
/// - API Key:
276-
/// - type: apiKey api_key
276+
/// - type: apiKey api_key (HEADER)
277277
/// - name: api_key
278278
/// - parameter petId: (path) ID of pet to return
279279
/// - returns: AnyPublisher<Pet, Error>

0 commit comments

Comments
 (0)