Skip to content

Commit 4a691fa

Browse files
authored
Merge pull request #335 from mattpolzin/a-few-more-content-types
Add a few more builtin content types I was surprised to have not included already.
2 parents 2c09502 + afb7252 commit 4a691fa

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Sources/OpenAPIKitCore/Shared/ContentType.swift

+26
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,21 @@ extension Shared {
9696

9797
// convenience constructors
9898
public extension Shared.ContentType {
99+
/// AAC audio
100+
static let aac: Self = .init(.aac)
101+
/// Audio Video Interleave
102+
static let avi: Self = .init(.avi)
99103
/// Bitmap image
100104
static let bmp: Self = .init(.bmp)
101105
static let css: Self = .init(.css)
102106
/// Comma-separated values
103107
static let csv: Self = .init(.csv)
108+
static let doc: Self = .init(.doc)
109+
static let docx: Self = .init(.docx)
104110
/// URL-encoded form data. See also: `multipartForm`.
105111
static let form: Self = .init(.form)
112+
/// Graphics Interchange Format
113+
static let gif: Self = .init(.gif)
106114
static let html: Self = .init(.html)
107115
static let javascript: Self = .init(.javascript)
108116
/// JPEG image
@@ -161,13 +169,21 @@ extension Shared.ContentType {
161169
// This internal representation makes it easier to ensure that the popular
162170
// builtin types supported are fully covered in their rawValue implementation.
163171
internal enum Builtin: Codable, Equatable, Hashable {
172+
/// AAC audio
173+
case aac
174+
/// Audio Video Interleave
175+
case avi
164176
/// Bitmap image
165177
case bmp
166178
case css
167179
/// Comma-separated values
168180
case csv
181+
case doc
182+
case docx
169183
/// URL-encoded form data. See also: `multipartForm`.
170184
case form
185+
/// Graphics Interchange Format
186+
case gif
171187
case html
172188
case javascript
173189
/// JPEG image
@@ -226,10 +242,15 @@ extension Shared.ContentType {
226242
extension Shared.ContentType.Builtin: RawRepresentable {
227243
public var rawValue: String {
228244
switch self {
245+
case .aac: return "audio/aac"
246+
case .avi: return "video/x-msvideo"
229247
case .bmp: return "image/bmp"
230248
case .css: return "text/css"
231249
case .csv: return "text/csv"
250+
case .doc: return "application/msword"
251+
case .docx: return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
232252
case .form: return "application/x-www-form-urlencoded"
253+
case .gif: return "image/gif"
233254
case .html: return "text/html"
234255
case .javascript: return "application/javascript"
235256
case .jpg: return "image/jpeg"
@@ -269,10 +290,15 @@ extension Shared.ContentType.Builtin: RawRepresentable {
269290

270291
public init?(rawValue: String) {
271292
switch rawValue {
293+
case "audio/aac": self = .aac
294+
case "video/x-msvideo": self = .avi
272295
case "image/bmp": self = .bmp
273296
case "text/css": self = .css
274297
case "text/csv": self = .csv
298+
case "application/msword": self = .doc
299+
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": self = .docx
275300
case "application/x-www-form-urlencoded": self = .form
301+
case "image/gif": self = .gif
276302
case "text/html": self = .html
277303
case "application/javascript": self = .javascript
278304
case "image/jpeg": self = .jpg

Tests/OpenAPIKitCoreTests/ContentTypeTests.swift

+5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ final class ContentTypeTests: XCTestCase {
1919

2020
func test_contentTypeStringReflexivity() {
2121
let types: [Shared.ContentType] = [
22+
.avi,
23+
.aac,
2224
.bmp,
2325
.css,
2426
.csv,
27+
.doc,
28+
.docx,
2529
.form,
30+
.gif,
2631
.html,
2732
.javascript,
2833
.jpg,

0 commit comments

Comments
 (0)