Make moduleObject.mustache confirms to JSONEncodable. (#11202)

* Make moduleObject.mustache confirms to JSONEncodable.

* Regenerate samples

* Don't confirm JSONEncodable when using Vapor.

* Use CodableHelper.jsonEncoder

* Encode `Data` using `encodeToJSON()`

* Update sample

* Don't extend JSONEncodable when using Vapor.

* Add JSONEncodable in moduleEnum, moduleInlineEnumDeclaration, and modelOneOf

* Update sample

* Remove line break.

* Update sample

* Revert "Update sample"

This reverts commit 6ec206b506a5402a225184bd8e80f5e654f426f8.

* Don't confirm JSONEncodable when enum confirms RawRepresentable.

* Update sample

* Add space before {

* Update sample

* Don't confirm JSONEncodable when enum confirms RawRepresentable.
This commit is contained in:
Akira MATSUDA 2022-01-10 00:47:03 +09:00 committed by GitHub
parent 1343024786
commit febf49662a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
521 changed files with 709 additions and 505 deletions

View File

@ -65,6 +65,16 @@ extension Date: JSONEncodable {
func encodeToJSON() -> Any { func encodeToJSON() -> Any {
return CodableHelper.dateFormatter.string(from: self) return CodableHelper.dateFormatter.string(from: self)
} }
}
extension JSONEncodable where Self: Encodable {
func encodeToJSON() -> Any {
let encoder = CodableHelper.jsonEncoder
guard let data = try? encoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.encodeToJSON()
}
}{{/useVapor}}{{#generateModelAdditionalProperties}} }{{/useVapor}}{{#generateModelAdditionalProperties}}
extension String: CodingKey { extension String: CodingKey {

View File

@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} { {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, JSONEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} {
{{#allowableValues}} {{#allowableValues}}
{{#enumVars}} {{#enumVars}}
case {{{name}}} = {{{value}}} case {{{name}}} = {{{value}}}

View File

@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} { {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isContainer}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, JSONEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/isContainer}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} {
{{#allowableValues}} {{#allowableValues}}
{{#enumVars}} {{#enumVars}}
case {{{name}}} = {{{value}}} case {{{name}}} = {{{value}}}

View File

@ -1,5 +1,5 @@
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} { {{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable, JSONEncodable{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} {
{{/objcCompatible}}{{#objcCompatible}}@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable { {{/objcCompatible}}{{#objcCompatible}}@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable, JSONEncodable {
{{/objcCompatible}} {{/objcCompatible}}
{{#allVars}} {{#allVars}}

View File

@ -1,4 +1,4 @@
public enum {{classname}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} { public enum {{classname}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable, JSONEncodable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
{{#oneOf}} {{#oneOf}}
case type{{.}}({{.}}) case type{{.}}({{.}})
{{/oneOf}} {{/oneOf}}

View File

@ -0,0 +1,44 @@
openapi: 3.0.0
info:
title: test
version: '1.0'
servers:
- url: 'http://localhost:3000'
paths:
/postModel:
post:
summary: Create New User
operationId: post-user
responses:
'200':
description: User Created
content:
application/json:
schema:
$ref: '#/components/schemas/User'
examples: {}
'400':
description: Missing Required Information
description: Create a new user.
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/Request'
parameters: []
components:
schemas:
User:
title: User
type: object
description: ''
x-examples: {}
properties:
integerValue:
type: integer
Request:
title: Request
type: object
properties:
user1:
$ref: '#/components/schemas/User'

View File

@ -65,6 +65,16 @@ extension Date: JSONEncodable {
} }
} }
extension JSONEncodable where Self: Encodable {
func encodeToJSON() -> Any {
let encoder = CodableHelper.jsonEncoder
guard let data = try? encoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.encodeToJSON()
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct AdditionalPropertiesClass: Codable, Hashable { public struct AdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
public var mapString: [String: String]? public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]? public var mapMapString: [String: [String: String]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Animal: Codable, Hashable { public struct Animal: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ApiResponse: Codable, Hashable { public struct ApiResponse: Codable, JSONEncodable, Hashable {
public var code: Int? public var code: Int?
public var type: String? public var type: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayOfArrayOfNumberOnly: Codable, Hashable { public struct ArrayOfArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public var arrayArrayNumber: [[Double]]? public var arrayArrayNumber: [[Double]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayOfNumberOnly: Codable, Hashable { public struct ArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public var arrayNumber: [Double]? public var arrayNumber: [Double]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayTest: Codable, Hashable { public struct ArrayTest: Codable, JSONEncodable, Hashable {
public var arrayOfString: [String]? public var arrayOfString: [String]?
public var arrayArrayOfInteger: [[Int64]]? public var arrayArrayOfInteger: [[Int64]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Capitalization: Codable, Hashable { public struct Capitalization: Codable, JSONEncodable, Hashable {
public var smallCamel: String? public var smallCamel: String?
public var capitalCamel: String? public var capitalCamel: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Cat: Codable, Hashable { public struct Cat: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct CatAllOf: Codable, Hashable { public struct CatAllOf: Codable, JSONEncodable, Hashable {
public var declawed: Bool? public var declawed: Bool?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Category: Codable, Hashable { public struct Category: Codable, JSONEncodable, Hashable {
public var id: Int64? public var id: Int64?
public var name: String? = "default-name" public var name: String? = "default-name"

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing model with \"_class\" property */ /** Model for testing model with \"_class\" property */
public struct ClassModel: Codable, Hashable { public struct ClassModel: Codable, JSONEncodable, Hashable {
public var _class: String? public var _class: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Client: Codable, Hashable { public struct Client: Codable, JSONEncodable, Hashable {
public var client: String? public var client: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Dog: Codable, Hashable { public struct Dog: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct DogAllOf: Codable, Hashable { public struct DogAllOf: Codable, JSONEncodable, Hashable {
public var breed: String? public var breed: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct EnumArrays: Codable, Hashable { public struct EnumArrays: Codable, JSONEncodable, Hashable {
public enum JustSymbol: String, Codable, CaseIterable { public enum JustSymbol: String, Codable, CaseIterable {
case greaterThanOrEqualTo = ">=" case greaterThanOrEqualTo = ">="

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct EnumTest: Codable, Hashable { public struct EnumTest: Codable, JSONEncodable, Hashable {
public enum EnumString: String, Codable, CaseIterable { public enum EnumString: String, Codable, CaseIterable {
case upper = "UPPER" case upper = "UPPER"

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Must be named `File` for test. */ /** Must be named `File` for test. */
public struct File: Codable, Hashable { public struct File: Codable, JSONEncodable, Hashable {
/** Test capitalization */ /** Test capitalization */
public var sourceURI: String? public var sourceURI: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct FileSchemaTestClass: Codable, Hashable { public struct FileSchemaTestClass: Codable, JSONEncodable, Hashable {
public var file: File? public var file: File?
public var files: [File]? public var files: [File]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct FormatTest: Codable, Hashable { public struct FormatTest: Codable, JSONEncodable, Hashable {
public var integer: Int? public var integer: Int?
public var int32: Int? public var int32: Int?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct HasOnlyReadOnly: Codable, Hashable { public struct HasOnlyReadOnly: Codable, JSONEncodable, Hashable {
public var bar: String? public var bar: String?
public var foo: String? public var foo: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct List: Codable, Hashable { public struct List: Codable, JSONEncodable, Hashable {
public var _123list: String? public var _123list: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct MapTest: Codable, Hashable { public struct MapTest: Codable, JSONEncodable, Hashable {
public enum MapOfEnumString: String, Codable, CaseIterable { public enum MapOfEnumString: String, Codable, CaseIterable {
case upper = "UPPER" case upper = "UPPER"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, Hashable { public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
public var uuid: UUID? public var uuid: UUID?
public var dateTime: Date? public var dateTime: Date?

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing model name starting with number */ /** Model for testing model name starting with number */
public struct Model200Response: Codable, Hashable { public struct Model200Response: Codable, JSONEncodable, Hashable {
public var name: Int? public var name: Int?
public var _class: String? public var _class: String?

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing model name same as property name */ /** Model for testing model name same as property name */
public struct Name: Codable, Hashable { public struct Name: Codable, JSONEncodable, Hashable {
public var name: Int public var name: Int
public var snakeCase: NullEncodable<Int> = .encodeValue(11033) public var snakeCase: NullEncodable<Int> = .encodeValue(11033)

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct NumberOnly: Codable, Hashable { public struct NumberOnly: Codable, JSONEncodable, Hashable {
public var justNumber: Double? public var justNumber: Double?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Order: Codable, Hashable { public struct Order: Codable, JSONEncodable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case placed = "placed" case placed = "placed"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct OuterComposite: Codable, Hashable { public struct OuterComposite: Codable, JSONEncodable, Hashable {
public var myNumber: Double? public var myNumber: Double?
public var myString: String? public var myString: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Pet: Codable, Hashable { public struct Pet: Codable, JSONEncodable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ReadOnlyFirst: Codable, Hashable { public struct ReadOnlyFirst: Codable, JSONEncodable, Hashable {
public var bar: String? public var bar: String?
public var baz: String? public var baz: String?

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing reserved words */ /** Model for testing reserved words */
public struct Return: Codable, Hashable { public struct Return: Codable, JSONEncodable, Hashable {
public var _return: Int? public var _return: Int?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct SpecialModelName: Codable, Hashable { public struct SpecialModelName: Codable, JSONEncodable, Hashable {
public var specialPropertyName: Int64? public var specialPropertyName: Int64?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct StringBooleanMap: Codable, Hashable { public struct StringBooleanMap: Codable, JSONEncodable, Hashable {
public enum CodingKeys: CodingKey, CaseIterable { public enum CodingKeys: CodingKey, CaseIterable {

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Tag: Codable, Hashable { public struct Tag: Codable, JSONEncodable, Hashable {
public var id: Int64? public var id: Int64?
public var name: String? public var name: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct TypeHolderDefault: Codable, Hashable { public struct TypeHolderDefault: Codable, JSONEncodable, Hashable {
public var stringItem: String = "what" public var stringItem: String = "what"
public var numberItem: Double public var numberItem: Double

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct TypeHolderExample: Codable, Hashable { public struct TypeHolderExample: Codable, JSONEncodable, Hashable {
public var stringItem: String public var stringItem: String
public var numberItem: Double public var numberItem: Double

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct User: Codable, Hashable { public struct User: Codable, JSONEncodable, Hashable {
public var id: Int64? public var id: Int64?
public var username: String? public var username: String?

View File

@ -65,6 +65,16 @@ extension Date: JSONEncodable {
} }
} }
extension JSONEncodable where Self: Encodable {
func encodeToJSON() -> Any {
let encoder = CodableHelper.jsonEncoder
guard let data = try? encoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.encodeToJSON()
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct AdditionalPropertiesClass: Codable, Hashable { public struct AdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
public var mapString: [String: String]? public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]? public var mapMapString: [String: [String: String]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Animal: Codable, Hashable { public struct Animal: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ApiResponse: Codable, Hashable { public struct ApiResponse: Codable, JSONEncodable, Hashable {
public var code: Int? public var code: Int?
public var type: String? public var type: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayOfArrayOfNumberOnly: Codable, Hashable { public struct ArrayOfArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public var arrayArrayNumber: [[Double]]? public var arrayArrayNumber: [[Double]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayOfNumberOnly: Codable, Hashable { public struct ArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public var arrayNumber: [Double]? public var arrayNumber: [Double]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayTest: Codable, Hashable { public struct ArrayTest: Codable, JSONEncodable, Hashable {
public var arrayOfString: [String]? public var arrayOfString: [String]?
public var arrayArrayOfInteger: [[Int64]]? public var arrayArrayOfInteger: [[Int64]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Capitalization: Codable, Hashable { public struct Capitalization: Codable, JSONEncodable, Hashable {
public var smallCamel: String? public var smallCamel: String?
public var capitalCamel: String? public var capitalCamel: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Cat: Codable, Hashable { public struct Cat: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct CatAllOf: Codable, Hashable { public struct CatAllOf: Codable, JSONEncodable, Hashable {
public var declawed: Bool? public var declawed: Bool?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Category: Codable, Hashable { public struct Category: Codable, JSONEncodable, Hashable {
public var id: Int64? public var id: Int64?
public var name: String? = "default-name" public var name: String? = "default-name"

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing model with \&quot;_class\&quot; property */ /** Model for testing model with \&quot;_class\&quot; property */
public struct ClassModel: Codable, Hashable { public struct ClassModel: Codable, JSONEncodable, Hashable {
public var _class: String? public var _class: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Client: Codable, Hashable { public struct Client: Codable, JSONEncodable, Hashable {
public var client: String? public var client: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Dog: Codable, Hashable { public struct Dog: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct DogAllOf: Codable, Hashable { public struct DogAllOf: Codable, JSONEncodable, Hashable {
public var breed: String? public var breed: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct EnumArrays: Codable, Hashable { public struct EnumArrays: Codable, JSONEncodable, Hashable {
public enum JustSymbol: String, Codable, CaseIterable { public enum JustSymbol: String, Codable, CaseIterable {
case greaterThanOrEqualTo = ">=" case greaterThanOrEqualTo = ">="

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct EnumTest: Codable, Hashable { public struct EnumTest: Codable, JSONEncodable, Hashable {
public enum EnumString: String, Codable, CaseIterable { public enum EnumString: String, Codable, CaseIterable {
case upper = "UPPER" case upper = "UPPER"

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Must be named &#x60;File&#x60; for test. */ /** Must be named &#x60;File&#x60; for test. */
public struct File: Codable, Hashable { public struct File: Codable, JSONEncodable, Hashable {
/** Test capitalization */ /** Test capitalization */
public var sourceURI: String? public var sourceURI: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct FileSchemaTestClass: Codable, Hashable { public struct FileSchemaTestClass: Codable, JSONEncodable, Hashable {
public var file: File? public var file: File?
public var files: [File]? public var files: [File]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct FormatTest: Codable, Hashable { public struct FormatTest: Codable, JSONEncodable, Hashable {
public var integer: Int? public var integer: Int?
public var int32: Int? public var int32: Int?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct HasOnlyReadOnly: Codable, Hashable { public struct HasOnlyReadOnly: Codable, JSONEncodable, Hashable {
public var bar: String? public var bar: String?
public var foo: String? public var foo: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct List: Codable, Hashable { public struct List: Codable, JSONEncodable, Hashable {
public var _123list: String? public var _123list: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct MapTest: Codable, Hashable { public struct MapTest: Codable, JSONEncodable, Hashable {
public enum MapOfEnumString: String, Codable, CaseIterable { public enum MapOfEnumString: String, Codable, CaseIterable {
case upper = "UPPER" case upper = "UPPER"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, Hashable { public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
public var uuid: UUID? public var uuid: UUID?
public var dateTime: Date? public var dateTime: Date?

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing model name starting with number */ /** Model for testing model name starting with number */
public struct Model200Response: Codable, Hashable { public struct Model200Response: Codable, JSONEncodable, Hashable {
public var name: Int? public var name: Int?
public var _class: String? public var _class: String?

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing model name same as property name */ /** Model for testing model name same as property name */
public struct Name: Codable, Hashable { public struct Name: Codable, JSONEncodable, Hashable {
public var name: Int public var name: Int
public var snakeCase: NullEncodable<Int> = .encodeValue(11033) public var snakeCase: NullEncodable<Int> = .encodeValue(11033)

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct NumberOnly: Codable, Hashable { public struct NumberOnly: Codable, JSONEncodable, Hashable {
public var justNumber: Double? public var justNumber: Double?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Order: Codable, Hashable { public struct Order: Codable, JSONEncodable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case placed = "placed" case placed = "placed"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct OuterComposite: Codable, Hashable { public struct OuterComposite: Codable, JSONEncodable, Hashable {
public var myNumber: Double? public var myNumber: Double?
public var myString: String? public var myString: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Pet: Codable, Hashable { public struct Pet: Codable, JSONEncodable, Hashable {
public enum Status: String, Codable, CaseIterable { public enum Status: String, Codable, CaseIterable {
case available = "available" case available = "available"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ReadOnlyFirst: Codable, Hashable { public struct ReadOnlyFirst: Codable, JSONEncodable, Hashable {
public var bar: String? public var bar: String?
public var baz: String? public var baz: String?

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing reserved words */ /** Model for testing reserved words */
public struct Return: Codable, Hashable { public struct Return: Codable, JSONEncodable, Hashable {
public var _return: Int? public var _return: Int?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct SpecialModelName: Codable, Hashable { public struct SpecialModelName: Codable, JSONEncodable, Hashable {
public var specialPropertyName: Int64? public var specialPropertyName: Int64?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct StringBooleanMap: Codable, Hashable { public struct StringBooleanMap: Codable, JSONEncodable, Hashable {
public enum CodingKeys: CodingKey, CaseIterable { public enum CodingKeys: CodingKey, CaseIterable {

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Tag: Codable, Hashable { public struct Tag: Codable, JSONEncodable, Hashable {
public var id: Int64? public var id: Int64?
public var name: String? public var name: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct TypeHolderDefault: Codable, Hashable { public struct TypeHolderDefault: Codable, JSONEncodable, Hashable {
public var stringItem: String = "what" public var stringItem: String = "what"
public var numberItem: Double public var numberItem: Double

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct TypeHolderExample: Codable, Hashable { public struct TypeHolderExample: Codable, JSONEncodable, Hashable {
public var stringItem: String public var stringItem: String
public var numberItem: Double public var numberItem: Double

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct User: Codable, Hashable { public struct User: Codable, JSONEncodable, Hashable {
public var id: Int64? public var id: Int64?
public var username: String? public var username: String?

View File

@ -65,6 +65,16 @@ extension Date: JSONEncodable {
} }
} }
extension JSONEncodable where Self: Encodable {
func encodeToJSON() -> Any {
let encoder = CodableHelper.jsonEncoder
guard let data = try? encoder.encode(self) else {
fatalError("Could not encode to json: \(self)")
}
return data.encodeToJSON()
}
}
extension String: CodingKey { extension String: CodingKey {
public var stringValue: String { public var stringValue: String {

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct AdditionalPropertiesClass: Codable, Hashable { public struct AdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
public var mapString: [String: String]? public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]? public var mapMapString: [String: [String: String]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Animal: Codable, Hashable { public struct Animal: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ApiResponse: Codable, Hashable { public struct ApiResponse: Codable, JSONEncodable, Hashable {
public var code: Int? public var code: Int?
public var type: String? public var type: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayOfArrayOfNumberOnly: Codable, Hashable { public struct ArrayOfArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public var arrayArrayNumber: [[Double]]? public var arrayArrayNumber: [[Double]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayOfNumberOnly: Codable, Hashable { public struct ArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public var arrayNumber: [Double]? public var arrayNumber: [Double]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct ArrayTest: Codable, Hashable { public struct ArrayTest: Codable, JSONEncodable, Hashable {
public var arrayOfString: [String]? public var arrayOfString: [String]?
public var arrayArrayOfInteger: [[Int64]]? public var arrayArrayOfInteger: [[Int64]]?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Capitalization: Codable, Hashable { public struct Capitalization: Codable, JSONEncodable, Hashable {
public var smallCamel: String? public var smallCamel: String?
public var capitalCamel: String? public var capitalCamel: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Cat: Codable, Hashable { public struct Cat: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct CatAllOf: Codable, Hashable { public struct CatAllOf: Codable, JSONEncodable, Hashable {
public var declawed: Bool? public var declawed: Bool?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Category: Codable, Hashable { public struct Category: Codable, JSONEncodable, Hashable {
public var id: Int64? public var id: Int64?
public var name: String? = "default-name" public var name: String? = "default-name"

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Model for testing model with \&quot;_class\&quot; property */ /** Model for testing model with \&quot;_class\&quot; property */
public struct ClassModel: Codable, Hashable { public struct ClassModel: Codable, JSONEncodable, Hashable {
public var _class: String? public var _class: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Client: Codable, Hashable { public struct Client: Codable, JSONEncodable, Hashable {
public var client: String? public var client: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct Dog: Codable, Hashable { public struct Dog: Codable, JSONEncodable, Hashable {
public var className: String public var className: String
public var color: String? = "red" public var color: String? = "red"

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct DogAllOf: Codable, Hashable { public struct DogAllOf: Codable, JSONEncodable, Hashable {
public var breed: String? public var breed: String?

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct EnumArrays: Codable, Hashable { public struct EnumArrays: Codable, JSONEncodable, Hashable {
public enum JustSymbol: String, Codable, CaseIterable { public enum JustSymbol: String, Codable, CaseIterable {
case greaterThanOrEqualTo = ">=" case greaterThanOrEqualTo = ">="

View File

@ -10,7 +10,7 @@ import Foundation
import AnyCodable import AnyCodable
#endif #endif
public struct EnumTest: Codable, Hashable { public struct EnumTest: Codable, JSONEncodable, Hashable {
public enum EnumString: String, Codable, CaseIterable { public enum EnumString: String, Codable, CaseIterable {
case upper = "UPPER" case upper = "UPPER"

View File

@ -11,7 +11,7 @@ import AnyCodable
#endif #endif
/** Must be named &#x60;File&#x60; for test. */ /** Must be named &#x60;File&#x60; for test. */
public struct File: Codable, Hashable { public struct File: Codable, JSONEncodable, Hashable {
/** Test capitalization */ /** Test capitalization */
public var sourceURI: String? public var sourceURI: String?

Some files were not shown because too many files have changed in this diff Show More