Skip to content

Commit ef352d3

Browse files
authored
Merge pull request #430 from mattpolzin/feature/423/yaml-media-type
Support and prefer new official yaml media type
2 parents 94f9f20 + 4067f83 commit ef352d3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/OpenAPIKitCore/Shared/ContentType.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ extension Shared.ContentType.Builtin: RawRepresentable {
305305
case .woff: return "font/woff"
306306
case .woff2: return "font/woff2"
307307
case .xml: return "application/xml"
308-
case .yaml: return "application/x-yaml"
308+
case .yaml: return "application/yaml"
309309
case .zip: return "application/zip"
310310

311311
case .anyApplication: return "application/*"
@@ -359,6 +359,7 @@ extension Shared.ContentType.Builtin: RawRepresentable {
359359
case "font/woff2": self = .woff2
360360
case "application/xml": self = .xml
361361
case "application/x-yaml": self = .yaml
362+
case "application/yaml": self = .yaml
362363
case "application/zip": self = .zip
363364

364365
case "application/*": self = .anyApplication

Tests/OpenAPIKitCoreTests/ContentTypeTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ final class ContentTypeTests: XCTestCase {
6666
}
6767
}
6868

69+
func test_x_yaml() {
70+
// test that we support old x-yaml type but also prefer new official media type
71+
let type1 = Shared.ContentType.init(rawValue: "application/yaml")
72+
let type2 = Shared.ContentType.init(rawValue: "application/x-yaml")
73+
74+
XCTAssertEqual(type1?.rawValue, "application/yaml")
75+
XCTAssertEqual(type1, .yaml)
76+
XCTAssertEqual(type2?.rawValue, "application/yaml")
77+
XCTAssertEqual(type2, .yaml)
78+
}
79+
6980
func test_goodParam() {
7081
let type = Shared.ContentType.init(rawValue: "text/html; charset=utf8")
7182
XCTAssertEqual(type?.warnings.count, 0)

0 commit comments

Comments
 (0)