diff --git a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift index 510db702..2bebc6fd 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift @@ -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 {