forked from loafle/openapi-generator-original
[swift6] replace AnyCodable with JSONValue (#19763)
This commit is contained in:
parent
577483c2e2
commit
74100e44cb
@ -76,7 +76,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|
||||
<ul class="column-ul">
|
||||
<li>Any</li>
|
||||
<li>AnyCodable</li>
|
||||
<li>AnyObject</li>
|
||||
<li>Bool</li>
|
||||
<li>Character</li>
|
||||
@ -88,6 +87,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
<li>Int</li>
|
||||
<li>Int32</li>
|
||||
<li>Int64</li>
|
||||
<li>JSONValue</li>
|
||||
<li>OpenAPIDateWithoutTime</li>
|
||||
<li>String</li>
|
||||
<li>URL</li>
|
||||
|
@ -173,7 +173,7 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"AnyObject",
|
||||
"Any",
|
||||
"Decimal",
|
||||
"AnyCodable") // from AnyCodable dependency
|
||||
"JSONValue")
|
||||
);
|
||||
defaultIncludes = new HashSet<>(
|
||||
Arrays.asList(
|
||||
@ -279,8 +279,8 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("UUID", "UUID");
|
||||
typeMapping.put("URI", "String");
|
||||
typeMapping.put("decimal", "Decimal");
|
||||
typeMapping.put("object", "AnyCodable");
|
||||
typeMapping.put("AnyType", "AnyCodable");
|
||||
typeMapping.put("object", "JSONValue");
|
||||
typeMapping.put("AnyType", "JSONValue");
|
||||
|
||||
importMapping = new HashMap<>();
|
||||
|
||||
@ -651,6 +651,9 @@ public class Swift6ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
supportingFiles.add(new SupportingFile("OpenISO8601DateFormatter.mustache",
|
||||
sourceFolder,
|
||||
"OpenISO8601DateFormatter.swift"));
|
||||
supportingFiles.add(new SupportingFile("JSONValue.mustache",
|
||||
sourceFolder,
|
||||
"JSONValue.swift"));
|
||||
if (useCustomDateWithoutTime) {
|
||||
supportingFiles.add(new SupportingFile("OpenAPIDateWithoutTime.mustache",
|
||||
sourceFolder,
|
||||
|
@ -1,4 +1,3 @@
|
||||
github "Flight-School/AnyCodable" ~> 0.6{{#useAlamofire}}
|
||||
github "Alamofire/Alamofire" ~> 5.9{{/useAlamofire}}{{#usePromiseKit}}
|
||||
{{#useAlamofire}}github "Alamofire/Alamofire" ~> 5.9{{/useAlamofire}}{{#usePromiseKit}}
|
||||
github "mxcl/PromiseKit" ~> 8.1{{/usePromiseKit}}{{#useRxSwift}}
|
||||
github "ReactiveX/RxSwift" ~> 6.7{{/useRxSwift}}
|
||||
|
@ -7,9 +7,6 @@
|
||||
import Foundation
|
||||
#if canImport(FoundationNetworking)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif{{#usePromiseKit}}
|
||||
@preconcurrency import PromiseKit{{/usePromiseKit}}{{#useVapor}}
|
||||
import Vapor{{/useVapor}}{{^useVapor}}
|
||||
@ -277,4 +274,4 @@ extension Set: RequestDecodable where Element: Content {
|
||||
|
||||
extension Set: Content where Element: Content { }
|
||||
|
||||
extension AnyCodable: Content {}{{/useVapor}}
|
||||
extension JSONValue: Content {}{{/useVapor}}
|
||||
|
247
modules/openapi-generator/src/main/resources/swift6/JSONValue.mustache
vendored
Normal file
247
modules/openapi-generator/src/main/resources/swift6/JSONValue.mustache
vendored
Normal file
@ -0,0 +1,247 @@
|
||||
//
|
||||
// JSONValue.swift
|
||||
//
|
||||
// Generated by openapi-generator
|
||||
// https://openapi-generator.tech
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum JSONValue: Codable, Hashable {
|
||||
case string(String)
|
||||
case int(Int)
|
||||
case double(Double)
|
||||
case bool(Bool)
|
||||
case array([JSONValue])
|
||||
case dictionary([String: JSONValue])
|
||||
case null
|
||||
|
||||
// MARK: - Decoding Logic
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
|
||||
if let stringValue = try? container.decode(String.self) {
|
||||
self = .string(stringValue)
|
||||
} else if let intValue = try? container.decode(Int.self) {
|
||||
self = .int(intValue)
|
||||
} else if let doubleValue = try? container.decode(Double.self) {
|
||||
self = .double(doubleValue)
|
||||
} else if let boolValue = try? container.decode(Bool.self) {
|
||||
self = .bool(boolValue)
|
||||
} else if let arrayValue = try? container.decode([JSONValue].self) {
|
||||
self = .array(arrayValue)
|
||||
} else if let dictionaryValue = try? container.decode([String: JSONValue].self) {
|
||||
self = .dictionary(dictionaryValue)
|
||||
} else if container.decodeNil() {
|
||||
self = .null
|
||||
} else {
|
||||
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unknown JSON value")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Encoding Logic
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
|
||||
switch self {
|
||||
case .string(let value):
|
||||
try container.encode(value)
|
||||
case .int(let value):
|
||||
try container.encode(value)
|
||||
case .double(let value):
|
||||
try container.encode(value)
|
||||
case .bool(let value):
|
||||
try container.encode(value)
|
||||
case .array(let value):
|
||||
try container.encode(value)
|
||||
case .dictionary(let value):
|
||||
try container.encode(value)
|
||||
case .null:
|
||||
try container.encodeNil()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(_ value: String) {
|
||||
self = .string(value)
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(_ value: Int) {
|
||||
self = .int(value)
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(_ value: Double) {
|
||||
self = .double(value)
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(_ value: Bool) {
|
||||
self = .bool(value)
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(_ value: [JSONValue]) {
|
||||
self = .array(value)
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(_ value: [String: JSONValue]) {
|
||||
self = .dictionary(value)
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init<T: Codable>(_ codable: T) throws {
|
||||
let encoder = JSONEncoder()
|
||||
let encodedData = try encoder.encode(codable)
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
let decodedValue = try decoder.decode(JSONValue.self, from: encodedData)
|
||||
self = decodedValue
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var isString: Bool {
|
||||
if case .string = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var isInt: Bool {
|
||||
if case .int = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var isDouble: Bool {
|
||||
if case .double = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var isBool: Bool {
|
||||
if case .bool = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var isArray: Bool {
|
||||
if case .array = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var isDictionary: Bool {
|
||||
if case .dictionary = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var isNull: Bool {
|
||||
return self == .null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var stringValue: String? {
|
||||
switch self {
|
||||
case .string(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var intValue: Int? {
|
||||
switch self {
|
||||
case .int(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var doubleValue: Double? {
|
||||
switch self {
|
||||
case .double(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var boolValue: Bool? {
|
||||
switch self {
|
||||
case .bool(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var arrayValue: [JSONValue]? {
|
||||
if case let .array(value) = self {
|
||||
return value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var dictionaryValue: [String: JSONValue]? {
|
||||
if case let .dictionary(value) = self {
|
||||
return value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} subscript(key: String) -> JSONValue? {
|
||||
return dictionaryValue?[key]
|
||||
}
|
||||
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} subscript(index: Int) -> JSONValue? {
|
||||
guard case let .array(array) = self, index >= 0 && index < array.count else {
|
||||
return nil
|
||||
}
|
||||
return array[index]
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(stringLiteral value: StringLiteralType) {
|
||||
self = .string(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByIntegerLiteral {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(integerLiteral value: IntegerLiteralType) {
|
||||
self = .int(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByFloatLiteral {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(floatLiteral value: FloatLiteralType) {
|
||||
self = .double(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension JSONValue: ExpressibleByBooleanLiteral {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(booleanLiteral value: BooleanLiteralType) {
|
||||
self = .bool(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByArrayLiteral {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(arrayLiteral elements: JSONValue...) {
|
||||
self = .array(elements)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByDictionaryLiteral {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(dictionaryLiteral elements: (String, JSONValue)...) {
|
||||
var dict: [String: JSONValue] = [:]
|
||||
for (key, value) in elements {
|
||||
dict[key] = value
|
||||
}
|
||||
self = .dictionary(dict)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByNilLiteral {
|
||||
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(nilLiteral: ()) {
|
||||
self = .null
|
||||
}
|
||||
}
|
@ -24,7 +24,6 @@ let package = Package(
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
.package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.7")),
|
||||
{{#useAlamofire}}
|
||||
.package(url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "5.9.1")),
|
||||
{{/useAlamofire}}
|
||||
@ -43,7 +42,7 @@ let package = Package(
|
||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||
.target(
|
||||
name: "{{projectName}}",
|
||||
dependencies: ["AnyCodable", {{#useVapor}}"Vapor", {{/useVapor}}{{#useAlamofire}}"Alamofire", {{/useAlamofire}}{{#usePromiseKit}}"PromiseKit", {{/usePromiseKit}}{{#useRxSwift}}"RxSwift"{{/useRxSwift}}],
|
||||
dependencies: [{{#useVapor}}"Vapor", {{/useVapor}}{{#useAlamofire}}"Alamofire", {{/useAlamofire}}{{#usePromiseKit}}"PromiseKit", {{/usePromiseKit}}{{#useRxSwift}}"RxSwift"{{/useRxSwift}}],
|
||||
path: "{{swiftPackagePath}}{{^swiftPackagePath}}{{#useSPMFileStructure}}Sources/{{projectName}}{{/useSPMFileStructure}}{{^useSPMFileStructure}}{{projectName}}/Classes{{/useSPMFileStructure}}{{/swiftPackagePath}}"
|
||||
),
|
||||
],
|
||||
|
@ -26,7 +26,6 @@ Pod::Spec.new do |s|
|
||||
s.documentation_url = '{{.}}'
|
||||
{{/podDocumentationURL}}
|
||||
s.source_files = '{{swiftPackagePath}}{{^swiftPackagePath}}{{#useSPMFileStructure}}Sources/{{projectName}}{{/useSPMFileStructure}}{{^useSPMFileStructure}}{{projectName}}/Classes{{/useSPMFileStructure}}{{/swiftPackagePath}}/**/*.swift'
|
||||
s.dependency 'AnyCodable-FlightSchool', '~> 0.6'
|
||||
{{#useAlamofire}}
|
||||
s.dependency 'Alamofire', '~> 5.9'
|
||||
{{/useAlamofire}}
|
||||
|
@ -11,8 +11,7 @@ targets:
|
||||
settings:
|
||||
APPLICATION_EXTENSION_API_ONLY: true
|
||||
scheme: {}
|
||||
dependencies:
|
||||
- carthage: AnyCodable{{#useAlamofire}}
|
||||
dependencies:{{#useAlamofire}}
|
||||
- carthage: Alamofire{{/useAlamofire}}{{#usePromiseKit}}
|
||||
- carthage: PromiseKit{{/usePromiseKit}}{{#useRxSwift}}
|
||||
- carthage: RxSwift{{/useRxSwift}}
|
||||
|
@ -11,10 +11,7 @@ import Foundation{{#usePromiseKit}}
|
||||
#if canImport(Combine)
|
||||
import Combine
|
||||
#endif{{/useCombine}}{{#useVapor}}
|
||||
import Vapor{{/useVapor}}
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif{{#swiftUseApiNamespace}}
|
||||
import Vapor{{/useVapor}}{{#swiftUseApiNamespace}}
|
||||
|
||||
extension {{projectName}}API {
|
||||
{{/swiftUseApiNamespace}}
|
||||
|
@ -5,10 +5,7 @@
|
||||
// https://openapi-generator.tech
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif{{#useVapor}}
|
||||
import Foundation{{#useVapor}}
|
||||
import Vapor{{/useVapor}}
|
||||
{{#swiftUseApiNamespace}}
|
||||
|
||||
|
@ -168,8 +168,8 @@ public class Swift6ClientCodegenTest {
|
||||
final DefaultCodegen codegen = new Swift6ClientCodegen();
|
||||
codegen.setModelNamePrefix("API");
|
||||
|
||||
final String result = codegen.toModelName("AnyCodable");
|
||||
Assert.assertEquals(result, "AnyCodable");
|
||||
final String result = codegen.toModelName("JSONValue");
|
||||
Assert.assertEquals(result, "JSONValue");
|
||||
}
|
||||
|
||||
@Test(description = "type from languageSpecificPrimitives should not be suffixed", enabled = true)
|
||||
@ -177,8 +177,8 @@ public class Swift6ClientCodegenTest {
|
||||
final DefaultCodegen codegen = new Swift6ClientCodegen();
|
||||
codegen.setModelNameSuffix("API");
|
||||
|
||||
final String result = codegen.toModelName("AnyCodable");
|
||||
Assert.assertEquals(result, "AnyCodable");
|
||||
final String result = codegen.toModelName("JSONValue");
|
||||
Assert.assertEquals(result, "JSONValue");
|
||||
}
|
||||
|
||||
@Test(description = "Other types should be prefixed", enabled = true)
|
||||
|
@ -16,6 +16,7 @@ PetstoreClient/Classes/OpenAPIs/CodableHelper.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Extensions.swift
|
||||
PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift
|
||||
PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift
|
||||
PetstoreClient/Classes/OpenAPIs/JSONValue.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Models.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesClass.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Models/Animal.swift
|
||||
|
@ -1,2 +1 @@
|
||||
github "Flight-School/AnyCodable" ~> 0.6
|
||||
github "Alamofire/Alamofire" ~> 5.9
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "8b2114c772cba9dfd29281c36d3097ab5d8bcb8eaf2c8fd299949087a48fd168",
|
||||
"originHash" : "6fb5b6bfc406365339fcc9d8236adab4f0b7ee38fc666a0f00b4b3b75beb7900",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "alamofire",
|
||||
@ -9,15 +9,6 @@
|
||||
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
|
||||
"version" : "5.9.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "anycodable",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/Flight-School/AnyCodable",
|
||||
"state" : {
|
||||
"revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05",
|
||||
"version" : "0.6.7"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
|
@ -19,7 +19,6 @@ let package = Package(
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
.package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.7")),
|
||||
.package(url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "5.9.1")),
|
||||
],
|
||||
targets: [
|
||||
@ -27,7 +26,7 @@ let package = Package(
|
||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||
.target(
|
||||
name: "PetstoreClient",
|
||||
dependencies: ["AnyCodable", "Alamofire", ],
|
||||
dependencies: ["Alamofire", ],
|
||||
path: "PetstoreClient/Classes"
|
||||
),
|
||||
],
|
||||
|
@ -11,6 +11,5 @@ Pod::Spec.new do |s|
|
||||
s.homepage = 'https://github.com/openapitools/openapi-generator'
|
||||
s.summary = 'PetstoreClient'
|
||||
s.source_files = 'PetstoreClient/Classes/**/*.swift'
|
||||
s.dependency 'AnyCodable-FlightSchool', '~> 0.6'
|
||||
s.dependency 'Alamofire', '~> 5.9'
|
||||
end
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class AnotherFakeAPI {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class FakeAPI {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class FakeClassnameTags123API {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class PetAPI {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class StoreAPI {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class UserAPI {
|
||||
|
||||
|
@ -8,9 +8,6 @@ import Foundation
|
||||
#if canImport(FoundationNetworking)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
extension Bool: JSONEncodable {
|
||||
func encodeToJSON(codableHelper: CodableHelper) -> Any { self }
|
||||
|
@ -0,0 +1,247 @@
|
||||
//
|
||||
// JSONValue.swift
|
||||
//
|
||||
// Generated by openapi-generator
|
||||
// https://openapi-generator.tech
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum JSONValue: Codable, Hashable {
|
||||
case string(String)
|
||||
case int(Int)
|
||||
case double(Double)
|
||||
case bool(Bool)
|
||||
case array([JSONValue])
|
||||
case dictionary([String: JSONValue])
|
||||
case null
|
||||
|
||||
// MARK: - Decoding Logic
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
|
||||
if let stringValue = try? container.decode(String.self) {
|
||||
self = .string(stringValue)
|
||||
} else if let intValue = try? container.decode(Int.self) {
|
||||
self = .int(intValue)
|
||||
} else if let doubleValue = try? container.decode(Double.self) {
|
||||
self = .double(doubleValue)
|
||||
} else if let boolValue = try? container.decode(Bool.self) {
|
||||
self = .bool(boolValue)
|
||||
} else if let arrayValue = try? container.decode([JSONValue].self) {
|
||||
self = .array(arrayValue)
|
||||
} else if let dictionaryValue = try? container.decode([String: JSONValue].self) {
|
||||
self = .dictionary(dictionaryValue)
|
||||
} else if container.decodeNil() {
|
||||
self = .null
|
||||
} else {
|
||||
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unknown JSON value")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Encoding Logic
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
|
||||
switch self {
|
||||
case .string(let value):
|
||||
try container.encode(value)
|
||||
case .int(let value):
|
||||
try container.encode(value)
|
||||
case .double(let value):
|
||||
try container.encode(value)
|
||||
case .bool(let value):
|
||||
try container.encode(value)
|
||||
case .array(let value):
|
||||
try container.encode(value)
|
||||
case .dictionary(let value):
|
||||
try container.encode(value)
|
||||
case .null:
|
||||
try container.encodeNil()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public init(_ value: String) {
|
||||
self = .string(value)
|
||||
}
|
||||
|
||||
public init(_ value: Int) {
|
||||
self = .int(value)
|
||||
}
|
||||
|
||||
public init(_ value: Double) {
|
||||
self = .double(value)
|
||||
}
|
||||
|
||||
public init(_ value: Bool) {
|
||||
self = .bool(value)
|
||||
}
|
||||
|
||||
public init(_ value: [JSONValue]) {
|
||||
self = .array(value)
|
||||
}
|
||||
|
||||
public init(_ value: [String: JSONValue]) {
|
||||
self = .dictionary(value)
|
||||
}
|
||||
|
||||
public init<T: Codable>(_ codable: T) throws {
|
||||
let encoder = JSONEncoder()
|
||||
let encodedData = try encoder.encode(codable)
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
let decodedValue = try decoder.decode(JSONValue.self, from: encodedData)
|
||||
self = decodedValue
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public var isString: Bool {
|
||||
if case .string = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isInt: Bool {
|
||||
if case .int = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isDouble: Bool {
|
||||
if case .double = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isBool: Bool {
|
||||
if case .bool = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isArray: Bool {
|
||||
if case .array = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isDictionary: Bool {
|
||||
if case .dictionary = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isNull: Bool {
|
||||
return self == .null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public var stringValue: String? {
|
||||
switch self {
|
||||
case .string(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var intValue: Int? {
|
||||
switch self {
|
||||
case .int(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var doubleValue: Double? {
|
||||
switch self {
|
||||
case .double(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var boolValue: Bool? {
|
||||
switch self {
|
||||
case .bool(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var arrayValue: [JSONValue]? {
|
||||
if case let .array(value) = self {
|
||||
return value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public var dictionaryValue: [String: JSONValue]? {
|
||||
if case let .dictionary(value) = self {
|
||||
return value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public subscript(key: String) -> JSONValue? {
|
||||
return dictionaryValue?[key]
|
||||
}
|
||||
|
||||
public subscript(index: Int) -> JSONValue? {
|
||||
guard case let .array(array) = self, index >= 0 && index < array.count else {
|
||||
return nil
|
||||
}
|
||||
return array[index]
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
|
||||
public init(stringLiteral value: StringLiteralType) {
|
||||
self = .string(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByIntegerLiteral {
|
||||
public init(integerLiteral value: IntegerLiteralType) {
|
||||
self = .int(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByFloatLiteral {
|
||||
public init(floatLiteral value: FloatLiteralType) {
|
||||
self = .double(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension JSONValue: ExpressibleByBooleanLiteral {
|
||||
public init(booleanLiteral value: BooleanLiteralType) {
|
||||
self = .bool(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByArrayLiteral {
|
||||
public init(arrayLiteral elements: JSONValue...) {
|
||||
self = .array(elements)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByDictionaryLiteral {
|
||||
public init(dictionaryLiteral elements: (String, JSONValue)...) {
|
||||
var dict: [String: JSONValue] = [:]
|
||||
for (key, value) in elements {
|
||||
dict[key] = value
|
||||
}
|
||||
self = .dictionary(dict)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByNilLiteral {
|
||||
public init(nilLiteral: ()) {
|
||||
self = .null
|
||||
}
|
||||
}
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct AdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Animal: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,8 +6,5 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public typealias AnimalFarm = [Animal]
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ApiResponse: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ArrayOfArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ArrayTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Capitalization: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Cat: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Category: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Model for testing model with \"_class\" property */
|
||||
public struct ClassModel: Codable, JSONEncodable, Hashable {
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Client: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Dog: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct EnumArrays: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public enum EnumClass: String, Codable, CaseIterable {
|
||||
case abc = "_abc"
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct EnumTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Must be named `File` for test. */
|
||||
public struct File: Codable, JSONEncodable, Hashable {
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct FileSchemaTestClass: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct FormatTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct HasOnlyReadOnly: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct List: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct MapTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Model for testing model name starting with number */
|
||||
public struct Model200Response: Codable, JSONEncodable, Hashable {
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Model for testing model name same as property name */
|
||||
public struct Name: Codable, JSONEncodable, Hashable {
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct NumberOnly: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Order: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct OuterComposite: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public enum OuterEnum: String, Codable, CaseIterable {
|
||||
case placed = "placed"
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Pet: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ReadOnlyFirst: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Model for testing reserved words */
|
||||
public struct Return: Codable, JSONEncodable, Hashable {
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct SpecialModelName: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct StringBooleanMap: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Tag: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct TypeHolderDefault: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct TypeHolderExample: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct User: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "8b2114c772cba9dfd29281c36d3097ab5d8bcb8eaf2c8fd299949087a48fd168",
|
||||
"originHash" : "6fb5b6bfc406365339fcc9d8236adab4f0b7ee38fc666a0f00b4b3b75beb7900",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "alamofire",
|
||||
@ -9,15 +9,6 @@
|
||||
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
|
||||
"version" : "5.9.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "anycodable",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/Flight-School/AnyCodable",
|
||||
"state" : {
|
||||
"revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05",
|
||||
"version" : "0.6.7"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
|
@ -12,5 +12,4 @@ targets:
|
||||
APPLICATION_EXTENSION_API_ONLY: true
|
||||
scheme: {}
|
||||
dependencies:
|
||||
- carthage: AnyCodable
|
||||
- carthage: Alamofire
|
||||
|
@ -16,6 +16,7 @@ PetstoreClient/Classes/OpenAPIs/CodableHelper.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Extensions.swift
|
||||
PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift
|
||||
PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift
|
||||
PetstoreClient/Classes/OpenAPIs/JSONValue.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Models.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesClass.swift
|
||||
PetstoreClient/Classes/OpenAPIs/Models/Animal.swift
|
||||
|
@ -1,4 +1,3 @@
|
||||
github "Flight-School/AnyCodable" ~> 0.6
|
||||
github "Alamofire/Alamofire" ~> 5.9
|
||||
github "mxcl/PromiseKit" ~> 8.1
|
||||
github "ReactiveX/RxSwift" ~> 6.7
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "99c6cc361c92d76d3f9edcf90668a78a95b742f853a66cbb1804fbcfc63a985c",
|
||||
"originHash" : "b14c4fe6a7263c50050b60f25c3f28d6b22d415d0c780c4d5a3494c6c0218ccd",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "alamofire",
|
||||
@ -10,15 +10,6 @@
|
||||
"version" : "5.9.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "anycodable",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/Flight-School/AnyCodable",
|
||||
"state" : {
|
||||
"revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05",
|
||||
"version" : "0.6.7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "promisekit",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
@ -19,7 +19,6 @@ let package = Package(
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
.package(url: "https://github.com/Flight-School/AnyCodable", .upToNextMajor(from: "0.6.7")),
|
||||
.package(url: "https://github.com/Alamofire/Alamofire", .upToNextMajor(from: "5.9.1")),
|
||||
.package(url: "https://github.com/mxcl/PromiseKit", .upToNextMajor(from: "8.1.2")),
|
||||
.package(url: "https://github.com/ReactiveX/RxSwift", .upToNextMajor(from: "6.7.1")),
|
||||
@ -29,7 +28,7 @@ let package = Package(
|
||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||
.target(
|
||||
name: "PetstoreClient",
|
||||
dependencies: ["AnyCodable", "Alamofire", "PromiseKit", "RxSwift"],
|
||||
dependencies: ["Alamofire", "PromiseKit", "RxSwift"],
|
||||
path: "PetstoreClient/Classes"
|
||||
),
|
||||
],
|
||||
|
@ -11,7 +11,6 @@ Pod::Spec.new do |s|
|
||||
s.homepage = 'https://github.com/openapitools/openapi-generator'
|
||||
s.summary = 'PetstoreClient'
|
||||
s.source_files = 'PetstoreClient/Classes/**/*.swift'
|
||||
s.dependency 'AnyCodable-FlightSchool', '~> 0.6'
|
||||
s.dependency 'Alamofire', '~> 5.9'
|
||||
s.dependency 'PromiseKit/CorePromise', '~> 8.1'
|
||||
s.dependency 'RxSwift', '~> 6.7'
|
||||
|
@ -11,9 +11,6 @@ import Foundation
|
||||
#if canImport(Combine)
|
||||
import Combine
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class AnotherFakeAPI {
|
||||
public let openAPIClient: OpenAPIClient
|
||||
|
@ -11,9 +11,6 @@ import Foundation
|
||||
#if canImport(Combine)
|
||||
import Combine
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class FakeAPI {
|
||||
public let openAPIClient: OpenAPIClient
|
||||
|
@ -11,9 +11,6 @@ import Foundation
|
||||
#if canImport(Combine)
|
||||
import Combine
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class FakeClassnameTags123API {
|
||||
public let openAPIClient: OpenAPIClient
|
||||
|
@ -11,9 +11,6 @@ import Foundation
|
||||
#if canImport(Combine)
|
||||
import Combine
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class PetAPI {
|
||||
public let openAPIClient: OpenAPIClient
|
||||
|
@ -11,9 +11,6 @@ import Foundation
|
||||
#if canImport(Combine)
|
||||
import Combine
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class StoreAPI {
|
||||
public let openAPIClient: OpenAPIClient
|
||||
|
@ -11,9 +11,6 @@ import Foundation
|
||||
#if canImport(Combine)
|
||||
import Combine
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
open class UserAPI {
|
||||
public let openAPIClient: OpenAPIClient
|
||||
|
@ -8,9 +8,6 @@ import Foundation
|
||||
#if canImport(FoundationNetworking)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
@preconcurrency import PromiseKit
|
||||
|
||||
extension Bool: JSONEncodable {
|
||||
|
@ -0,0 +1,247 @@
|
||||
//
|
||||
// JSONValue.swift
|
||||
//
|
||||
// Generated by openapi-generator
|
||||
// https://openapi-generator.tech
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum JSONValue: Codable, Hashable {
|
||||
case string(String)
|
||||
case int(Int)
|
||||
case double(Double)
|
||||
case bool(Bool)
|
||||
case array([JSONValue])
|
||||
case dictionary([String: JSONValue])
|
||||
case null
|
||||
|
||||
// MARK: - Decoding Logic
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
|
||||
if let stringValue = try? container.decode(String.self) {
|
||||
self = .string(stringValue)
|
||||
} else if let intValue = try? container.decode(Int.self) {
|
||||
self = .int(intValue)
|
||||
} else if let doubleValue = try? container.decode(Double.self) {
|
||||
self = .double(doubleValue)
|
||||
} else if let boolValue = try? container.decode(Bool.self) {
|
||||
self = .bool(boolValue)
|
||||
} else if let arrayValue = try? container.decode([JSONValue].self) {
|
||||
self = .array(arrayValue)
|
||||
} else if let dictionaryValue = try? container.decode([String: JSONValue].self) {
|
||||
self = .dictionary(dictionaryValue)
|
||||
} else if container.decodeNil() {
|
||||
self = .null
|
||||
} else {
|
||||
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unknown JSON value")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Encoding Logic
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
|
||||
switch self {
|
||||
case .string(let value):
|
||||
try container.encode(value)
|
||||
case .int(let value):
|
||||
try container.encode(value)
|
||||
case .double(let value):
|
||||
try container.encode(value)
|
||||
case .bool(let value):
|
||||
try container.encode(value)
|
||||
case .array(let value):
|
||||
try container.encode(value)
|
||||
case .dictionary(let value):
|
||||
try container.encode(value)
|
||||
case .null:
|
||||
try container.encodeNil()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public init(_ value: String) {
|
||||
self = .string(value)
|
||||
}
|
||||
|
||||
public init(_ value: Int) {
|
||||
self = .int(value)
|
||||
}
|
||||
|
||||
public init(_ value: Double) {
|
||||
self = .double(value)
|
||||
}
|
||||
|
||||
public init(_ value: Bool) {
|
||||
self = .bool(value)
|
||||
}
|
||||
|
||||
public init(_ value: [JSONValue]) {
|
||||
self = .array(value)
|
||||
}
|
||||
|
||||
public init(_ value: [String: JSONValue]) {
|
||||
self = .dictionary(value)
|
||||
}
|
||||
|
||||
public init<T: Codable>(_ codable: T) throws {
|
||||
let encoder = JSONEncoder()
|
||||
let encodedData = try encoder.encode(codable)
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
let decodedValue = try decoder.decode(JSONValue.self, from: encodedData)
|
||||
self = decodedValue
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public var isString: Bool {
|
||||
if case .string = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isInt: Bool {
|
||||
if case .int = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isDouble: Bool {
|
||||
if case .double = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isBool: Bool {
|
||||
if case .bool = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isArray: Bool {
|
||||
if case .array = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isDictionary: Bool {
|
||||
if case .dictionary = self { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
public var isNull: Bool {
|
||||
return self == .null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public var stringValue: String? {
|
||||
switch self {
|
||||
case .string(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var intValue: Int? {
|
||||
switch self {
|
||||
case .int(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var doubleValue: Double? {
|
||||
switch self {
|
||||
case .double(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var boolValue: Bool? {
|
||||
switch self {
|
||||
case .bool(let value):
|
||||
return value
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var arrayValue: [JSONValue]? {
|
||||
if case let .array(value) = self {
|
||||
return value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public var dictionaryValue: [String: JSONValue]? {
|
||||
if case let .dictionary(value) = self {
|
||||
return value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue {
|
||||
public subscript(key: String) -> JSONValue? {
|
||||
return dictionaryValue?[key]
|
||||
}
|
||||
|
||||
public subscript(index: Int) -> JSONValue? {
|
||||
guard case let .array(array) = self, index >= 0 && index < array.count else {
|
||||
return nil
|
||||
}
|
||||
return array[index]
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
|
||||
public init(stringLiteral value: StringLiteralType) {
|
||||
self = .string(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByIntegerLiteral {
|
||||
public init(integerLiteral value: IntegerLiteralType) {
|
||||
self = .int(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByFloatLiteral {
|
||||
public init(floatLiteral value: FloatLiteralType) {
|
||||
self = .double(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension JSONValue: ExpressibleByBooleanLiteral {
|
||||
public init(booleanLiteral value: BooleanLiteralType) {
|
||||
self = .bool(value)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByArrayLiteral {
|
||||
public init(arrayLiteral elements: JSONValue...) {
|
||||
self = .array(elements)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByDictionaryLiteral {
|
||||
public init(dictionaryLiteral elements: (String, JSONValue)...) {
|
||||
var dict: [String: JSONValue] = [:]
|
||||
for (key, value) in elements {
|
||||
dict[key] = value
|
||||
}
|
||||
self = .dictionary(dict)
|
||||
}
|
||||
}
|
||||
|
||||
extension JSONValue: ExpressibleByNilLiteral {
|
||||
public init(nilLiteral: ()) {
|
||||
self = .null
|
||||
}
|
||||
}
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct AdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Animal: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ApiResponse: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ArrayOfArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct ArrayTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Capitalization: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Cat: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Category: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Model for testing model with \"_class\" property */
|
||||
public struct ClassModel: Codable, JSONEncodable, Hashable {
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Client: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct Dog: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct EnumArrays: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public enum EnumClass: String, Codable, CaseIterable {
|
||||
case abc = "_abc"
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct EnumTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Must be named `File` for test. */
|
||||
public struct File: Codable, JSONEncodable, Hashable {
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct FileSchemaTestClass: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct FormatTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct HasOnlyReadOnly: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct List: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct MapTest: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
|
||||
|
||||
|
@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
#if canImport(AnyCodable)
|
||||
import AnyCodable
|
||||
#endif
|
||||
|
||||
/** Model for testing model name starting with number */
|
||||
public struct Model200Response: Codable, JSONEncodable, Hashable {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user