From 5cb26f2d7f6baedcbfc46521dca6ad795624b546 Mon Sep 17 00:00:00 2001 From: Andrew Rouse Date: Thu, 28 Mar 2024 15:30:56 +0000 Subject: [PATCH] Schema model: support arbitrary properties --- .../openapi/models/media/Schema.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/api/src/main/java/org/eclipse/microprofile/openapi/models/media/Schema.java b/api/src/main/java/org/eclipse/microprofile/openapi/models/media/Schema.java index 0a3941e3..8c083205 100644 --- a/api/src/main/java/org/eclipse/microprofile/openapi/models/media/Schema.java +++ b/api/src/main/java/org/eclipse/microprofile/openapi/models/media/Schema.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; +import org.eclipse.microprofile.openapi.OASFactory; import org.eclipse.microprofile.openapi.models.Constructible; import org.eclipse.microprofile.openapi.models.Extensible; import org.eclipse.microprofile.openapi.models.ExternalDocumentation; @@ -2100,4 +2101,83 @@ default Schema examples(List examples) { */ void removeExample(Object example); + /** + * Gets a schema property by name. + *

+ * Allows access to arbitrary properties in a schema object, allowing use of alternative schema dialects which use + * different property names (or the same property names with different data types). + *

+ * When using the standard schema dialect, this method can be used to retrieve values set by other methods. E.g. + * + *

+     * {@code
+     * schema.setMinimum(new BigDecimal(3));
+     * BigDecimal minimum = (BigDecimal) schema.get("minimum"); // returns 3
+     * }
+     * 
+ * + * @param propertyName + * the property name + * @return the value of the named property, or {@code null} if a property with the given name is not set + */ + Object get(String propertyName); + + /** + * Sets a schema property. + *

+ * Allows the modifications of arbitrary schema properties in a schema properties, allowing use of alternative + * schema dialects which use different property names (or the same property names with different data types). + *

+ * Passing {@code null} as the {@code value} removes the property from the schema object. + *

+ * {@code value} must be one of the following types, otherwise non-portable behavior results: + *

+ * + *

+ * When using the standard schema dialect, values set by this method can be retrieved by other methods. E.g. + * + *

+     * {@code
+     * schema.set("minimum", new BigDecimal(3));
+     * BigDecimal minimum = schema.getMinimum(); // returns 3
+     * }
+     * 
+ * + * @param propertyName + * the property name + * @param the + * value to set + */ + void set(String propertyName, Object value); + + /** + * Gets all properties of a schema. + *

+ * Equivalent to calling {@link #get(String)} for each property and putting them all into a {@code Map}. + * + * @return a {@code Map} of property names to their corresponding values + */ + Map getAll(); + + /** + * Sets all properties of a schema. + *

+ * Equivalent to clearing all properties and then setting each property with {@link #set(String, Object)}. + * + * @param allProperties + * the properties to set. Each value in the map must be valid according to the rules in + * {@link #set(String, Object)} + */ + void setAll(Map allProperties); }