Skip to content

Commit ea0c5ed

Browse files
authored
Merge pull request #513 from MikeEdgar/387_annotation_extensions
Support extensions as nested annotations for extensible models
2 parents 435326e + ad88f72 commit ea0c5ed

40 files changed

+368
-18
lines changed

api/src/main/java/org/eclipse/microprofile/openapi/annotations/Components.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.Target;
2323

2424
import org.eclipse.microprofile.openapi.annotations.callbacks.Callback;
25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2526
import org.eclipse.microprofile.openapi.annotations.headers.Header;
2627
import org.eclipse.microprofile.openapi.annotations.links.Link;
2728
import org.eclipse.microprofile.openapi.annotations.media.ExampleObject;
@@ -105,4 +106,15 @@
105106
* @return the reusable Callback objects.
106107
*/
107108
Callback[] callbacks() default {};
109+
110+
/**
111+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.Components Components} model
112+
* corresponding to the containing annotation.
113+
*
114+
* @return array of extensions
115+
*
116+
* @since 3.1
117+
*/
118+
Extension[] extensions() default {};
119+
108120
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/ExternalDocumentation.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
27+
2628
/**
2729
* This annotation allows referencing an external resource for extended documentation.
2830
* <p>
@@ -56,4 +58,13 @@
5658
**/
5759
String url() default "";
5860

61+
/**
62+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.ExternalDocumentation
63+
* ExternalDocumentation} model corresponding to the containing annotation.
64+
*
65+
* @return array of extensions
66+
*
67+
* @since 3.1
68+
*/
69+
Extension[] extensions() default {};
5970
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/OpenAPIDefinition.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2627
import org.eclipse.microprofile.openapi.annotations.info.Info;
2728
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
2829
import org.eclipse.microprofile.openapi.annotations.servers.Server;
@@ -87,4 +88,14 @@
8788
* @return the element with a set of reusable objects for different aspects of the OAS.
8889
*/
8990
Components components() default @Components;
91+
92+
/**
93+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.OpenAPI OpenAPI} model
94+
* corresponding to the containing annotation.
95+
*
96+
* @return array of extensions
97+
*
98+
* @since 3.1
99+
*/
100+
Extension[] extensions() default {};
90101
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/Operation.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
27+
2628
/**
2729
* Describes a single API operation on a path.
2830
*
@@ -75,4 +77,14 @@
7577
* @return whether or not this operation is hidden
7678
*/
7779
boolean hidden() default false;
80+
81+
/**
82+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.Operation Operation} model
83+
* corresponding to the containing annotation.
84+
*
85+
* @return array of extensions
86+
*
87+
* @since 3.1
88+
*/
89+
Extension[] extensions() default {};
7890
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/callbacks/Callback.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.lang.annotation.RetentionPolicy;
2525
import java.lang.annotation.Target;
2626

27+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
28+
2729
/**
2830
* This object represents a callback URL that will be invoked.
2931
*
@@ -74,4 +76,14 @@
7476
* @return reference to a callback object definition
7577
**/
7678
String ref() default "";
79+
80+
/**
81+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.callbacks.Callback Callback}
82+
* model corresponding to the containing annotation.
83+
*
84+
* @return array of extensions
85+
*
86+
* @since 3.1
87+
*/
88+
Extension[] extensions() default {};
7789
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/callbacks/CallbackOperation.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@
109109
SecurityRequirement[] security() default {};
110110

111111
/**
112-
* The list of optional extensions.
112+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.Operation Operation} model
113+
* corresponding to the containing annotation.
113114
*
114-
* @return an optional array of extensions
115+
* @return array of extensions
116+
*
117+
* @since 3.1
115118
*/
116119
Extension[] extensions() default {};
117120
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/callbacks/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
* </pre>
4545
*/
4646

47-
@org.osgi.annotation.versioning.Version("1.0")
47+
@org.osgi.annotation.versioning.Version("1.1")
4848
@org.osgi.annotation.versioning.ProviderType
4949
package org.eclipse.microprofile.openapi.annotations.callbacks;

api/src/main/java/org/eclipse/microprofile/openapi/annotations/extensions/Extension.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,62 @@
2424
import java.lang.annotation.Target;
2525

2626
/**
27-
* A named extension that should be added to the OpenAPI definition.
27+
* A named extension that should be added to the OpenAPI definition. The names of all extensions MUST begin with
28+
* {@code x-} or else an invalid document will potentially be created.
29+
*
30+
* <p>
31+
* Although this annotation may currently be placed directly on a Java language element target, application developers
32+
* should instead utilize the {@code extensions} property of the particular annotation that corresponds to the model
33+
* being extended. Use of the annotation directly on a Java element is often ambiguous and it may result in the
34+
* extension being added to an incorrect location in the OpenAPI model. Future releases of MicroProfile OpenAPI may
35+
* remove the capability of placing this annotation directly on a Java element.
36+
*
37+
* <p>
38+
* When {@code @Extension} annotations are used both directly on a Java element as well as within another annotation
39+
* that targets the same Java element, implementations will apply only the nested extensions to the resulting model.
40+
*
41+
* <p>
42+
* Example of <em>preferred</em> use with {@code @Extension} nested within an {@code @Schema} annotation:
43+
*
44+
* <pre>
45+
* class MyPojo {
46+
*
47+
* {@literal @}Schema(
48+
* type = SchemaType.STRING,
49+
* extensions = {@literal @}Extension(
50+
* name = "x-custom-property",
51+
* value = "custom-value")
52+
* String property1;
53+
*
54+
* }
55+
* </pre>
56+
*
57+
* <p>
58+
* Example of <em>deprecated</em> use with {@code @Extension} placed directly on a field implied to be a schema
59+
* property:
60+
*
61+
* <pre>
62+
* class MyPojo {
63+
*
64+
* {@literal @}Extension(
65+
* name = "x-custom-property",
66+
* value = "custom-value")
67+
* String property1;
68+
*
69+
* }
70+
* </pre>
71+
*
2872
*/
2973
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE})
3074
@Retention(RetentionPolicy.RUNTIME)
3175
@Repeatable(Extensions.class)
3276
public @interface Extension {
3377

3478
/**
35-
* A name for the extension.
79+
* A name for the extension. The names of all extensions MUST begin with {@code x-} or else an invalid document will
80+
* potentially be created.
3681
*
37-
* @return an option name for these extensions - will be prefixed with "x-"
82+
* @return an option name for these extensions - must be prefixed with {@code x-}
3883
*/
3984
String name();
4085

api/src/main/java/org/eclipse/microprofile/openapi/annotations/headers/Header.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2526
import org.eclipse.microprofile.openapi.annotations.media.Schema;
2627

2728
/**
@@ -92,4 +93,13 @@
9293
**/
9394
String ref() default "";
9495

96+
/**
97+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.headers.Header Header} model
98+
* corresponding to the containing annotation.
99+
*
100+
* @return array of extensions
101+
*
102+
* @since 3.1
103+
*/
104+
Extension[] extensions() default {};
95105
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/headers/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
* </pre>
2727
*/
2828

29-
@org.osgi.annotation.versioning.Version("1.0")
29+
@org.osgi.annotation.versioning.Version("1.1")
3030
@org.osgi.annotation.versioning.ProviderType
3131
package org.eclipse.microprofile.openapi.annotations.headers;

api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/Contact.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
26+
2527
/**
2628
* Contact information for the exposed API.
2729
*
@@ -52,4 +54,13 @@
5254
**/
5355
String email() default "";
5456

57+
/**
58+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.info.Contact Contact} model
59+
* corresponding to the containing annotation.
60+
*
61+
* @return array of extensions
62+
*
63+
* @since 3.1
64+
*/
65+
Extension[] extensions() default {};
5566
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/Info.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
26+
2527
/**
2628
* This annotation provides metadata about the API, and maps to the Info object in OpenAPI Specification 3.
2729
*
@@ -73,4 +75,13 @@
7375
**/
7476
String version();
7577

78+
/**
79+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.info.Info Info} model
80+
* corresponding to the containing annotation.
81+
*
82+
* @return array of extensions
83+
*
84+
* @since 3.1
85+
*/
86+
Extension[] extensions() default {};
7687
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/License.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
26+
2527
/**
2628
* License information for the exposed API.
2729
*
@@ -45,4 +47,13 @@
4547
**/
4648
String url() default "";
4749

50+
/**
51+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.info.License License} model
52+
* corresponding to the containing annotation.
53+
*
54+
* @return array of extensions
55+
*
56+
* @since 3.1
57+
*/
58+
Extension[] extensions() default {};
4859
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/info/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
* </pre>
3535
*/
3636

37-
@org.osgi.annotation.versioning.Version("1.0")
37+
@org.osgi.annotation.versioning.Version("1.1")
3838
@org.osgi.annotation.versioning.ProviderType
3939
package org.eclipse.microprofile.openapi.annotations.info;

api/src/main/java/org/eclipse/microprofile/openapi/annotations/links/Link.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2526
import org.eclipse.microprofile.openapi.annotations.servers.Server;
2627

2728
/**
@@ -103,4 +104,13 @@
103104
**/
104105
String ref() default "";
105106

107+
/**
108+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.links.Link Link} model
109+
* corresponding to the containing annotation.
110+
*
111+
* @return array of extensions
112+
*
113+
* @since 3.1
114+
*/
115+
Extension[] extensions() default {};
106116
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/links/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
* </pre>
3232
*/
3333

34-
@org.osgi.annotation.versioning.Version("1.0")
34+
@org.osgi.annotation.versioning.Version("1.1")
3535
@org.osgi.annotation.versioning.ProviderType
3636
package org.eclipse.microprofile.openapi.annotations.links;

api/src/main/java/org/eclipse/microprofile/openapi/annotations/media/Content.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
26+
2527
/**
2628
* This object provides schema and examples for a particular media type.
2729
*
@@ -72,4 +74,13 @@
7274
*/
7375
Encoding[] encoding() default {};
7476

77+
/**
78+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.media.MediaType MediaType}
79+
* model corresponding to the containing annotation.
80+
*
81+
* @return array of extensions
82+
*
83+
* @since 3.1
84+
*/
85+
Extension[] extensions() default {};
7586
}

api/src/main/java/org/eclipse/microprofile/openapi/annotations/media/Encoding.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.RetentionPolicy;
2323
import java.lang.annotation.Target;
2424

25+
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
2526
import org.eclipse.microprofile.openapi.annotations.headers.Header;
2627

2728
/**
@@ -103,4 +104,13 @@
103104
*/
104105
Header[] headers() default {};
105106

107+
/**
108+
* List of extensions to be added to the {@link org.eclipse.microprofile.openapi.models.media.Encoding Encoding}
109+
* model corresponding to the containing annotation.
110+
*
111+
* @return array of extensions
112+
*
113+
* @since 3.1
114+
*/
115+
Extension[] extensions() default {};
106116
}

0 commit comments

Comments
 (0)