Skip to content

Commit 250adec

Browse files
authored
Merge pull request #9906 from hlineholm/hlineholm/use-jsonvalue
Add missing JSONValue files
2 parents 3089fd3 + d4802cd commit 250adec

File tree

11 files changed

+408
-12
lines changed

11 files changed

+408
-12
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.11-SNAPSHOT

samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ open class FakeAPI {
451451
- parameter param: (body) request body
452452
- parameter completion: completion handler to receive the data and the error objects
453453
*/
454-
open class func testInlineAdditionalProperties(param: Any, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
454+
open class func testInlineAdditionalProperties(param: JSONValue, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
455455
testInlineAdditionalPropertiesWithRequestBuilder(param: param).execute { (response, error) -> Void in
456456
if error == nil {
457457
completion((), error)
@@ -471,7 +471,7 @@ open class FakeAPI {
471471

472472
- returns: RequestBuilder<Void>
473473
*/
474-
open class func testInlineAdditionalPropertiesWithRequestBuilder(param: Any) -> RequestBuilder<Void> {
474+
open class func testInlineAdditionalPropertiesWithRequestBuilder(param: JSONValue) -> RequestBuilder<Void> {
475475
let path = "/fake/inline-additionalProperties"
476476
let URLString = PetstoreClientAPI.basePath + path
477477
let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: param)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// JSONEncodingHelper.swift
3+
//
4+
// Generated by swagger-codegen
5+
// https://github.com/swagger-api/swagger-codegen
6+
//
7+
8+
import Foundation
9+
10+
11+
public enum JSONValue: Codable, Equatable {
12+
case string(String)
13+
case int(Int)
14+
case double(Double)
15+
case bool(Bool)
16+
case object([String: JSONValue])
17+
case array([JSONValue])
18+
case null
19+
20+
public func encode(to encoder: Encoder) throws {
21+
var container = encoder.singleValueContainer()
22+
switch self {
23+
case .string(let string): try container.encode(string)
24+
case .int(let int): try container.encode(int)
25+
case .double(let double): try container.encode(double)
26+
case .bool(let bool): try container.encode(bool)
27+
case .object(let object): try container.encode(object)
28+
case .array(let array): try container.encode(array)
29+
case .null: try container.encode(Optional<String>.none)
30+
}
31+
}
32+
33+
public init(from decoder: Decoder) throws {
34+
let container = try decoder.singleValueContainer()
35+
self = try ((try? container.decode(String.self)).map(JSONValue.string))
36+
.or((try? container.decode(Int.self)).map(JSONValue.int))
37+
.or((try? container.decode(Double.self)).map(JSONValue.double))
38+
.or((try? container.decode(Bool.self)).map(JSONValue.bool))
39+
.or((try? container.decode([String: JSONValue].self)).map(JSONValue.object))
40+
.or((try? container.decode([JSONValue].self)).map(JSONValue.array))
41+
.or((container.decodeNil() ? .some(JSONValue.null) : .none))
42+
.resolve(
43+
with: DecodingError.typeMismatch(
44+
JSONValue.self,
45+
DecodingError.Context(
46+
codingPath: container.codingPath,
47+
debugDescription: "Not a JSON value"
48+
)
49+
)
50+
)
51+
}
52+
53+
}
54+
55+
extension JSONValue: ExpressibleByStringLiteral {
56+
public init(stringLiteral value: String) {
57+
self = .string(value)
58+
}
59+
}
60+
extension JSONValue: ExpressibleByIntegerLiteral {
61+
public init(integerLiteral value: Int) {
62+
self = .int(value)
63+
}
64+
}
65+
extension JSONValue: ExpressibleByFloatLiteral {
66+
public init(floatLiteral value: Double) {
67+
self = .double(value)
68+
}
69+
}
70+
extension JSONValue: ExpressibleByBooleanLiteral {
71+
public init(booleanLiteral value: Bool) {
72+
self = .bool(value)
73+
}
74+
}
75+
extension JSONValue: ExpressibleByDictionaryLiteral {
76+
public init(dictionaryLiteral elements: (String, JSONValue)...) {
77+
self = .object([String: JSONValue](uniqueKeysWithValues: elements))
78+
}
79+
}
80+
extension JSONValue: ExpressibleByArrayLiteral {
81+
public init(arrayLiteral elements: JSONValue...) {
82+
self = .array(elements)
83+
}
84+
}
85+
86+
fileprivate extension Optional {
87+
func or(_ other: Optional) -> Optional {
88+
switch self {
89+
case .none: return other
90+
case .some: return self
91+
}
92+
}
93+
func resolve(with error: @autoclosure () -> Error) throws -> Wrapped {
94+
switch self {
95+
case .none: throw error()
96+
case .some(let wrapped): return wrapped
97+
}
98+
}
99+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.11-SNAPSHOT

samples/client/petstore/swift5/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ open class FakeAPI {
604604
- parameter param: (body) request body
605605
- parameter completion: completion handler to receive the data and the error objects
606606
*/
607-
open class func testInlineAdditionalProperties(param: Any, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
607+
open class func testInlineAdditionalProperties(param: JSONValue, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
608608
testInlineAdditionalPropertiesWithRequestBuilder(param: param).execute { (response, error) -> Void in
609609
if error == nil {
610610
completion((), error)
@@ -620,7 +620,7 @@ open class FakeAPI {
620620
- parameter param: (body) request body
621621
- returns: Promise<Void>
622622
*/
623-
open class func testInlineAdditionalProperties( param: Any) -> Promise<Void> {
623+
open class func testInlineAdditionalProperties( param: JSONValue) -> Promise<Void> {
624624
let deferred = Promise<Void>.pending()
625625
testInlineAdditionalProperties(param: param) { data, error in
626626
if let error = error {
@@ -641,7 +641,7 @@ open class FakeAPI {
641641

642642
- returns: RequestBuilder<Void>
643643
*/
644-
open class func testInlineAdditionalPropertiesWithRequestBuilder(param: Any) -> RequestBuilder<Void> {
644+
open class func testInlineAdditionalPropertiesWithRequestBuilder(param: JSONValue) -> RequestBuilder<Void> {
645645
let path = "/fake/inline-additionalProperties"
646646
let URLString = PetstoreClientAPI.basePath + path
647647
let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: param)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// JSONEncodingHelper.swift
3+
//
4+
// Generated by swagger-codegen
5+
// https://github.com/swagger-api/swagger-codegen
6+
//
7+
8+
import Foundation
9+
10+
11+
public enum JSONValue: Codable, Equatable {
12+
case string(String)
13+
case int(Int)
14+
case double(Double)
15+
case bool(Bool)
16+
case object([String: JSONValue])
17+
case array([JSONValue])
18+
case null
19+
20+
public func encode(to encoder: Encoder) throws {
21+
var container = encoder.singleValueContainer()
22+
switch self {
23+
case .string(let string): try container.encode(string)
24+
case .int(let int): try container.encode(int)
25+
case .double(let double): try container.encode(double)
26+
case .bool(let bool): try container.encode(bool)
27+
case .object(let object): try container.encode(object)
28+
case .array(let array): try container.encode(array)
29+
case .null: try container.encode(Optional<String>.none)
30+
}
31+
}
32+
33+
public init(from decoder: Decoder) throws {
34+
let container = try decoder.singleValueContainer()
35+
self = try ((try? container.decode(String.self)).map(JSONValue.string))
36+
.or((try? container.decode(Int.self)).map(JSONValue.int))
37+
.or((try? container.decode(Double.self)).map(JSONValue.double))
38+
.or((try? container.decode(Bool.self)).map(JSONValue.bool))
39+
.or((try? container.decode([String: JSONValue].self)).map(JSONValue.object))
40+
.or((try? container.decode([JSONValue].self)).map(JSONValue.array))
41+
.or((container.decodeNil() ? .some(JSONValue.null) : .none))
42+
.resolve(
43+
with: DecodingError.typeMismatch(
44+
JSONValue.self,
45+
DecodingError.Context(
46+
codingPath: container.codingPath,
47+
debugDescription: "Not a JSON value"
48+
)
49+
)
50+
)
51+
}
52+
53+
}
54+
55+
extension JSONValue: ExpressibleByStringLiteral {
56+
public init(stringLiteral value: String) {
57+
self = .string(value)
58+
}
59+
}
60+
extension JSONValue: ExpressibleByIntegerLiteral {
61+
public init(integerLiteral value: Int) {
62+
self = .int(value)
63+
}
64+
}
65+
extension JSONValue: ExpressibleByFloatLiteral {
66+
public init(floatLiteral value: Double) {
67+
self = .double(value)
68+
}
69+
}
70+
extension JSONValue: ExpressibleByBooleanLiteral {
71+
public init(booleanLiteral value: Bool) {
72+
self = .bool(value)
73+
}
74+
}
75+
extension JSONValue: ExpressibleByDictionaryLiteral {
76+
public init(dictionaryLiteral elements: (String, JSONValue)...) {
77+
self = .object([String: JSONValue](uniqueKeysWithValues: elements))
78+
}
79+
}
80+
extension JSONValue: ExpressibleByArrayLiteral {
81+
public init(arrayLiteral elements: JSONValue...) {
82+
self = .array(elements)
83+
}
84+
}
85+
86+
fileprivate extension Optional {
87+
func or(_ other: Optional) -> Optional {
88+
switch self {
89+
case .none: return other
90+
case .some: return self
91+
}
92+
}
93+
func resolve(with error: @autoclosure () -> Error) throws -> Wrapped {
94+
switch self {
95+
case .none: throw error()
96+
case .some(let wrapped): return wrapped
97+
}
98+
}
99+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.11-SNAPSHOT

samples/client/petstore/swift5/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ open class FakeAPI {
620620
- parameter param: (body) request body
621621
- parameter completion: completion handler to receive the data and the error objects
622622
*/
623-
open class func testInlineAdditionalProperties(param: Any, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
623+
open class func testInlineAdditionalProperties(param: JSONValue, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
624624
testInlineAdditionalPropertiesWithRequestBuilder(param: param).execute { (response, error) -> Void in
625625
if error == nil {
626626
completion((), error)
@@ -636,7 +636,7 @@ open class FakeAPI {
636636
- parameter param: (body) request body
637637
- returns: Observable<Void>
638638
*/
639-
open class func testInlineAdditionalProperties(param: Any) -> Observable<Void> {
639+
open class func testInlineAdditionalProperties(param: JSONValue) -> Observable<Void> {
640640
return Observable.create { observer -> Disposable in
641641
testInlineAdditionalProperties(param: param) { data, error in
642642
if let error = error {
@@ -659,7 +659,7 @@ open class FakeAPI {
659659

660660
- returns: RequestBuilder<Void>
661661
*/
662-
open class func testInlineAdditionalPropertiesWithRequestBuilder(param: Any) -> RequestBuilder<Void> {
662+
open class func testInlineAdditionalPropertiesWithRequestBuilder(param: JSONValue) -> RequestBuilder<Void> {
663663
let path = "/fake/inline-additionalProperties"
664664
let URLString = PetstoreClientAPI.basePath + path
665665
let parameters = JSONEncodingHelper.encodingParameters(forEncodableObject: param)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// JSONEncodingHelper.swift
3+
//
4+
// Generated by swagger-codegen
5+
// https://github.com/swagger-api/swagger-codegen
6+
//
7+
8+
import Foundation
9+
10+
11+
public enum JSONValue: Codable, Equatable {
12+
case string(String)
13+
case int(Int)
14+
case double(Double)
15+
case bool(Bool)
16+
case object([String: JSONValue])
17+
case array([JSONValue])
18+
case null
19+
20+
public func encode(to encoder: Encoder) throws {
21+
var container = encoder.singleValueContainer()
22+
switch self {
23+
case .string(let string): try container.encode(string)
24+
case .int(let int): try container.encode(int)
25+
case .double(let double): try container.encode(double)
26+
case .bool(let bool): try container.encode(bool)
27+
case .object(let object): try container.encode(object)
28+
case .array(let array): try container.encode(array)
29+
case .null: try container.encode(Optional<String>.none)
30+
}
31+
}
32+
33+
public init(from decoder: Decoder) throws {
34+
let container = try decoder.singleValueContainer()
35+
self = try ((try? container.decode(String.self)).map(JSONValue.string))
36+
.or((try? container.decode(Int.self)).map(JSONValue.int))
37+
.or((try? container.decode(Double.self)).map(JSONValue.double))
38+
.or((try? container.decode(Bool.self)).map(JSONValue.bool))
39+
.or((try? container.decode([String: JSONValue].self)).map(JSONValue.object))
40+
.or((try? container.decode([JSONValue].self)).map(JSONValue.array))
41+
.or((container.decodeNil() ? .some(JSONValue.null) : .none))
42+
.resolve(
43+
with: DecodingError.typeMismatch(
44+
JSONValue.self,
45+
DecodingError.Context(
46+
codingPath: container.codingPath,
47+
debugDescription: "Not a JSON value"
48+
)
49+
)
50+
)
51+
}
52+
53+
}
54+
55+
extension JSONValue: ExpressibleByStringLiteral {
56+
public init(stringLiteral value: String) {
57+
self = .string(value)
58+
}
59+
}
60+
extension JSONValue: ExpressibleByIntegerLiteral {
61+
public init(integerLiteral value: Int) {
62+
self = .int(value)
63+
}
64+
}
65+
extension JSONValue: ExpressibleByFloatLiteral {
66+
public init(floatLiteral value: Double) {
67+
self = .double(value)
68+
}
69+
}
70+
extension JSONValue: ExpressibleByBooleanLiteral {
71+
public init(booleanLiteral value: Bool) {
72+
self = .bool(value)
73+
}
74+
}
75+
extension JSONValue: ExpressibleByDictionaryLiteral {
76+
public init(dictionaryLiteral elements: (String, JSONValue)...) {
77+
self = .object([String: JSONValue](uniqueKeysWithValues: elements))
78+
}
79+
}
80+
extension JSONValue: ExpressibleByArrayLiteral {
81+
public init(arrayLiteral elements: JSONValue...) {
82+
self = .array(elements)
83+
}
84+
}
85+
86+
fileprivate extension Optional {
87+
func or(_ other: Optional) -> Optional {
88+
switch self {
89+
case .none: return other
90+
case .some: return self
91+
}
92+
}
93+
func resolve(with error: @autoclosure () -> Error) throws -> Wrapped {
94+
switch self {
95+
case .none: throw error()
96+
case .some(let wrapped): return wrapped
97+
}
98+
}
99+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.9-SNAPSHOT
1+
2.4.11-SNAPSHOT

0 commit comments

Comments
 (0)