Skip to content

Commit

Permalink
Merge pull request #301 from mattpolzin/bugfix/300/explode-the-header
Browse files Browse the repository at this point in the history
fix bug where headers were not allowed to define explode when decoding
  • Loading branch information
mattpolzin authored Aug 26, 2023
2 parents e9c50c9 + adcc199 commit 0f712cc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
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

0 comments on commit 0f712cc

Please sign in to comment.