Skip to content

Commit ebd7d01

Browse files
committed
Don't extend JSONEncodable when using Vapor.
1 parent e55c757 commit ebd7d01

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ extension Date: JSONEncodable {
6565
func encodeToJSON() -> Any {
6666
return CodableHelper.dateFormatter.string(from: self)
6767
}
68-
}{{/useVapor}}{{#generateModelAdditionalProperties}}
68+
}
69+
70+
extension JSONEncodable where Self: Encodable {
71+
func encodeToJSON() -> Any {
72+
let encoder = CodableHelper.jsonEncoder
73+
guard let data = try? encoder.encode(self) else {
74+
fatalError("Could not encode to json: \(self)")
75+
}
76+
return data.encodeToJSON()
77+
}
78+
}
79+
{{/useVapor}}{{#generateModelAdditionalProperties}}
6980

7081
extension String: CodingKey {
7182
@@ -206,13 +217,3 @@ extension Set: RequestDecodable where Element: Content {
206217
extension Set: Content where Element: Content { }
207218

208219
extension AnyCodable: Content {}{{/useVapor}}
209-
210-
extension JSONEncodable where Self: Encodable {
211-
func encodeToJSON() -> Any {
212-
let encoder = CodableHelper.jsonEncoder
213-
guard let data = try? encoder.encode(self) else {
214-
fatalError("Could not encode to json: \(self)")
215-
}
216-
return data.encodeToJSON()
217-
}
218-
}

0 commit comments

Comments
 (0)