1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.bean.openapi3;
18
19 import static org.apache.juneau.commons.utils.AssertionUtils.*;
20 import static org.apache.juneau.commons.utils.CollectionUtils.*;
21 import static org.apache.juneau.commons.utils.ThrowableUtils.*;
22 import static org.apache.juneau.commons.utils.Utils.*;
23 import static org.apache.juneau.internal.ConverterUtils.*;
24
25 import java.util.*;
26
27 import org.apache.juneau.commons.collections.*;
28 import org.apache.juneau.marshaller.*;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 public class Parameter extends OpenApiElement {
82
83 private static final String[] VALID_IN = { "query", "header", "path", "cookie" };
84 private static final String[] VALID_STYLES = { "matrix", "label", "form", "simple", "spaceDelimited", "pipeDelimited", "deepObject" };
85
86 private String name, in, description, style;
87 private Boolean required, deprecated, allowEmptyValue, explode, allowReserved;
88 private SchemaInfo schema;
89 private Object example;
90 private Map<String,Example> examples;
91
92
93
94
95 public Parameter() {}
96
97
98
99
100
101
102 public Parameter(Parameter copyFrom) {
103 super(copyFrom);
104 this.name = copyFrom.name;
105 this.in = copyFrom.in;
106 this.description = copyFrom.description;
107 this.style = copyFrom.style;
108 this.required = copyFrom.required;
109 this.deprecated = copyFrom.deprecated;
110 this.allowEmptyValue = copyFrom.allowEmptyValue;
111 this.explode = copyFrom.explode;
112 this.allowReserved = copyFrom.allowReserved;
113 this.schema = copyFrom.schema;
114 this.example = copyFrom.example;
115 this.examples = copyOf(copyFrom.examples);
116 }
117
118
119
120
121
122
123 public Parameter copy() {
124 return new Parameter(this);
125 }
126
127 @Override
128 public <T> T get(String property, Class<T> type) {
129 assertArgNotNull("property", property);
130 return switch (property) {
131 case "name" -> toType(getName(), type);
132 case "in" -> toType(getIn(), type);
133 case "description" -> toType(getDescription(), type);
134 case "required" -> toType(getRequired(), type);
135 case "deprecated" -> toType(getDeprecated(), type);
136 case "allowEmptyValue" -> toType(getAllowEmptyValue(), type);
137 case "style" -> toType(getStyle(), type);
138 case "explode" -> toType(getExplode(), type);
139 case "allowReserved" -> toType(getAllowReserved(), type);
140 case "schema" -> toType(getSchema(), type);
141 case "example" -> toType(getExample(), type);
142 case "examples" -> toType(getExamples(), type);
143 default -> super.get(property, type);
144 };
145 }
146
147
148
149
150
151
152 public Boolean getAllowEmptyValue() { return allowEmptyValue; }
153
154
155
156
157
158
159 public Boolean getAllowReserved() { return allowReserved; }
160
161
162
163
164
165
166 public Boolean getDeprecated() { return deprecated; }
167
168
169
170
171
172
173 public String getDescription() { return description; }
174
175
176
177
178
179
180 public Object getExample() { return example; }
181
182
183
184
185
186
187 public Map<String,Example> getExamples() { return examples; }
188
189
190
191
192
193
194 public Boolean getExplode() { return explode; }
195
196
197
198
199
200
201 public String getIn() { return in; }
202
203
204
205
206
207
208 public String getName() { return name; }
209
210
211
212
213
214
215 public Boolean getRequired() { return required; }
216
217
218
219
220
221
222 public SchemaInfo getSchema() { return schema; }
223
224
225
226
227
228
229 public String getStyle() { return style; }
230
231 @Override
232 public Set<String> keySet() {
233
234 var s = setb(String.class)
235 .addIf(nn(allowEmptyValue), "allowEmptyValue")
236 .addIf(nn(allowReserved), "allowReserved")
237 .addIf(nn(deprecated), "deprecated")
238 .addIf(nn(description), "description")
239 .addIf(nn(example), "example")
240 .addIf(nn(examples), "examples")
241 .addIf(nn(explode), "explode")
242 .addIf(nn(in), "in")
243 .addIf(nn(name), "name")
244 .addIf(nn(required), "required")
245 .addIf(nn(schema), "schema")
246 .addIf(nn(style), "style")
247 .build();
248
249 return new MultiSet<>(s, super.keySet());
250 }
251
252 @Override
253 public Parameter set(String property, Object value) {
254 assertArgNotNull("property", property);
255 return switch (property) {
256 case "allowEmptyValue" -> setAllowEmptyValue(toType(value, Boolean.class));
257 case "allowReserved" -> setAllowReserved(toType(value, Boolean.class));
258 case "description" -> setDescription(s(value));
259 case "deprecated" -> setDeprecated(toType(value, Boolean.class));
260 case "example" -> setExample(value);
261 case "examples" -> setExamples(toMapBuilder(value, String.class, Example.class).sparse().build());
262 case "explode" -> setExplode(toType(value, Boolean.class));
263 case "in" -> setIn(s(value));
264 case "name" -> setName(s(value));
265 case "required" -> setRequired(toType(value, Boolean.class));
266 case "schema" -> setSchema(toType(value, SchemaInfo.class));
267 case "style" -> setStyle(s(value));
268 default -> {
269 super.set(property, value);
270 yield this;
271 }
272 };
273 }
274
275
276
277
278
279
280
281 public Parameter setAllowEmptyValue(Boolean value) {
282 allowEmptyValue = value;
283 return this;
284 }
285
286
287
288
289
290
291
292 public Parameter setAllowReserved(Boolean value) {
293 allowReserved = value;
294 return this;
295 }
296
297
298
299
300
301
302
303 public Parameter setDeprecated(Boolean value) {
304 deprecated = value;
305 return this;
306 }
307
308
309
310
311
312
313
314 public Parameter setDescription(String value) {
315 description = value;
316 return this;
317 }
318
319
320
321
322
323
324
325 public Parameter setExample(Object value) {
326 example = value;
327 return this;
328 }
329
330
331
332
333
334
335
336 public Parameter setExamples(Map<String,Example> value) {
337 examples = value;
338 return this;
339 }
340
341
342
343
344
345
346
347 public Parameter setExplode(Boolean value) {
348 explode = value;
349 return this;
350 }
351
352
353
354
355
356
357
358 public Parameter setIn(String value) {
359 if (isStrict() && ! contains(value, VALID_IN))
360 throw rex("Invalid value passed in to setIn(String). Value=''{0}'', valid values={1}", value, Json5.of(VALID_IN));
361 in = value;
362 return this;
363 }
364
365
366
367
368
369
370
371 public Parameter setName(String value) {
372 name = value;
373 return this;
374 }
375
376
377
378
379
380
381
382 public Parameter setRequired(Boolean value) {
383 required = value;
384 return this;
385 }
386
387
388
389
390
391
392
393 public Parameter setSchema(SchemaInfo value) {
394 schema = value;
395 return this;
396 }
397
398
399
400
401
402
403
404 public Parameter setStyle(String value) {
405 if (isStrict() && ! contains(value, VALID_STYLES))
406 throw rex("Invalid value passed in to setStyle(String). Value=''{0}'', valid values={1}", value, Json5.of(VALID_STYLES));
407 style = value;
408 return this;
409 }
410
411 @Override
412 public Parameter strict() {
413 super.strict();
414 return this;
415 }
416
417 @Override
418 public Parameter strict(Object value) {
419 super.strict(value);
420 return this;
421 }
422 }