/
SchemaProperty.java
376 lines (335 loc) · 12.6 KB
/
SchemaProperty.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/**
* Copyright (c) 2019 Contributors to the Eclipse Foundation
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.microprofile.openapi.annotations.media;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.eclipse.microprofile.openapi.annotations.ExternalDocumentation;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
/**
* The SchemaProperty Object allows the definition of input and output data types nested within the
* <code>properties</code> attribute of a {@link Schema} annotation. These types can be objects, but also primitives and
* arrays.
*
* This object is an extended subset of the JSON Schema Specification Wright Draft 00.
*
* @see <a href= "https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject">OpenAPI
* Specification Schema Object</a>
*
* @since 2.0
**/
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface SchemaProperty {
/**
* Provides a java class as implementation for this schema. When provided, additional information in the Schema
* annotation (except for type information) will augment the java class after introspection.
*
* @return a class that implements this schema
**/
Class<?> implementation() default Void.class;
/**
* Provides a java class to be used to disallow matching properties. Inline or referenced schema MUST be of a Schema
* Object and not a standard JSON Schema.
*
* @return a class with disallowed properties
**/
Class<?> not() default Void.class;
/**
* Provides an array of java class implementations which can be used to describe multiple acceptable schemas. If
* more than one match the derived schemas, a validation error will occur.
* <p>
* Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
* </p>
*
* @return the list of possible classes for a single match
**/
Class<?>[] oneOf() default {};
/**
* Provides an array of java class implementations which can be used to describe multiple acceptable schemas. If any
* match, the schema will be considered valid.
* <p>
* Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
* </p>
*
* @return the list of possible class matches
**/
Class<?>[] anyOf() default {};
/**
* Provides an array of java class implementations which can be used to describe multiple acceptable schemas. If all
* match, the schema will be considered valid.
* <p>
* Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema.
* </p>
*
* @return the list of classes to match
**/
Class<?>[] allOf() default {};
/**
* The name of the property.
* <p>
* The name will be used as the key to add this schema to the parent schema's 'properties' map.
* </p>
*
* @return the name of the schema
**/
String name();
/**
* A title to explain the purpose of the schema.
*
* @return the title of the schema
**/
String title() default "";
/**
* Constrains a value such that when divided by the multipleOf, the remainder must be an integer. Ignored if the
* value is 0.
*
* @return the multiplier constraint of the schema
**/
double multipleOf() default 0;
/**
* Sets the maximum numeric value for a property. Value must be a valid number. Ignored if the value is an empty
* string or not a number.
*
* @return the maximum value for this schema
**/
String maximum() default "";
/**
* If true, makes the maximum value exclusive, or a less-than criteria.
*
* @return the exclusive maximum value for this schema
**/
boolean exclusiveMaximum() default false;
/**
* Sets the minimum numeric value for a property. Value must be a valid number. Ignored if the value is an empty
* string or not a number.
*
* @return the minimum value for this schema
**/
String minimum() default "";
/**
* If true, makes the minimum value exclusive, or a greater-than criteria.
*
* @return the exclusive minimum value for this schema
**/
boolean exclusiveMinimum() default false;
/**
* Sets the maximum length of a string value. Ignored if the value is negative.
*
* @return the maximum length of this schema
**/
int maxLength() default Integer.MAX_VALUE;
/**
* Sets the minimum length of a string value. Ignored if the value is negative.
*
* @return the minimum length of this schema
**/
int minLength() default 0;
/**
* A pattern that the value must satisfy. Ignored if the value is an empty string.
*
* @return the pattern of this schema
**/
String pattern() default "";
/**
* Constrains the number of arbitrary properties when additionalProperties is defined. Ignored if value is 0.
*
* @return the maximum number of properties for this schema
**/
int maxProperties() default 0;
/**
* Constrains the number of arbitrary properties when additionalProperties is defined. Ignored if value is 0.
*
* @return the minimum number of properties for this schema
**/
int minProperties() default 0;
/**
* Allows multiple properties in an object to be marked as required.
*
* @return the list of required schema properties
**/
String[] requiredProperties() default {};
/**
* A description of the schema.
*
* @return this schema's description
**/
String description() default "";
/**
* Provides an optional override for the format.
* <p>
* If a consumer is unaware of the meaning of the format, they shall fall back to using the basic type without
* format. For example, if \"type: integer, format: int128\" were used to designate a very large integer,
* most consumers will not understand how to handle it, and fall back to simply \"type: integer\"
* </p>
*
* @return this schema's format
**/
String format() default "";
/**
* Reference value to a Schema definition.
* <p>
* This property provides a reference to an object defined elsewhere. This property and all other properties are
* mutually exclusive. If other properties are defined in addition to the ref property then the result is undefined.
*
* @return a reference to a schema definition
**/
String ref() default "";
/**
* Allows sending a null value for the defined schema.
*
* @return whether or not this schema is nullable
**/
boolean nullable() default false;
/**
* Relevant only for Schema "properties" definitions. Declares the property as "read only". This means that it MAY
* be sent as part of a response but SHOULD NOT be sent as part of the request.
* <p>
* If the property is marked as readOnly being true and is in the required list, the required will take effect on
* the response only. A property MUST NOT be marked as both readOnly and writeOnly being true.
* </p>
*
* @return whether or not this schema is read only
**/
boolean readOnly() default false;
/**
* Relevant only for Schema "properties" definitions. Declares the property as "write only". Therefore, it MAY be
* sent as part of a request but SHOULD NOT be sent as part of the response.
* <p>
* If the property is marked as writeOnly being true and is in the required list, the required will take effect on
* the request only. A property MUST NOT be marked as both readOnly and writeOnly being true.
* </p>
*
* @return whether or not this schema is write only
**/
boolean writeOnly() default false;
/**
* A free-form property to include an example of an instance for this schema.
* <p>
* To represent examples that cannot be naturally represented in JSON or YAML, a string value is used to contain the
* example with escaping where necessary.
* </p>
* When associated with a specific media type, the example string shall be parsed by the consumer to be treated as
* an object or an array.
*
* @return an example of this schema
**/
String example() default "";
/**
* Additional external documentation for this schema.
*
* @return additional schema documentation
**/
ExternalDocumentation externalDocs() default @ExternalDocumentation();
/**
* Specifies that a schema is deprecated and SHOULD be transitioned out of usage.
*
* @return whether or not this schema is deprecated
**/
boolean deprecated() default false;
/**
* Provides an override for the basic type of the schema.
* <p>
* Value MUST be a string. Multiple types via an array are not supported.
* </p>
* MUST be a valid type per the OpenAPI Specification.
*
* @return the type of this schema
**/
SchemaType type() default SchemaType.DEFAULT;
/**
* Provides a list of enum values. Corresponds to the enum property in the OAS schema and the enumeration property
* in the schema model.
*
* @return a list of allowed schema values
*/
String[] enumeration() default {};
/**
* Provides a default value. The default value represents what would be assumed by the consumer of the input as the
* value of the schema if one is not provided.
* <p>
* Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level.
* </p>
* For example, if type is string, then default can be "foo" but cannot be 1.
*
* @return the default value of this schema
*/
String defaultValue() default "";
/**
* Provides a discriminator property value. Adds support for polymorphism.
* <p>
* The discriminator is an object name that is used to differentiate between other schemas which may satisfy the
* payload description.
* </p>
*
* @return the discriminator property
*/
String discriminatorProperty() default "";
/**
* An array of discriminator mappings.
*
* @return the discriminator mappings for this schema
*/
DiscriminatorMapping[] discriminatorMapping() default {};
/**
* Allows schema to be marked as hidden.
*
* @return whether or not this schema is hidden
*/
boolean hidden() default false;
/**
* Only applicable if type=array. Sets the maximum number of items in an array. This integer MUST be greater than,
* or equal to, 0.
* <p>
* An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.
* </p>
* Ignored if value is Integer.MIN_VALUE.
*
* @return the maximum number of items in this array
**/
int maxItems() default Integer.MIN_VALUE;
/**
* Only applicable if type=array. Sets the minimum number of items in an array. This integer MUST be greater than,
* or equal to, 0.
* <p>
* An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this
* keyword.
* </p>
* Ignored if value is Integer.MAX_VALUE.
*
* @return the minimum number of items in this array
**/
int minItems() default Integer.MAX_VALUE;
/**
* Only applicable if type=array. Determines if the items in the array SHOULD be unique.
* <p>
* If false, the instance validates successfully. If true, the instance validates successfully if all of its
* elements are unique.
* </p>
*
* @return whether the items in this array are unique
**/
boolean uniqueItems() default false;
/**
* The list of optional extensions.
*
* @return an optional array of extensions
*
* @since 3.1
*/
Extension[] extensions() default {};
}