forked from loafle/openapi-generator-original
review remarks
This commit is contained in:
@@ -136,7 +136,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"String",
|
||||
"Data",
|
||||
"Date",
|
||||
"DateWithoutTime",
|
||||
"OpenAPIDateWithoutTime",
|
||||
"Character",
|
||||
"UUID",
|
||||
"URL",
|
||||
@@ -528,7 +528,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
additionalProperties.put(USE_CUSTOM_DATE_WITHOUT_TIME, useCustomDateWithoutTime);
|
||||
if (useCustomDateWithoutTime) {
|
||||
typeMapping.put("date", "DateWithoutTime");
|
||||
typeMapping.put("date", "OpenAPIDateWithoutTime");
|
||||
} else {
|
||||
typeMapping.put("date", "Date");
|
||||
}
|
||||
@@ -588,9 +588,11 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
supportingFiles.add(new SupportingFile("OpenISO8601DateFormatter.mustache",
|
||||
sourceFolder,
|
||||
"OpenISO8601DateFormatter.swift"));
|
||||
supportingFiles.add(new SupportingFile("DateWithoutTime.mustache",
|
||||
if (additionalProperties.containsKey(USE_CUSTOM_DATE_WITHOUT_TIME)) {
|
||||
supportingFiles.add(new SupportingFile("OpenAPIDateWithoutTime.mustache",
|
||||
sourceFolder,
|
||||
"DateWithoutTime.swift"));
|
||||
"OpenAPIDateWithoutTime.swift"));
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("APIs.mustache",
|
||||
sourceFolder,
|
||||
"APIs.swift"));
|
||||
|
||||
@@ -93,12 +93,6 @@ extension Date: JSONEncodable {
|
||||
}
|
||||
}
|
||||
|
||||
extension DateWithoutTime: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate())
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONEncodable where Self: Encodable {
|
||||
func encodeToJSON() -> Any {
|
||||
guard let data = try? CodableHelper.jsonEncoder.encode(self) else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// DateWithoutTime.swift
|
||||
// OpenAPIDateWithoutTime.swift
|
||||
//
|
||||
// Generated by openapi-generator
|
||||
// https://openapi-generator.tech
|
||||
@@ -15,7 +15,7 @@ import Foundation
|
||||
/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601.
|
||||
/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate
|
||||
/// can be used safely.
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct DateWithoutTime: Codable, Hashable, Equatable {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct OpenAPIDateWithoutTime: Codable, Hashable, Equatable {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let wrappedDate: Date
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let timezone: TimeZone
|
||||
|
||||
@@ -40,7 +40,7 @@ import Foundation
|
||||
self.init(wrappedDate: wrappedDate, timezone: timezone)
|
||||
}
|
||||
|
||||
/// Designated Initializer for `DateWithoutTime`
|
||||
/// Designated Initializer for `OpenAPIDateWithoutTime`
|
||||
///
|
||||
/// Since usually `Date`s without time components - as e.g. birthdays - are created Calendar- and timezone-aware
|
||||
// it is important to also provide a timezone so that the generator is able to normalize the supplied Date to ISO8601 (GMT+0)
|
||||
@@ -56,8 +56,14 @@ import Foundation
|
||||
}
|
||||
|
||||
/// Normalizes the wrappedDate to GMT+0 according to the supplied timezone
|
||||
internal func normalizedWrappedDate() -> Date {
|
||||
fileprivate func normalizedWrappedDate() -> Date {
|
||||
return wrappedDate.addingTimeInterval(
|
||||
Double(timezone.secondsFromGMT(for: wrappedDate)))
|
||||
}
|
||||
}
|
||||
|
||||
extension OpenAPIDateWithoutTime: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate())
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class Swift5ClientCodegenTest {
|
||||
Assert.assertEquals(op.bodyParam.dataType, "Date");
|
||||
}
|
||||
|
||||
@Test(description = "returns DateWithoutTime when response format is date and cli option is enabled", enabled = true)
|
||||
@Test(description = "returns OpenAPIDateWithoutTime when response format is date and cli option is enabled", enabled = true)
|
||||
public void dateWithoutTimeTest() {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/datePropertyTest.json");
|
||||
final DefaultCodegen codegen = new Swift5ClientCodegen();
|
||||
@@ -162,8 +162,8 @@ public class Swift5ClientCodegenTest {
|
||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||
final CodegenOperation op = codegen.fromOperation(path, "post", p, null);
|
||||
|
||||
Assert.assertEquals(op.returnType, "DateWithoutTime");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "DateWithoutTime");
|
||||
Assert.assertEquals(op.returnType, "OpenAPIDateWithoutTime");
|
||||
Assert.assertEquals(op.bodyParam.dataType, "OpenAPIDateWithoutTime");
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
|
||||
@@ -155,10 +155,10 @@ public class Swift5ModelTest {
|
||||
Assert.assertFalse(property3.isContainer);
|
||||
|
||||
Assert.assertEquals(property7.baseName, "dateOfBirth");
|
||||
Assert.assertEquals(property7.dataType, "DateWithoutTime");
|
||||
Assert.assertEquals(property7.dataType, "OpenAPIDateWithoutTime");
|
||||
Assert.assertEquals(property7.name, "dateOfBirth");
|
||||
Assert.assertNull(property7.defaultValue);
|
||||
Assert.assertEquals(property7.baseType, "DateWithoutTime");
|
||||
Assert.assertEquals(property7.baseType, "OpenAPIDateWithoutTime");
|
||||
Assert.assertFalse(property7.required);
|
||||
Assert.assertFalse(property7.isContainer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user