Started Suffix documentation.
This commit is contained in:
parent
6e6fd86163
commit
d1c7b4bebc
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue