diff --git a/README.md b/README.md index 797d899..565d1f4 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ let mediaType = MediaType(rawValue: rawMediaType) ### Suffixes and Parameters -Media type suffixes and parameters are supported both via string literals and ``MediaType`` cases. +Media type ``Suffix``es and parameters are supported both via string literals and ``MediaType`` cases. ```swift MediaType.application(.atom(nil, ["charset": "utf-8"])) // is equivalent to diff --git a/Sources/MediaType/Suffix.swift b/Sources/MediaType/Suffix.swift index 8f51f51..6e2eca5 100644 --- a/Sources/MediaType/Suffix.swift +++ b/Sources/MediaType/Suffix.swift @@ -1,5 +1,18 @@ import Foundation +/// Represents the media type [suffix](https://en.wikipedia.org/wiki/Media_type#Suffix)es. +/// +/// The library allows all ``MediaType``s to have a suffix. Keep in mind though, that not all such combinations are +/// registered (see the [official site](https://www.iana.org/assignments/media-types/media-types.xhtml) for details). +/// +/// It is also possible to create completely custom suffixes by using either the ``Suffix/other(_:)`` case directly or a +/// string literal. +/// +/// ```swift +/// MediaType.application(.jose(.json)) // Creates: application/jose+json +/// MediaType.application(.jose(.other("custom"))) // Creates: application/jose+custom +/// MediaType.image(.svg("zip")) // Creates: image/svg+zip +/// ``` public enum Suffix { case xml case json diff --git a/Tests/MediaTypeTests/CodeExamples/CodeExamples+Suffix.swift b/Tests/MediaTypeTests/CodeExamples/CodeExamples+Suffix.swift new file mode 100644 index 0000000..a2fb05b --- /dev/null +++ b/Tests/MediaTypeTests/CodeExamples/CodeExamples+Suffix.swift @@ -0,0 +1,10 @@ +import XCTest +import MediaType + +extension CodeExamples { + func test_suffix_use_cases() { + XCTAssertEqual(MediaType.application(.jose(.json)), "application/jose+json") + XCTAssertEqual(MediaType.application(.jose(.other("custom"))), "application/jose+custom") + XCTAssertEqual(MediaType.image(.svg("zip")), "image/svg+zip") + } +}