Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for responses with examples #166

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,85 @@ final class SnippetBasedReferenceTests: XCTestCase {
)
)
}

func testResponseWithExampleWithSummaryAndValue() throws {
try self.assertResponsesTranslation(
"""
responses:
MyResponse:
description: Some response
content:
application/json:
schema:
type: string
examples:
application/json:
summary: "a hello response"
value: "hello"
""",
"""
public enum Responses {
public struct MyResponse: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable { public init() {} }
public var headers: Components.Responses.MyResponse.Headers
@frozen public enum Body: Sendable, Equatable, Hashable {
case json(Swift.String)
}
public var body: Components.Responses.MyResponse.Body
public init(
headers: Components.Responses.MyResponse.Headers = .init(),
body: Components.Responses.MyResponse.Body
) {
self.headers = headers
self.body = body
}
}
}
"""
)
}

func testResponseWithExampleWithOnlyValue() throws {
// This test currently throws because the parsing of ExampleObject is too strict:
// https://github.com/mattpolzin/OpenAPIKit/issues/286.
XCTAssertThrowsError(
try self.assertResponsesTranslation(
"""
responses:
MyResponse:
description: Some response
content:
application/json:
schema:
type: string
examples:
application/json:
summary: "a hello response"
""",
"""
public enum Responses {
public struct MyResponse: Sendable, Equatable, Hashable {
public struct Headers: Sendable, Equatable, Hashable { public init() {} }
public var headers: Components.Responses.MyResponse.Headers
@frozen public enum Body: Sendable, Equatable, Hashable {
case json(Swift.String)
}
public var body: Components.Responses.MyResponse.Body
public init(
headers: Components.Responses.MyResponse.Headers = .init(),
body: Components.Responses.MyResponse.Body
) {
self.headers = headers
self.body = body
}
}
}
"""
)
) { error in
XCTAssert(error is DecodingError)
}
}
}

extension SnippetBasedReferenceTests {
Expand Down