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 > {
@@ -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}
0 commit comments