Skip to content
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
3 changes: 2 additions & 1 deletion Sources/OpenAPIKitCore/Shared/ContentType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ extension Shared.ContentType.Builtin: RawRepresentable {
case .woff: return "font/woff"
case .woff2: return "font/woff2"
case .xml: return "application/xml"
case .yaml: return "application/x-yaml"
case .yaml: return "application/yaml"
case .zip: return "application/zip"

case .anyApplication: return "application/*"
Expand Down Expand Up @@ -359,6 +359,7 @@ extension Shared.ContentType.Builtin: RawRepresentable {
case "font/woff2": self = .woff2
case "application/xml": self = .xml
case "application/x-yaml": self = .yaml
case "application/yaml": self = .yaml
case "application/zip": self = .zip

case "application/*": self = .anyApplication
Expand Down
11 changes: 11 additions & 0 deletions Tests/OpenAPIKitCoreTests/ContentTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ final class ContentTypeTests: XCTestCase {
}
}

func test_x_yaml() {
// test that we support old x-yaml type but also prefer new official media type
let type1 = Shared.ContentType.init(rawValue: "application/yaml")
let type2 = Shared.ContentType.init(rawValue: "application/x-yaml")

XCTAssertEqual(type1?.rawValue, "application/yaml")
XCTAssertEqual(type1, .yaml)
XCTAssertEqual(type2?.rawValue, "application/yaml")
XCTAssertEqual(type2, .yaml)
}

func test_goodParam() {
let type = Shared.ContentType.init(rawValue: "text/html; charset=utf8")
XCTAssertEqual(type?.warnings.count, 0)
Expand Down