|
1 | 1 | package io.smallrye.openapi.runtime.io.headers; |
2 | 2 |
|
3 | | -import org.eclipse.microprofile.openapi.OASFactory; |
4 | 3 | import org.eclipse.microprofile.openapi.models.headers.Header; |
5 | 4 | import org.jboss.jandex.AnnotationInstance; |
| 5 | +import org.jboss.jandex.AnnotationValue; |
6 | 6 |
|
7 | | -import io.smallrye.openapi.model.ReferenceType; |
8 | 7 | import io.smallrye.openapi.runtime.io.IOContext; |
9 | | -import io.smallrye.openapi.runtime.io.IoLogging; |
10 | 8 | import io.smallrye.openapi.runtime.io.MapModelIO; |
11 | 9 | import io.smallrye.openapi.runtime.io.Names; |
12 | 10 | import io.smallrye.openapi.runtime.io.ReferenceIO; |
13 | 11 |
|
14 | 12 | public class HeaderIO<V, A extends V, O extends V, AB, OB> extends MapModelIO<Header, V, A, O, AB, OB> |
15 | 13 | implements ReferenceIO<V, A, O, AB, OB> { |
16 | 14 |
|
17 | | - private static final String PROP_DESCRIPTION = "description"; |
18 | 15 | private static final String PROP_SCHEMA = "schema"; |
19 | | - private static final String PROP_ALLOW_EMPTY_VALUE = "allowEmptyValue"; |
20 | | - private static final String PROP_REQUIRED = "required"; |
21 | | - private static final String PROP_DEPRECATED = "deprecated"; |
| 16 | + private static final String PROP_EXAMPLE = "example"; |
| 17 | + private static final String PROP_EXAMPLES = "examples"; |
22 | 18 |
|
23 | 19 | public HeaderIO(IOContext<V, A, O, AB, OB> context) { |
24 | 20 | super(context, Names.HEADER, Names.create(Header.class)); |
25 | 21 | } |
26 | 22 |
|
27 | 23 | @Override |
28 | 24 | public Header read(AnnotationInstance annotation) { |
29 | | - IoLogging.logger.singleAnnotation("@Header"); |
30 | | - Header header = OASFactory.createHeader(); |
31 | | - header.setRef(ReferenceType.HEADER.refValue(annotation)); |
32 | | - header.setDescription(value(annotation, PROP_DESCRIPTION)); |
33 | | - header.setSchema(schemaIO().read(annotation.value(PROP_SCHEMA))); |
34 | | - header.setRequired(value(annotation, PROP_REQUIRED)); |
35 | | - header.setDeprecated(value(annotation, PROP_DEPRECATED)); |
36 | | - header.setAllowEmptyValue(value(annotation, PROP_ALLOW_EMPTY_VALUE)); |
37 | | - header.setExtensions(extensionIO().readExtensible(annotation)); |
| 25 | + Header header = read(Header.class, annotation, "name"); |
| 26 | + |
| 27 | + if (header.getExample() != null || header.getExamples() != null) { |
| 28 | + /* |
| 29 | + * Save the header for later parsing. The schema may not yet be set |
| 30 | + * so we do not know if it should be parsed. |
| 31 | + */ |
| 32 | + scannerContext().getUnparsedExamples().add(header); |
| 33 | + } |
| 34 | + |
38 | 35 | return header; |
39 | 36 | } |
| 37 | + |
| 38 | + @Override |
| 39 | + protected boolean setProperty(Header model, AnnotationValue value) { |
| 40 | + switch (value.name()) { |
| 41 | + case PROP_SCHEMA: |
| 42 | + model.setSchema(schemaIO().read(value)); |
| 43 | + return true; |
| 44 | + case PROP_EXAMPLES: |
| 45 | + model.setExamples(exampleObjectIO().readMap(value)); |
| 46 | + return true; |
| 47 | + case PROP_EXAMPLE: |
| 48 | + model.setExample(value.asString()); |
| 49 | + return true; |
| 50 | + default: |
| 51 | + break; |
| 52 | + } |
| 53 | + |
| 54 | + return false; |
| 55 | + } |
40 | 56 | } |
0 commit comments