Skip to content

Commit

Permalink
Add path components tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Jan 31, 2020
1 parent c3a22f1 commit d9f6085
Show file tree
Hide file tree
Showing 4 changed files with 448 additions and 49 deletions.
44 changes: 2 additions & 42 deletions Sources/OpenAPIKit/Path Item/PathItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,7 @@ extension OpenAPI {
trace = op
}

public typealias Map = OrderedDictionary<PathComponents, Either<JSONReference<Components, PathItem>, PathItem>>
}
}

extension Either where A == JSONReference<OpenAPI.Components, OpenAPI.PathItem>, B == OpenAPI.PathItem {
public static func pathItem(_ pathItem: OpenAPI.PathItem) -> Self {
return .b(pathItem)
}

public static func pathItem(summary: String? = nil,
description: String? = nil,
servers: [OpenAPI.Server]? = nil,
parameters: OpenAPI.PathItem.Parameter.Array = [],
get: OpenAPI.PathItem.Operation? = nil,
put: OpenAPI.PathItem.Operation? = nil,
post: OpenAPI.PathItem.Operation? = nil,
delete: OpenAPI.PathItem.Operation? = nil,
options: OpenAPI.PathItem.Operation? = nil,
head: OpenAPI.PathItem.Operation? = nil,
patch: OpenAPI.PathItem.Operation? = nil,
trace: OpenAPI.PathItem.Operation? = nil) -> Self {
return .b(
OpenAPI.PathItem(
summary: summary,
description: description,
servers: servers,
parameters: parameters,
get: get,
put: put,
post: post,
delete: delete,
options: options,
head: head,
patch: patch,
trace: trace
)
)
}

public static func pathItem(reference: JSONReference<OpenAPI.Components, OpenAPI.PathItem>) -> Self {
return .a(reference)
public typealias Map = OrderedDictionary<PathComponents, PathItem>
}
}

Expand Down Expand Up @@ -224,7 +184,7 @@ extension OpenAPI.PathComponents: Decodable {

let rawValue = try container.decode(String.self)

components = rawValue.split(separator: "/").map(String.init)
self.init(rawValue: rawValue)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenAPIKitTests/DeclarativeEaseOfUseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class DeclarativeEaseOfUseTests: XCTestCase {
)
],
paths: [
"/test/api/endpoint/{param}": .pathItem(
"/test/api/endpoint/{param}": .init(
summary: "Test Endpoint",
description: "Test Endpoint description",
parameters: [
Expand Down Expand Up @@ -267,7 +267,7 @@ final class DeclarativeEaseOfUseTests: XCTestCase {
info: apiInfo,
servers: [server],
paths: [
"/test/api/endpoint/{param}": .pathItem(testRoute)
"/test/api/endpoint/{param}": testRoute
],
components: components,
security: [],
Expand Down
6 changes: 3 additions & 3 deletions Tests/OpenAPIKitTests/DocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class DocumentTests: XCTestCase {
.init(url: URL(string: "https://google.com")!)
],
paths: [
"/hi/there": .pathItem(
"/hi/there": .init(
parameters: [],
get: .init(
tags: "hi",
Expand Down Expand Up @@ -278,7 +278,7 @@ extension DocumentTests {
let document = OpenAPI.Document(
info: .init(title: "API", version: "1.0"),
servers: [],
paths: ["test": .pathItem(summary: "hi")],
paths: ["test": .init(summary: "hi")],
components: .noComponents
)
let encodedDocument = try testStringFromEncoding(of: document)
Expand Down Expand Up @@ -325,7 +325,7 @@ extension DocumentTests {
OpenAPI.Document(
info: .init(title: "API", version: "1.0"),
servers: [],
paths: ["test": .pathItem(summary: "hi")],
paths: ["test": .init(summary: "hi")],
components: .noComponents
)
)
Expand Down
Loading

0 comments on commit d9f6085

Please sign in to comment.