Skip to content

Commit 454e0e9

Browse files
committed
update README
1 parent c888002 commit 454e0e9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ let decoder = ... // JSONDecoder() or YAMLDecoder()
9090
let openAPIDoc = try decoder.decode(OpenAPI.Document.self, from: ...)
9191
```
9292

93+
#### Decoding Future Versions
94+
`OpenAPIKit` adds support for new OAS versions when it has support for most or
95+
all of the features of that OAS version. If you want to parse an OpenAPI
96+
Document that is written in a newer version than `OpenAPIKit` supports and you
97+
are asserting that the newer version is possible to parse as if it were the
98+
pre-existing version, you can tell `OpenAPIKit` to parse the newer version as if
99+
it were the older version.
100+
101+
You do this with `userInfo` passed into the `Decoder` you are using. For
102+
example, to decode a hypothetical document version of `"3.100.100"` as if it
103+
were version `"3.1.1"`, set your decoder up as follows:
104+
```swift
105+
let userInfo = [
106+
DocumentConfiguration.versionMapKey: ["3.100.100": OpenAPI.Document.Version.v3_1_1]
107+
]
108+
109+
let decoder = ... // JSONDecoder() or YAMLDecoder()
110+
decoder.userInfo = userInfo
111+
112+
let openAPIDoc = try decoder.decode(OpenAPI.Document.self, from: ...)
113+
```
114+
93115
#### Decoding Errors
94116
You can wrap any error you get back from a decoder in `OpenAPI.Error` to get a friendlier human-readable description from `localizedDescription`.
95117

0 commit comments

Comments
 (0)