Skip to content

Commit 35f021c

Browse files
committed
Define and verify behavior of schema extension properties
Signed-off-by: Michael Edgar <michael@xlate.io>
1 parent 2828747 commit 35f021c

4 files changed

Lines changed: 128 additions & 11 deletions

File tree

api/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
<artifactId>osgi.annotation</artifactId>
3434
<scope>provided</scope>
3535
</dependency>
36+
<dependency>
37+
<groupId>biz.aQute.bnd</groupId>
38+
<artifactId>biz.aQute.bnd.annotation</artifactId>
39+
<version>7.0.0</version>
40+
<scope>provided</scope>
41+
</dependency>
3642
</dependencies>
3743

3844
<build>

api/src/main/java/org/eclipse/microprofile/openapi/models/Extensible.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,24 @@
2323
* The base interface for OpenAPI model objects that can contain extensions. Extensions contain data not required by the
2424
* specification and may or may not be supported by the tools you use.
2525
* <p>
26-
* The extensions property names are always prefixed by "x-".
26+
* The extension's property names are always prefixed by "x-" unless otherwise specified by sub-interfaces or Extensible
27+
* methods overridden therein. Sub-interfaces may also include additional detail regarding the handling of extension
28+
* properties and how they relate to other well-known properties of the interface.
29+
*
30+
* For example, {@link org.eclipse.microprofile.openapi.models.media.Schema Schema} defines such handling and relaxes
31+
* the requirement that extension properties are prefixed by "x-".
2732
*/
2833
public interface Extensible<T extends Extensible<T>> {
2934

3035
/**
31-
* Returns the extensions property from an Extensible instance.
36+
* Returns the map of all extension properties from an Extensible instance.
3237
*
3338
* @return a map containing keys which start with "x-" and values which provide additional information
3439
**/
3540
Map<String, Object> getExtensions();
3641

3742
/**
38-
* Sets this Extensible's extensions property to the given map of extensions.
43+
* Sets this Extensible's extension properties to the given map of extensions.
3944
*
4045
* @param extensions
4146
* map containing keys which start with "x-" and values which provide additional information
@@ -49,7 +54,7 @@ default T extensions(Map<String, Object> extensions) {
4954
}
5055

5156
/**
52-
* Adds the given object to this Extensible's map of extensions, with the given name as its key.
57+
* Adds the given extension property to this Extensible, with the given name as its key.
5358
*
5459
* @param name
5560
* the key used to access the extension object. Always prefixed by "x-".
@@ -61,23 +66,23 @@ default T extensions(Map<String, Object> extensions) {
6166
T addExtension(String name, Object value);
6267

6368
/**
64-
* Removes the given object to this Extensible's map of extensions, with the given name as its key.
69+
* Removes an extension with the given property name from this Extensible.
6570
*
6671
* @param name
6772
* the key used to access the extension object. Always prefixed by "x-".
6873
*/
6974
void removeExtension(String name);
7075

7176
/**
72-
* Sets this Extensible's extensions property to the given map of extensions.
77+
* Sets this Extensible's extension properties to the given map of extensions.
7378
*
7479
* @param extensions
7580
* map containing keys which start with "x-" and values which provide additional information
7681
*/
7782
void setExtensions(Map<String, Object> extensions);
7883

7984
/**
80-
* Checks whether an extension with the given name is present in this Extensible's map of extensions.
85+
* Checks whether an extension with the given name is present in this Extensible.
8186
*
8287
* @param name
8388
* the key used to access the extension object. Always prefixed by "x-".
@@ -93,7 +98,7 @@ default boolean hasExtension(String name) {
9398
}
9499

95100
/**
96-
* Returns the extension object with the given name from this Extensible's map of extensions.
101+
* Returns the object with the given name from this Extensible's extensions.
97102
*
98103
* @param name
99104
* the key used to access the extension object. Always prefixed by "x-".

api/src/main/java/org/eclipse/microprofile/openapi/models/media/Schema.java

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
* Any time a Schema Object can be used, a Reference Object can be used in its place. This allows referencing an
4040
* existing definition instead of defining the same Schema again.
4141
*
42+
* <h3 id="schema-extensions">Extensions</h3> Although Schema is {@link Extensible}, the behavior of extensions is only
43+
* defined for the OAS schema dialect identified by URI {@code https://spec.openapis.org/oas/3.1/dialect/base} (the
44+
* default if not specified). For this dialect, Schema instances will consider all unknown properties to be extensions.
45+
*
46+
* The behavior is undefined when adding an extension via one of the methods of the {@link Extensible} interface when
47+
* the name of the extension matches the name of a standard OAS schema property.
48+
*
4249
* @see <a href= "https://spec.openapis.org/oas/v3.1.0.html#schema-object">OpenAPI Specification Schema Object</a>
4350
*/
4451
public interface Schema extends Extensible<Schema>, Constructible, Reference<Schema> {
@@ -2051,7 +2058,8 @@ default Schema examples(List<Object> examples) {
20512058
* Allows access to arbitrary properties in a schema object, allowing use of alternative schema dialects which use
20522059
* different property names (or the same property names with different data types).
20532060
* <p>
2054-
* When using the standard schema dialect, this method can be used to retrieve values set by other methods. E.g.
2061+
* When using the standard schema dialect, this method can be used to retrieve values set by other methods provided
2062+
* the type is compatible. E.g.
20552063
*
20562064
* <pre>
20572065
* {@code
@@ -2060,6 +2068,9 @@ default Schema examples(List<Object> examples) {
20602068
* }
20612069
* </pre>
20622070
*
2071+
* <p>
2072+
* Note, if the property is an extension, this method is equivalent to {@link #getExtension(String)}.
2073+
*
20632074
* @param propertyName
20642075
* the property name
20652076
* @return the value of the named property, or {@code null} if a property with the given name is not set
@@ -2090,7 +2101,8 @@ default Schema examples(List<Object> examples) {
20902101
* </ul>
20912102
*
20922103
* <p>
2093-
* When using the standard schema dialect, values set by this method can be retrieved by other methods. E.g.
2104+
* When using the standard schema dialect, values set by this method can be retrieved by other methods provided the
2105+
* type is compatible. E.g.
20942106
*
20952107
* <pre>
20962108
* {@code
@@ -2099,6 +2111,9 @@ default Schema examples(List<Object> examples) {
20992111
* }
21002112
* </pre>
21012113
*
2114+
* <p>
2115+
* Note, if the property is an extension, this method is equivalent to {@link #addExtension(String, Object)}.
2116+
*
21022117
* @param propertyName
21032118
* the property name
21042119
* @param value
@@ -2122,12 +2137,102 @@ default Schema examples(List<Object> examples) {
21222137
/**
21232138
* Sets all properties of a schema.
21242139
* <p>
2125-
* Equivalent to clearing all properties and then setting each property with {@link #set(String, Object)}.
2140+
* Equivalent to clearing all properties, including extensions, and then setting each property with
2141+
* {@link #set(String, Object)}.
21262142
*
21272143
* @param allProperties
21282144
* the properties to set. Each value in the map must be valid according to the rules in
21292145
* {@link #set(String, Object)}
21302146
* @since 4.0
21312147
*/
21322148
void setAll(Map<String, ?> allProperties);
2149+
2150+
/**
2151+
* Returns the map of all extension properties of the schema.
2152+
*
2153+
* @return a map containing all of this schema's extension properties
2154+
*
2155+
* @see <a href="#schema-extensions">Schema Extensions</a>
2156+
**/
2157+
@Override
2158+
Map<String, Object> getExtensions();
2159+
2160+
/**
2161+
* Sets this schema's extension properties to the given map of extensions. Passing an empty map has the effect of
2162+
* clearing all existing extension properties.
2163+
*
2164+
* @param extensions
2165+
* map containing the extension properties for this schema
2166+
* @return the current instance
2167+
*
2168+
* @see <a href="#schema-extensions">Schema Extensions</a>
2169+
*/
2170+
@Override
2171+
default Schema extensions(Map<String, Object> extensions) {
2172+
return Extensible.super.extensions(extensions);
2173+
}
2174+
2175+
/**
2176+
* Sets a schema extension property.
2177+
*
2178+
* @param name
2179+
* the extension property name
2180+
* @param value
2181+
* extension property value. null values will be rejected (implementation will throw an exception) or
2182+
* ignored.
2183+
* @return the current instance
2184+
*
2185+
* @see <a href="#schema-extensions">Schema Extensions</a>
2186+
*/
2187+
@Override
2188+
Schema addExtension(String name, Object value);
2189+
2190+
/**
2191+
* Removes the given extension property from the schema.
2192+
*
2193+
* @param name
2194+
* the extension property name
2195+
*
2196+
* @see <a href="#schema-extensions">Schema Extensions</a>
2197+
*/
2198+
@Override
2199+
void removeExtension(String name);
2200+
2201+
/**
2202+
* Sets this schema's extension properties to the given map of extensions. Passing an empty map has the effect of
2203+
* clearing all existing extension properties.
2204+
*
2205+
* @param extensions
2206+
* map containing the extension properties for this schema
2207+
*
2208+
* @see <a href="#schema-extensions">Schema Extensions</a>
2209+
*/
2210+
@Override
2211+
void setExtensions(Map<String, Object> extensions);
2212+
2213+
/**
2214+
* Checks whether an extension property with the given name is present on this schema.
2215+
*
2216+
* @param name
2217+
* the extension property name
2218+
*
2219+
* @return {@code true} if an extension with the given name is present, otherwise {@code false}
2220+
*/
2221+
@Override
2222+
default boolean hasExtension(String name) {
2223+
return Extensible.super.hasExtension(name);
2224+
}
2225+
2226+
/**
2227+
* Returns the extension object with the given name from this schema.
2228+
*
2229+
* @param name
2230+
* the extension property name
2231+
*
2232+
* @return the corresponding extension object, or {@code null} if no extension with the given name is present
2233+
*/
2234+
@Override
2235+
default Object getExtension(String name) {
2236+
return Extensible.super.getExtension(name);
2237+
}
21332238
}

spec/src/main/asciidoc/release_notes.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ A full list of changes delivered in the 4.2 release can be found at link:https:/
2828
==== API/SPI changes
2929

3030
* Add `example` and `examples` to `@Header` and verify implementation support in TCK (https://github.com/microprofile/microprofile-open-api/issues/697)[697])
31+
* Override `@Extensible`'s methods in `@Schema`, providing clarification in the documentation on how the methods behave specifically for schemas (https://github.com/microprofile/microprofile-open-api/issues/698[698])
3132

3233
[[other_changes_42]]
3334
==== Other Changes

0 commit comments

Comments
 (0)