Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bugfix/300/explode-th…
Browse files Browse the repository at this point in the history
…e-header-2
  • Loading branch information
mattpolzin committed Aug 26, 2023
2 parents 97618fa + 0f712cc commit a04ef3f
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 @@ -186,6 +186,7 @@ extension OpenAPI.Header {

// the following are parsed as part of Schema
case style
case explode
case allowReserved
case example
case examples
Expand All @@ -200,6 +201,7 @@ extension OpenAPI.Header {
.content,
.schema,
.style,
.explode,
.allowReserved,
.example,
.examples
Expand All @@ -224,6 +226,8 @@ extension OpenAPI.Header {
self = .schema
case "style":
self = .style
case "explode":
self = .explode
case "allowReserved":
self = .allowReserved
case "example":
Expand All @@ -249,6 +253,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 @@ -547,6 +547,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 a04ef3f

Please sign in to comment.