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

fix bug where headers were not allowed to define explode when decoding #301

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions Sources/OpenAPIKit/Header/Header.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ extension OpenAPI.Header {

// the following are parsed as part of Schema
case style
case explode
case allowReserved
case example
case examples
Expand All @@ -184,6 +185,7 @@ extension OpenAPI.Header {
.content,
.schema,
.style,
.explode,
.allowReserved,
.example,
.examples
Expand All @@ -208,6 +210,8 @@ extension OpenAPI.Header {
self = .schema
case "style":
self = .style
case "explode":
self = .explode
case "allowReserved":
self = .allowReserved
case "example":
Expand All @@ -233,6 +237,8 @@ extension OpenAPI.Header {
return "schema"
case .style:
return "style"
case .explode:
return "explode"
case .allowReserved:
return "allowReserved"
case .example:
Expand Down
61 changes: 61 additions & 0 deletions Tests/OpenAPIKitTests/Header/HeaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,67 @@ extension HeaderTests {
)
}

func test_header_withStyleAndExplode_encode() throws {
let header = OpenAPI.Header(
schema: .init(
.array(items: .string),
style: .form,
explode: false
),
required: true
)

let encodedHeader = try orderUnstableTestStringFromEncoding(of: header)

assertJSONEquivalent(
encodedHeader,
"""
{
"explode" : false,
"required" : true,
"schema" : {
"items" : {
"type" : "string"
},
"type" : "array"
},
"style" : "form"
}
"""
)
}

func test_header_withStyleAndExplode_decode() throws {
let headerData =
"""
{
"explode" : false,
"required" : true,
"schema" : {
"items" : {
"type" : "string"
},
"type" : "array"
},
"style" : "form"
}
""".data(using: .utf8)!

let header = try orderUnstableDecode(OpenAPI.Header.self, from: headerData)

XCTAssertEqual(
header,
OpenAPI.Header(
schema: .init(
.array(items: .string),
style: .form,
explode: false
),
required: true
)
)
}

func test_header_errorForBothContentAndSchema_decode() {
let headerData =
"""
Expand Down