Skip to content

Commit 574cf71

Browse files
committed
even more WIP: find a good mix of required changes vs. new convenience constructors
1 parent 8eb8fb2 commit 574cf71

18 files changed

+595
-230
lines changed

Sources/OpenAPIKit/Parameter/Parameter.swift

Lines changed: 322 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,328 @@ extension OpenAPI.Parameter {
9898
public typealias Array = [Either<OpenAPI.Reference<OpenAPI.Parameter>, OpenAPI.Parameter>]
9999
}
100100

101+
// MARK: Convenience constructors
102+
extension OpenAPI.Parameter {
103+
public static func cookie(
104+
name: String,
105+
required: Bool = false,
106+
schemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>,
107+
description: String? = nil,
108+
deprecated: Bool = false,
109+
vendorExtensions: [String: AnyCodable] = [:]
110+
) -> Self {
111+
.init(
112+
name: name,
113+
context: .cookie(required: required, schemaOrContent: schemaOrContent),
114+
description: description,
115+
deprecated: deprecated,
116+
vendorExtensions: vendorExtensions
117+
)
118+
}
119+
120+
public static func cookie(
121+
name: String,
122+
required: Bool = false,
123+
content: OpenAPI.Content.Map,
124+
description: String? = nil,
125+
deprecated: Bool = false,
126+
vendorExtensions: [String: AnyCodable] = [:]
127+
) -> Self {
128+
.init(
129+
name: name,
130+
context: .cookie(
131+
required: required,
132+
content: content
133+
),
134+
description: description,
135+
deprecated: deprecated,
136+
vendorExtensions: vendorExtensions
137+
)
138+
}
139+
140+
public static func cookie(
141+
name: String,
142+
required: Bool = false,
143+
schema: JSONSchema,
144+
description: String? = nil,
145+
deprecated: Bool = false,
146+
vendorExtensions: [String: AnyCodable] = [:]
147+
) -> Self {
148+
.init(
149+
name: name,
150+
context: .cookie(
151+
required: required,
152+
schema: schema
153+
),
154+
description: description,
155+
deprecated: deprecated,
156+
vendorExtensions: vendorExtensions
157+
)
158+
}
159+
160+
public static func cookie(
161+
name: String,
162+
required: Bool = false,
163+
schemaReference: OpenAPI.Reference<JSONSchema>,
164+
description: String? = nil,
165+
deprecated: Bool = false,
166+
vendorExtensions: [String: AnyCodable] = [:]
167+
) -> Self {
168+
.init(
169+
name: name,
170+
context: .cookie(
171+
required: required,
172+
schemaOrContent: .schema(.init(schemaReference: schemaReference, style: .default(for: .cookie)))
173+
),
174+
description: description,
175+
deprecated: deprecated,
176+
vendorExtensions: vendorExtensions
177+
)
178+
}
179+
180+
public static func header(
181+
name: String,
182+
required: Bool = false,
183+
schemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>,
184+
description: String? = nil,
185+
deprecated: Bool = false,
186+
vendorExtensions: [String: AnyCodable] = [:]
187+
) -> Self {
188+
.init(
189+
name: name,
190+
context: .header(required: required, schemaOrContent: schemaOrContent),
191+
description: description,
192+
deprecated: deprecated,
193+
vendorExtensions: vendorExtensions
194+
)
195+
}
196+
197+
public static func header(
198+
name: String,
199+
required: Bool = false,
200+
content: OpenAPI.Content.Map,
201+
description: String? = nil,
202+
deprecated: Bool = false,
203+
vendorExtensions: [String: AnyCodable] = [:]
204+
) -> Self {
205+
.init(
206+
name: name,
207+
context: .header(
208+
required: required,
209+
content: content
210+
),
211+
description: description,
212+
deprecated: deprecated,
213+
vendorExtensions: vendorExtensions
214+
)
215+
}
216+
217+
public static func header(
218+
name: String,
219+
required: Bool = false,
220+
schema: JSONSchema,
221+
description: String? = nil,
222+
deprecated: Bool = false,
223+
vendorExtensions: [String: AnyCodable] = [:]
224+
) -> Self {
225+
.init(
226+
name: name,
227+
context: .header(
228+
required: required,
229+
schema: schema
230+
),
231+
description: description,
232+
deprecated: deprecated,
233+
vendorExtensions: vendorExtensions
234+
)
235+
}
236+
237+
public static func header(
238+
name: String,
239+
required: Bool = false,
240+
schemaReference: OpenAPI.Reference<JSONSchema>,
241+
description: String? = nil,
242+
deprecated: Bool = false,
243+
vendorExtensions: [String: AnyCodable] = [:]
244+
) -> Self {
245+
.init(
246+
name: name,
247+
context: .header(
248+
required: required,
249+
schemaOrContent: .schema(.init(schemaReference: schemaReference, style: .default(for: .header)))
250+
),
251+
description: description,
252+
deprecated: deprecated,
253+
vendorExtensions: vendorExtensions
254+
)
255+
}
256+
257+
public static func path(
258+
name: String,
259+
schemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>,
260+
description: String? = nil,
261+
deprecated: Bool = false,
262+
vendorExtensions: [String: AnyCodable] = [:]
263+
) -> Self {
264+
.init(
265+
name: name,
266+
context: .path(schemaOrContent: schemaOrContent),
267+
description: description,
268+
deprecated: deprecated,
269+
vendorExtensions: vendorExtensions
270+
)
271+
}
272+
273+
public static func path(
274+
name: String,
275+
content: OpenAPI.Content.Map,
276+
description: String? = nil,
277+
deprecated: Bool = false,
278+
vendorExtensions: [String: AnyCodable] = [:]
279+
) -> Self {
280+
.init(
281+
name: name,
282+
context: .path(content: content),
283+
description: description,
284+
deprecated: deprecated,
285+
vendorExtensions: vendorExtensions
286+
)
287+
}
288+
289+
public static func path(
290+
name: String,
291+
schema: JSONSchema,
292+
description: String? = nil,
293+
deprecated: Bool = false,
294+
vendorExtensions: [String: AnyCodable] = [:]
295+
) -> Self {
296+
.init(
297+
name: name,
298+
context: .path(schema: schema),
299+
description: description,
300+
deprecated: deprecated,
301+
vendorExtensions: vendorExtensions
302+
)
303+
}
304+
305+
public static func path(
306+
name: String,
307+
schemaReference: OpenAPI.Reference<JSONSchema>,
308+
description: String? = nil,
309+
deprecated: Bool = false,
310+
vendorExtensions: [String: AnyCodable] = [:]
311+
) -> Self {
312+
.init(
313+
name: name,
314+
context: .path(schemaOrContent: .schema(.init(schemaReference: schemaReference, style: .default(for: .path)))),
315+
description: description,
316+
deprecated: deprecated,
317+
vendorExtensions: vendorExtensions
318+
)
319+
}
320+
321+
public static func query(
322+
name: String,
323+
required: Bool = false,
324+
allowEmptyValue: Bool = false,
325+
schemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>,
326+
description: String? = nil,
327+
deprecated: Bool = false,
328+
vendorExtensions: [String: AnyCodable] = [:]
329+
) -> Self {
330+
.init(
331+
name: name,
332+
context: .query(required: required, allowEmptyValue: allowEmptyValue, schemaOrContent: schemaOrContent),
333+
description: description,
334+
deprecated: deprecated,
335+
vendorExtensions: vendorExtensions
336+
)
337+
}
338+
339+
public static func query(
340+
name: String,
341+
required: Bool = false,
342+
allowEmptyValue: Bool = false,
343+
content: OpenAPI.Content.Map,
344+
description: String? = nil,
345+
deprecated: Bool = false,
346+
vendorExtensions: [String: AnyCodable] = [:]
347+
) -> Self {
348+
.init(
349+
name: name,
350+
context: .query(
351+
required: required,
352+
allowEmptyValue: allowEmptyValue,
353+
content: content
354+
),
355+
description: description,
356+
deprecated: deprecated,
357+
vendorExtensions: vendorExtensions
358+
)
359+
}
360+
361+
public static func query(
362+
name: String,
363+
required: Bool = false,
364+
allowEmptyValue: Bool = false,
365+
schema: JSONSchema,
366+
description: String? = nil,
367+
deprecated: Bool = false,
368+
vendorExtensions: [String: AnyCodable] = [:]
369+
) -> Self {
370+
.init(
371+
name: name,
372+
context: .query(
373+
required: required,
374+
allowEmptyValue: allowEmptyValue,
375+
schema: schema
376+
),
377+
description: description,
378+
deprecated: deprecated,
379+
vendorExtensions: vendorExtensions
380+
)
381+
}
382+
383+
public static func query(
384+
name: String,
385+
required: Bool = false,
386+
allowEmptyValue: Bool = false,
387+
schemaReference: OpenAPI.Reference<JSONSchema>,
388+
description: String? = nil,
389+
deprecated: Bool = false,
390+
vendorExtensions: [String: AnyCodable] = [:]
391+
) -> Self {
392+
.init(
393+
name: name,
394+
context: .query(
395+
required: required,
396+
allowEmptyValue: allowEmptyValue,
397+
schemaOrContent: .schema(.init(schemaReference: schemaReference, style: .default(for: .query)))
398+
),
399+
description: description,
400+
deprecated: deprecated,
401+
vendorExtensions: vendorExtensions
402+
)
403+
}
404+
405+
public static func querystring(
406+
name: String,
407+
required: Bool = false,
408+
content: OpenAPI.Content.Map,
409+
description: String? = nil,
410+
deprecated: Bool = false,
411+
vendorExtensions: [String: AnyCodable] = [:]
412+
) -> Self {
413+
.init(
414+
name: name,
415+
context: .querystring(content: content),
416+
description: description,
417+
deprecated: deprecated,
418+
vendorExtensions: vendorExtensions
419+
)
420+
}
421+
}
422+
101423
extension OpenAPI.Parameter {
102424
/// A parameter identity is just a hashable struct
103425
/// containing exactly the things that differentiate

Sources/OpenAPIKit/Parameter/ParameterContext.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,56 @@ extension OpenAPI.Parameter {
3535
schemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>
3636
) -> Context { return .query(required: false, allowEmptyValue: allowEmptyValue, schemaOrContent: schemaOrContent) }
3737

38+
public static func query(
39+
required: Bool = false,
40+
allowEmptyValue: Bool = false,
41+
schema: JSONSchema
42+
) -> Context { return .query(required: required, allowEmptyValue: allowEmptyValue, schemaOrContent: .schema(.init(schema, style: .default(for: .query)))) }
43+
44+
public static func query(
45+
required: Bool = false,
46+
allowEmptyValue: Bool = false,
47+
content: OpenAPI.Content.Map
48+
) -> Context { return .query(required: required, allowEmptyValue: allowEmptyValue, schemaOrContent: .content(content)) }
49+
3850
/// An optional header parameter.
3951
public static func header(
4052
schemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>
4153
) -> Context { return .header(required: false, schemaOrContent: schemaOrContent) }
4254

55+
public static func header(
56+
required: Bool = false,
57+
schema: JSONSchema
58+
) -> Context { return .header(required: required, schemaOrContent: .schema(.init(schema, style: .default(for: .header)))) }
59+
60+
public static func header(
61+
required: Bool = false,
62+
content: OpenAPI.Content.Map
63+
) -> Context { return .header(required: required, schemaOrContent: .content(content)) }
64+
4365
/// An optional cookie parameter.
4466
public static func cookie(
4567
schemaOrContent: Either<SchemaContext, OpenAPI.Content.Map>
4668
) -> Context { return .cookie(required: false, schemaOrContent: schemaOrContent) }
4769

70+
public static func cookie(
71+
required: Bool = false,
72+
schema: JSONSchema
73+
) -> Context { return .cookie(required: required, schemaOrContent: .schema(.init(schema, style: .default(for: .cookie)))) }
74+
75+
public static func cookie(
76+
required: Bool = false,
77+
content: OpenAPI.Content.Map
78+
) -> Context { return .cookie(required: required, schemaOrContent: .content(content)) }
79+
80+
public static func path(
81+
schema: JSONSchema
82+
) -> Context { return .path(schemaOrContent: .schema(.init(schema, style: .default(for: .path)))) }
83+
84+
public static func path(
85+
content: OpenAPI.Content.Map
86+
) -> Context { return .path(schemaOrContent: .content(content)) }
87+
4888
/// An optional querystring parameter.
4989
public static func querystring(
5090
content: OpenAPI.Content.Map

0 commit comments

Comments
 (0)