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 */
4451public interface Schema extends Extensible <Schema >, Constructible , Reference <Schema > {
@@ -2060,6 +2067,9 @@ default Schema examples(List<Object> examples) {
20602067 * }
20612068 * </pre>
20622069 *
2070+ * <p>
2071+ * Note, if the property is an extension, this method is equivalent to {@link #getExtension(String)}.
2072+ *
20632073 * @param propertyName
20642074 * the property name
20652075 * @return the value of the named property, or {@code null} if a property with the given name is not set
@@ -2090,7 +2100,8 @@ default Schema examples(List<Object> examples) {
20902100 * </ul>
20912101 *
20922102 * <p>
2093- * When using the standard schema dialect, values set by this method can be retrieved by other methods. E.g.
2103+ * When using the standard schema dialect, values set by this method can be retrieved by other methods provided the
2104+ * type is compatible. E.g.
20942105 *
20952106 * <pre>
20962107 * {@code
@@ -2099,6 +2110,9 @@ default Schema examples(List<Object> examples) {
20992110 * }
21002111 * </pre>
21012112 *
2113+ * <p>
2114+ * Note, if the property is an extension, this method is equivalent to {@link #addExtension(String, Object)}.
2115+ *
21022116 * @param propertyName
21032117 * the property name
21042118 * @param value
@@ -2122,12 +2136,104 @@ default Schema examples(List<Object> examples) {
21222136 /**
21232137 * Sets all properties of a schema.
21242138 * <p>
2125- * Equivalent to clearing all properties and then setting each property with {@link #set(String, Object)}.
2139+ * Equivalent to clearing all properties, including extensions, and then setting each property with
2140+ * {@link #set(String, Object)}.
21262141 *
21272142 * @param allProperties
21282143 * the properties to set. Each value in the map must be valid according to the rules in
21292144 * {@link #set(String, Object)}
21302145 * @since 4.0
21312146 */
21322147 void setAll (Map <String , ?> allProperties );
2148+
2149+ /**
2150+ * Returns the map of all extension properties of the schema.
2151+ *
2152+ * @return a map containing all of this schema's extension properties
2153+ *
2154+ * @see <a href="#schema-extensions">Schema Extensions</a>
2155+ **/
2156+ @ Override
2157+ Map <String , Object > getExtensions ();
2158+
2159+ /**
2160+ * Sets this schema's extension properties to the given map of extensions. Passing an empty map has the effect of
2161+ * clearing all existing extension properties.
2162+ *
2163+ * @param extensions
2164+ * map containing the extension properties for this schema
2165+ * @return the current instance
2166+ *
2167+ * @see <a href="#schema-extensions">Schema Extensions</a>
2168+ */
2169+ @ Override
2170+ @ aQute .bnd .annotation .baseline .BaselineIgnore ("4.2.0" )
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+ @ aQute .bnd .annotation .baseline .BaselineIgnore ("4.2.0" )
2189+ Schema addExtension (String name , Object value );
2190+
2191+ /**
2192+ * Removes the given extension property from the schema.
2193+ *
2194+ * @param name
2195+ * the extension property name
2196+ *
2197+ * @see <a href="#schema-extensions">Schema Extensions</a>
2198+ */
2199+ @ Override
2200+ void removeExtension (String name );
2201+
2202+ /**
2203+ * Sets this schema's extension properties to the given map of extensions. Passing an empty map has the effect of
2204+ * clearing all existing extension properties.
2205+ *
2206+ * @param extensions
2207+ * map containing the extension properties for this schema
2208+ *
2209+ * @see <a href="#schema-extensions">Schema Extensions</a>
2210+ */
2211+ @ Override
2212+ void setExtensions (Map <String , Object > extensions );
2213+
2214+ /**
2215+ * Checks whether an extension property with the given name is present on this schema.
2216+ *
2217+ * @param name
2218+ * the extension property name
2219+ *
2220+ * @return {@code true} if an extension with the given name is present, otherwise {@code false}
2221+ */
2222+ @ Override
2223+ default boolean hasExtension (String name ) {
2224+ return Extensible .super .hasExtension (name );
2225+ }
2226+
2227+ /**
2228+ * Returns the extension object with the given name from this schema.
2229+ *
2230+ * @param name
2231+ * the extension property name
2232+ *
2233+ * @return the corresponding extension object, or {@code null} if no extension with the given name is present
2234+ */
2235+ @ Override
2236+ default Object getExtension (String name ) {
2237+ return Extensible .super .getExtension (name );
2238+ }
21332239}
0 commit comments