From 2e7cfc0266835f0fab24de1e22619df0b3e285fc Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Fri, 1 Feb 2019 21:33:55 -0800 Subject: [PATCH 1/3] Add schema to parameter --- Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift | 3 ++- Sources/Swiftgger/OpenAPIModel/OpenAPIParameter.swift | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift b/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift index ff114b1..c87ce1b 100644 --- a/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift +++ b/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift @@ -31,7 +31,8 @@ class OpenAPIParametersBuilder { description: apiParameter.description, required: apiParameter.required, deprecated: apiParameter.deprecated, - allowEmptyValue: apiParameter.allowEmptyValue + allowEmptyValue: apiParameter.allowEmptyValue, + schema: OpenAPISchema(type: "string") ) openApiParameters.append(openAPIParameter) diff --git a/Sources/Swiftgger/OpenAPIModel/OpenAPIParameter.swift b/Sources/Swiftgger/OpenAPIModel/OpenAPIParameter.swift index 6210f95..a1346ee 100644 --- a/Sources/Swiftgger/OpenAPIModel/OpenAPIParameter.swift +++ b/Sources/Swiftgger/OpenAPIModel/OpenAPIParameter.swift @@ -20,6 +20,7 @@ public class OpenAPIParameter: Encodable { public private(set) var required: Bool = false public private(set) var deprecated: Bool = false public private(set) var allowEmptyValue: Bool = false + public private(set) var schema: OpenAPISchema? init(ref: String) { self.ref = ref @@ -31,7 +32,8 @@ public class OpenAPIParameter: Encodable { description: String? = nil, required: Bool = false, deprecated: Bool = false, - allowEmptyValue: Bool = false + allowEmptyValue: Bool = false, + schema: OpenAPISchema ) { self.name = name self.parameterLocation = parameterLocation @@ -39,6 +41,7 @@ public class OpenAPIParameter: Encodable { self.required = required self.deprecated = deprecated self.allowEmptyValue = allowEmptyValue + self.schema = schema } private enum CodingKeys: String, CodingKey { @@ -49,5 +52,6 @@ public class OpenAPIParameter: Encodable { case required case deprecated case allowEmptyValue + case schema } } From 29299c0e50d3d025412b38f2834d16b3c4d6d429 Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Sat, 2 Feb 2019 14:35:16 -0800 Subject: [PATCH 2/3] Initial support for OpenAPI Data Types --- Sources/Swiftgger/APIModel/APIParameter.swift | 5 +- .../Builder/OpenAPIParametersBuilder.swift | 2 +- .../Builder/OpenAPISchemasBuilder.swift | 33 +- Sources/Swiftgger/Common/APIDataType.swift | 26 ++ .../OpenAPIModel/OpenAPIObjectProperty.swift | 4 +- .../OpenAPIModel/OpenAPISchema.swift | 7 +- .../OpenAPIParametersBuilderTests.swift | 296 ++++++++++++++++++ .../OpenAPISchemasBuilderTests.swift | 35 ++- 8 files changed, 384 insertions(+), 24 deletions(-) create mode 100644 Sources/Swiftgger/Common/APIDataType.swift create mode 100644 Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift diff --git a/Sources/Swiftgger/APIModel/APIParameter.swift b/Sources/Swiftgger/APIModel/APIParameter.swift index 8064c59..1a5932f 100644 --- a/Sources/Swiftgger/APIModel/APIParameter.swift +++ b/Sources/Swiftgger/APIModel/APIParameter.swift @@ -15,6 +15,7 @@ public class APIParameter { var required: Bool = false var deprecated: Bool = false var allowEmptyValue: Bool = false + var dataType: APIDataType = APIDataType.string public init( name: String, @@ -22,7 +23,8 @@ public class APIParameter { description: String? = nil, required: Bool = false, deprecated: Bool = false, - allowEmptyValue: Bool = false + allowEmptyValue: Bool = false, + dataType: APIDataType = APIDataType.string ) { self.name = name self.parameterLocation = parameterLocation @@ -30,5 +32,6 @@ public class APIParameter { self.required = required self.deprecated = deprecated self.allowEmptyValue = allowEmptyValue + self.dataType = dataType } } diff --git a/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift b/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift index c87ce1b..ab26157 100644 --- a/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift +++ b/Sources/Swiftgger/Builder/OpenAPIParametersBuilder.swift @@ -32,7 +32,7 @@ class OpenAPIParametersBuilder { required: apiParameter.required, deprecated: apiParameter.deprecated, allowEmptyValue: apiParameter.allowEmptyValue, - schema: OpenAPISchema(type: "string") + schema: OpenAPISchema(type: apiParameter.dataType.type, format: apiParameter.dataType.format) ) openApiParameters.append(openAPIParameter) diff --git a/Sources/Swiftgger/Builder/OpenAPISchemasBuilder.swift b/Sources/Swiftgger/Builder/OpenAPISchemasBuilder.swift index c4bd24d..583b091 100644 --- a/Sources/Swiftgger/Builder/OpenAPISchemasBuilder.swift +++ b/Sources/Swiftgger/Builder/OpenAPISchemasBuilder.swift @@ -42,15 +42,40 @@ class OpenAPISchemasBuilder { var array: [(name: String, type: OpenAPIObjectProperty)] = [] for property in properties { - let someType = type(of: unwrap(property.value)) - let typeName = String(describing: someType) - let example = String(describing: unwrap(property.value)) - array.append((name: property.label!, type: OpenAPIObjectProperty(type: typeName.lowercased(), example: example))) + let unwrapped = unwrap(property.value) + let dataType = makeAPIDataType(fromSwiftValue: unwrapped) + let example = String(describing: unwrapped) + let objectProperty = OpenAPIObjectProperty(type: dataType.type, format: dataType.format, example: example) + array.append((name: property.label ?? "", type: objectProperty)) } return array } + /// Infer OpenAPI Data Type from Swift value type + /// (nested types or collections not supported at the moment) + /// + /// - Parameter value: Swift property value to analyze + /// - Returns: Most appropriate OpenAPI Data Type + private func makeAPIDataType(fromSwiftValue value: Any) -> APIDataType { + switch value { + case is Int32: + return .int32 + case is Int: + return .int64 + case is Float: + return .float + case is Double: + return .double + case is Bool: + return .boolean + case is Date: + return .dateTime + default: + return .string + } + } + private func getRequiredProperties(properties: Mirror.Children) -> [String] { var array: [String] = [] diff --git a/Sources/Swiftgger/Common/APIDataType.swift b/Sources/Swiftgger/Common/APIDataType.swift new file mode 100644 index 0000000..e4c82e9 --- /dev/null +++ b/Sources/Swiftgger/Common/APIDataType.swift @@ -0,0 +1,26 @@ +// +// APIDataType.swift +// Swiftgger +// +// Created by Eneko Alonso on 2/2/19. +// + +import Foundation + +/// OpenAPI Data Types as specified in https://swagger.io/specification/#dataTypes +public struct APIDataType { + let type: String + let format: String? + + public static let int32 = APIDataType(type: "integer", format: "int32") + public static let int64 = APIDataType(type: "integer", format: "int64") + public static let float = APIDataType(type: "number", format: "float") + public static let double = APIDataType(type: "number", format: "double") + public static let string = APIDataType(type: "string", format: nil) + public static let byte = APIDataType(type: "string", format: "byte") + public static let binary = APIDataType(type: "string", format: "binary") + public static let boolean = APIDataType(type: "boolean", format: nil) + public static let date = APIDataType(type: "string", format: "date") + public static let dateTime = APIDataType(type: "string", format: "date-time") + public static let password = APIDataType(type: "string", format: "password") +} diff --git a/Sources/Swiftgger/OpenAPIModel/OpenAPIObjectProperty.swift b/Sources/Swiftgger/OpenAPIModel/OpenAPIObjectProperty.swift index d3919b2..5e3c57b 100644 --- a/Sources/Swiftgger/OpenAPIModel/OpenAPIObjectProperty.swift +++ b/Sources/Swiftgger/OpenAPIModel/OpenAPIObjectProperty.swift @@ -11,10 +11,12 @@ import Foundation public class OpenAPIObjectProperty: Encodable { public private(set) var type: String + public private(set) var format: String? public private(set) var example: String? - init(type: String, example: String?) { + init(type: String, format: String?, example: String?) { self.type = type + self.format = format self.example = example } } diff --git a/Sources/Swiftgger/OpenAPIModel/OpenAPISchema.swift b/Sources/Swiftgger/OpenAPIModel/OpenAPISchema.swift index a2486b9..e377608 100644 --- a/Sources/Swiftgger/OpenAPIModel/OpenAPISchema.swift +++ b/Sources/Swiftgger/OpenAPIModel/OpenAPISchema.swift @@ -12,6 +12,7 @@ public class OpenAPISchema: Encodable { public private(set) var ref: String? public private(set) var type: String? + public private(set) var format: String? public private(set) var items: OpenAPISchema? public private(set) var required: [String]? public private(set) var properties: [String: OpenAPIObjectProperty]? @@ -20,8 +21,11 @@ public class OpenAPISchema: Encodable { self.ref = ref } - init(type: String? = nil, items: OpenAPISchema? = nil, required: [String]? = nil, properties: [(name: String, type: OpenAPIObjectProperty)]? = nil) { + init(type: String? = nil, format: String? = nil, + items: OpenAPISchema? = nil, required: [String]? = nil, + properties: [(name: String, type: OpenAPIObjectProperty)]? = nil) { self.type = type + self.format = format self.items = items self.required = required @@ -36,6 +40,7 @@ public class OpenAPISchema: Encodable { private enum CodingKeys: String, CodingKey { case ref = "$ref" case type + case format case items case required case properties diff --git a/Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift b/Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift new file mode 100644 index 0000000..afffa60 --- /dev/null +++ b/Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift @@ -0,0 +1,296 @@ +// +// OpenAPIParametersBuilderTests.swift +// SwiftggerTests +// +// Created by Eneko Alonso on 2/2/19. +// + +import XCTest +@testable import Swiftgger + +/** + Tests for paths components in OpenAPI standard (/paths). + + ``` + "paths": { + "/animals/{animalId}": { + "get": { + "summary": "Returns a pet by Id", + "description": "Returns a pet by Id from the system that the user has access to", + "parameters": [ + { + "schema" : { + "type" : "string" + }, + "in" : "path", + "allowEmptyValue" : false, + "deprecated" : false, + "description" : "Pet Id", + "required" : true, + "name" : "animalId" + } + ], + "responses": { + "200": { + "description": "A list of pets.", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/pet" + } + } + } + } + } + } + }, + "post": { + "summary": "Update an existing pet", + "description": "Update an existing pet in the system", + "parameters": [ + { + "schema" : { + "type" : "string" + }, + "in" : "path", + "allowEmptyValue" : false, + "deprecated" : false, + "description" : "Pet Id", + "required" : true, + "name" : "animalId" + } + ], + "requestBody": { + "description": "A pet.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/pet" + } + } + } + } + "responses": { + "200": { + "description": "A pet." + } + } + } + } + } + ``` + */ +class OpenAPIParametersBuilderTests: XCTestCase { + + func testParameterShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId") + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertNotNil(openAPIDocument.paths["/animals"]?.get?.parameters?.first, "Parameter should be added to the tree.") + } + + func testParameterNameShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId") + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual("animalId", openAPIDocument.paths["/animals"]?.get?.parameters?.first?.name) + } + + func testParameterRequiredShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId", required: true) + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual(true, openAPIDocument.paths["/animals"]?.get?.parameters?.first?.required) + } + + func testParameterDescriptionShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId", description: "Animal ID") + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual("Animal ID", openAPIDocument.paths["/animals"]?.get?.parameters?.first?.description) + } + + func testParameterLocationShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId", parameterLocation: .path) + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual(.path, openAPIDocument.paths["/animals"]?.get?.parameters?.first?.parameterLocation) + } + + func testParameterEmptyValueShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId", allowEmptyValue: true) + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual(true, openAPIDocument.paths["/animals"]?.get?.parameters?.first?.allowEmptyValue) + } + + func testParameterDeprecationShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId", deprecated: true) + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual(true, openAPIDocument.paths["/animals"]?.get?.parameters?.first?.deprecated) + } + + func testParameterSchemaTypeShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId") + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual("string", openAPIDocument.paths["/animals"]?.get?.parameters?.first?.schema?.type) + } + + func testParameterSchemaFormatShouldBeAddedToOpenAPIDocument() { + + // Arrange. + let openAPIBuilder = OpenAPIBuilder( + title: "Title", + version: "1.0.0", + description: "Description" + ) + .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ + APIAction(method: .get, route: "/animals", summary: "Action summary", + description: "Action description", parameters: [ + APIParameter(name: "animalId", dataType: .int64) + ]) + ])) + + // Act. + let openAPIDocument = openAPIBuilder.built() + + // Assert. + XCTAssertEqual("int64", openAPIDocument.paths["/animals"]?.get?.parameters?.first?.schema?.format) + } + + static var allTests = [ + ("testParameterShouldBeAddedToOpenAPIDocument", testParameterShouldBeAddedToOpenAPIDocument), + ("testParameterNameShouldBeAddedToOpenAPIDocument", testParameterNameShouldBeAddedToOpenAPIDocument), + ("testParameterRequiredShouldBeAddedToOpenAPIDocument", testParameterRequiredShouldBeAddedToOpenAPIDocument), + ("testParameterDescriptionShouldBeAddedToOpenAPIDocument", testParameterDescriptionShouldBeAddedToOpenAPIDocument), + ("testParameterLocationShouldBeAddedToOpenAPIDocument", testParameterLocationShouldBeAddedToOpenAPIDocument), + ("testParameterEmptyValueShouldBeAddedToOpenAPIDocument", testParameterEmptyValueShouldBeAddedToOpenAPIDocument), + ("testParameterDeprecationShouldBeAddedToOpenAPIDocument", testParameterDeprecationShouldBeAddedToOpenAPIDocument), + ("testParameterSchemaTypeShouldBeAddedToOpenAPIDocument", testParameterSchemaTypeShouldBeAddedToOpenAPIDocument), + ("testParameterSchemaFormatShouldBeAddedToOpenAPIDocument", testParameterSchemaFormatShouldBeAddedToOpenAPIDocument) + ] +} diff --git a/Tests/SwiftggerTests/OpenAPISchemasBuilderTests.swift b/Tests/SwiftggerTests/OpenAPISchemasBuilderTests.swift index 1db0934..2a257a1 100644 --- a/Tests/SwiftggerTests/OpenAPISchemasBuilderTests.swift +++ b/Tests/SwiftggerTests/OpenAPISchemasBuilderTests.swift @@ -38,7 +38,8 @@ struct Spaceship { "type": "object", "properties": { "age": { - "type": "int", + "type": "integer", + "format": "int64" }, "name": { "type": "string" @@ -74,7 +75,7 @@ class OpenAPISchemasBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssertNotNil(openAPIDocument.components?.schemas!["Vehicle"], "Schema name not exists") + XCTAssertNotNil(openAPIDocument.components?.schemas?["Vehicle"], "Schema name not exists") } func testSchemaTypeShouldBeTranslatedToOpenAPIDocument() { @@ -93,7 +94,7 @@ class OpenAPISchemasBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssertEqual("object", openAPIDocument.components?.schemas!["Vehicle"]?.type) + XCTAssertEqual("object", openAPIDocument.components?.schemas?["Vehicle"]?.type) } func testSchemaStringPropertyShouldBeTranslatedToOpenAPIDocument() { @@ -112,9 +113,9 @@ class OpenAPISchemasBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssertNotNil(openAPIDocument.components?.schemas!["Vehicle"]?.properties!["name"], "String property not exists in schema") - XCTAssertEqual("string", openAPIDocument.components?.schemas!["Vehicle"]?.properties!["name"]?.type) - XCTAssertEqual("Ford", openAPIDocument.components?.schemas!["Vehicle"]?.properties!["name"]?.example) + XCTAssertNotNil(openAPIDocument.components?.schemas?["Vehicle"]?.properties?["name"], "String property not exists in schema") + XCTAssertEqual("string", openAPIDocument.components?.schemas?["Vehicle"]?.properties?["name"]?.type) + XCTAssertEqual("Ford", openAPIDocument.components?.schemas?["Vehicle"]?.properties?["name"]?.example) } func testSchemaIntegerPropertyShouldBeTranslatedToOpenAPIDocument() { @@ -133,9 +134,10 @@ class OpenAPISchemasBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssertNotNil(openAPIDocument.components?.schemas!["Vehicle"]?.properties!["age"], "Integer property not exists in schema") - XCTAssertEqual("int", openAPIDocument.components?.schemas!["Vehicle"]?.properties!["age"]?.type) - XCTAssertEqual("21", openAPIDocument.components?.schemas!["Vehicle"]?.properties!["age"]?.example) + XCTAssertNotNil(openAPIDocument.components?.schemas?["Vehicle"]?.properties?["age"], "Integer property not exists in schema") + XCTAssertEqual("integer", openAPIDocument.components?.schemas?["Vehicle"]?.properties?["age"]?.type) + XCTAssertEqual("int64", openAPIDocument.components?.schemas?["Vehicle"]?.properties?["age"]?.format) + XCTAssertEqual("21", openAPIDocument.components?.schemas?["Vehicle"]?.properties?["age"]?.example) } func testSchemaRequiredFieldsShouldBeTranslatedToOpenAPIDocument() { @@ -154,7 +156,7 @@ class OpenAPISchemasBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssert(openAPIDocument.components?.schemas!["Vehicle"]?.required?.contains("name") == true, "Required property not exists in schema") + XCTAssert(openAPIDocument.components?.schemas?["Vehicle"]?.required?.contains("name") == true, "Required property not exists in schema") } func testSchemaNotRequiredFieldsShouldNotBeTranslatedToOpenAPIDocument() { @@ -173,7 +175,7 @@ class OpenAPISchemasBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssert(openAPIDocument.components?.schemas!["Vehicle"]?.required?.contains("age") == false, "Not required property exists in schema") + XCTAssert(openAPIDocument.components?.schemas?["Vehicle"]?.required?.contains("age") == false, "Not required property exists in schema") } func testSchemaStructTypeShouldBeTranslatedToOpenAPIDocument() { @@ -192,11 +194,12 @@ class OpenAPISchemasBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssertNotNil(openAPIDocument.components?.schemas!["Spaceship"], "Schema name not exists") - XCTAssertEqual("string", openAPIDocument.components?.schemas!["Spaceship"]?.properties!["name"]?.type) - XCTAssertEqual("Star Trek", openAPIDocument.components?.schemas!["Spaceship"]?.properties!["name"]?.example) - XCTAssertEqual("double", openAPIDocument.components?.schemas!["Spaceship"]?.properties!["speed"]?.type) - XCTAssertEqual("923211.0", openAPIDocument.components?.schemas!["Spaceship"]?.properties!["speed"]?.example) + XCTAssertNotNil(openAPIDocument.components?.schemas?["Spaceship"], "Schema name not exists") + XCTAssertEqual("string", openAPIDocument.components?.schemas?["Spaceship"]?.properties?["name"]?.type) + XCTAssertEqual("Star Trek", openAPIDocument.components?.schemas?["Spaceship"]?.properties?["name"]?.example) + XCTAssertEqual("number", openAPIDocument.components?.schemas?["Spaceship"]?.properties?["speed"]?.type) + XCTAssertEqual("double", openAPIDocument.components?.schemas?["Spaceship"]?.properties?["speed"]?.format) + XCTAssertEqual("923211.0", openAPIDocument.components?.schemas?["Spaceship"]?.properties?["speed"]?.example) } static var allTests = [ From 3f436677602555c790290e36279e535846e3f520 Mon Sep 17 00:00:00 2001 From: Eneko Alonso Date: Sat, 2 Feb 2019 15:23:11 -0800 Subject: [PATCH 3/3] Fix test --- Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift b/Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift index afffa60..7b1194f 100644 --- a/Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift +++ b/Tests/SwiftggerTests/OpenAPIParametersBuilderTests.swift @@ -183,7 +183,7 @@ class OpenAPIParametersBuilderTests: XCTestCase { .add(APIController(name: "ControllerName", description: "ControllerDescription", actions: [ APIAction(method: .get, route: "/animals", summary: "Action summary", description: "Action description", parameters: [ - APIParameter(name: "animalId", parameterLocation: .path) + APIParameter(name: "animalId", parameterLocation: .query) ]) ])) @@ -191,7 +191,7 @@ class OpenAPIParametersBuilderTests: XCTestCase { let openAPIDocument = openAPIBuilder.built() // Assert. - XCTAssertEqual(.path, openAPIDocument.paths["/animals"]?.get?.parameters?.first?.parameterLocation) + XCTAssertEqual(APILocation.query, openAPIDocument.paths["/animals"]?.get?.parameters?.first?.parameterLocation) } func testParameterEmptyValueShouldBeAddedToOpenAPIDocument() {