@@ -121,6 +121,108 @@ public protocol OpenAPIFormat: SwiftTyped, Codable, Equatable, RawRepresentable,
121
121
var jsonType : JSONType { get }
122
122
}
123
123
124
+ /// These are just the OpenAPIFormats that are specific to this module; there are shared
125
+ /// formats in OpenAPIKitCore/Shared/JSONTypeFormat.swift as well.
126
+ extension JSONTypeFormat {
127
+ /// The allowed "format" properties for `.string` schemas.
128
+ public enum StringFormat : RawRepresentable , Equatable {
129
+ case generic
130
+ case date
131
+ /// A string instance is valid against this attribute if it is a valid
132
+ /// date representation as defined by
133
+ /// https://tools.ietf.org/html/rfc3339#section-5.6
134
+ case dateTime
135
+ case duration
136
+ case email
137
+ case hostname
138
+ case idnEmail
139
+ case idnHostname
140
+ case ipv4
141
+ case ipv6
142
+ /// International version of .uri
143
+ case iri
144
+ /// International version of .uriReference
145
+ case iriReference
146
+ case jsonPointer
147
+ case password
148
+ case regex
149
+ case relativeJsonPointer
150
+ case time
151
+ /// A string instance is valid against this attribute if it is a valid
152
+ /// URI, according to
153
+ /// https://tools.ietf.org/html/rfc3986
154
+ case uri
155
+ /// A string instance is valid against this attribute if it is a valid
156
+ /// URI, according to
157
+ /// https://tools.ietf.org/html/rfc3986
158
+ case uriReference
159
+ case uriTemplate
160
+ case uuid
161
+ case other( String )
162
+
163
+ public var rawValue : String {
164
+ switch self {
165
+ case . generic: return " "
166
+ case . date: return " date "
167
+ case . dateTime: return " date-time "
168
+ case . duration: return " duration "
169
+ case . email: return " email "
170
+ case . hostname: return " hostname "
171
+ case . idnEmail: return " idn-email "
172
+ case . idnHostname: return " idn-hostname "
173
+ case . ipv4: return " ipv4 "
174
+ case . ipv6: return " ipv6 "
175
+ case . iri: return " iri "
176
+ case . iriReference: return " iri-reference "
177
+ case . jsonPointer: return " json-pointer "
178
+ case . password: return " password "
179
+ case . regex: return " regex "
180
+ case . relativeJsonPointer: return " relative-json-pointer "
181
+ case . time: return " time "
182
+ case . uri: return " uri "
183
+ case . uriReference: return " uri-reference "
184
+ case . uriTemplate: return " uri-template "
185
+ case . uuid: return " uuid "
186
+ case . other( let other) :
187
+ return other
188
+ }
189
+ }
190
+
191
+ public init ( rawValue: String ) {
192
+ switch rawValue {
193
+ case " " : self = . generic
194
+ case " date " : self = . date
195
+ case " date-time " : self = . dateTime
196
+ case " duration " : self = . duration
197
+ case " email " : self = . email
198
+ case " hostname " : self = . hostname
199
+ case " idn-email " : self = . idnEmail
200
+ case " idn-hostname " : self = . idnHostname
201
+ case " ipv4 " : self = . ipv4
202
+ case " ipv6 " : self = . ipv6
203
+ case " iri " : self = . iri
204
+ case " iri-reference " : self = . iriReference
205
+ case " json-pointer " : self = . jsonPointer
206
+ case " password " : self = . password
207
+ case " regex " : self = . regex
208
+ case " relative-json-pointer " : self = . relativeJsonPointer
209
+ case " time " : self = . time
210
+ case " uri " : self = . uri
211
+ case " uri-reference " : self = . uriReference
212
+ case " uri-template " : self = . uriTemplate
213
+ case " uuid " : self = . uuid
214
+ default : self = . other( rawValue)
215
+ }
216
+ }
217
+
218
+ public typealias SwiftType = String
219
+
220
+ public static var unspecified : StringFormat {
221
+ return . generic
222
+ }
223
+ }
224
+ }
225
+
124
226
/// A format used when no type is known or any type is allowed.
125
227
///
126
228
/// There are no built-in formats that do not have an associated
0 commit comments