Package io.smallrye.openapi.runtime.util
Class ModelUtil
- java.lang.Object
-
- io.smallrye.openapi.runtime.util.ModelUtil
-
public class ModelUtil extends Object
Class with some convenience methods useful for working with the OAI data model.- Author:
- eric.wittmann@gmail.com
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V> Map<String,V>add(String key, V value, Map<String,V> map, Supplier<Map<String,V>> factory)static <V> List<V>add(V value, List<V> list, Supplier<List<V>> factory)static voidaddTag(org.eclipse.microprofile.openapi.models.OpenAPI openApi, org.eclipse.microprofile.openapi.models.tags.Tag tag)Adds aTagto theOpenAPImodel.static org.eclipse.microprofile.openapi.models.Componentscomponents(org.eclipse.microprofile.openapi.models.OpenAPI openApi)Gets theComponentsfrom the OAI model.static <T extends org.eclipse.microprofile.openapi.models.Reference<T>>
Tdereference(org.eclipse.microprofile.openapi.models.OpenAPI openApi, T model)static <T> TgetComponent(org.eclipse.microprofile.openapi.models.OpenAPI openApi, String ref)Gets the component type specified by the given `ref` from the OpenAPI model.static List<org.eclipse.microprofile.openapi.models.media.Schema>getParameterSchemas(org.eclipse.microprofile.openapi.models.parameters.Parameter parameter)Returns the list ofSchemas defined for the givenParameter.static org.eclipse.microprofile.openapi.models.media.SchemagetPropertySchema(org.eclipse.microprofile.openapi.models.media.Schema schema, String name)Gets theSchemaassociated with the named property of the given schema.static StringnameFromRef(String ref)Returns the name component of the ref.static booleanparameterHasSchema(org.eclipse.microprofile.openapi.models.parameters.Parameter parameter)Returns true only if the givenParameterhas a schema defined for it.static org.eclipse.microprofile.openapi.models.Pathspaths(org.eclipse.microprofile.openapi.models.OpenAPI openApi)Gets thePathsfrom the OAI model.static <V> voidremove(List<V> list, V value)static <V> voidremove(Map<String,V> map, String key)static <V> List<V>replace(List<V> modified, UnaryOperator<List<V>> factory)static <V> Map<String,V>replace(Map<String,V> modified, UnaryOperator<Map<String,V>> factory)static booleanrequestBodyHasSchema(org.eclipse.microprofile.openapi.models.parameters.RequestBody requestBody)Returns true only if the givenRequestBodyhas a schema defined for it.static org.eclipse.microprofile.openapi.models.responses.APIResponsesresponses(org.eclipse.microprofile.openapi.models.Operation operation)Gets theAPIResponseschild model from the given operation.static voidsetParameterSchema(org.eclipse.microprofile.openapi.models.parameters.Parameter parameter, org.eclipse.microprofile.openapi.models.media.Schema schema)Sets the givenSchemaon the givenParameter.static voidsetRequestBodySchema(org.eclipse.microprofile.openapi.models.parameters.RequestBody requestBody, org.eclipse.microprofile.openapi.models.media.Schema schema, String[] mediaTypes)Sets the givenSchemaon the givenRequestBody.static <T> Tsupply(Supplier<T> source)static <V> List<V>unmodifiableList(List<V> list)static <V> Map<String,V>unmodifiableMap(Map<String,V> map)
-
-
-
Method Detail
-
addTag
public static void addTag(org.eclipse.microprofile.openapi.models.OpenAPI openApi, org.eclipse.microprofile.openapi.models.tags.Tag tag)Adds aTagto theOpenAPImodel. If a tag having the same name already exists in the model, the tags' attributes are merged, with the new tag's attributes overriding the value of any attributes specified on both.- Parameters:
openApi- the OpenAPI modeltag- a newTagto add
-
components
public static org.eclipse.microprofile.openapi.models.Components components(org.eclipse.microprofile.openapi.models.OpenAPI openApi)
Gets theComponentsfrom the OAI model. If it doesn't exist, creates it.- Parameters:
openApi- OpenAPI- Returns:
- Components
-
dereference
public static <T extends org.eclipse.microprofile.openapi.models.Reference<T>> T dereference(org.eclipse.microprofile.openapi.models.OpenAPI openApi, T model)
-
getComponent
public static <T> T getComponent(org.eclipse.microprofile.openapi.models.OpenAPI openApi, String ref)Gets the component type specified by the given `ref` from the OpenAPI model.- Type Parameters:
T- the type of the component map's entry values- Parameters:
openApi- containing OpenAPI modelref- reference path to retrieve- Returns:
- the component referenced by ref if present, otherwise null
-
paths
public static org.eclipse.microprofile.openapi.models.Paths paths(org.eclipse.microprofile.openapi.models.OpenAPI openApi)
Gets thePathsfrom the OAI model. If it doesn't exist, creates it.- Parameters:
openApi- OpenAPI- Returns:
- Paths
-
responses
public static org.eclipse.microprofile.openapi.models.responses.APIResponses responses(org.eclipse.microprofile.openapi.models.Operation operation)
Gets theAPIResponseschild model from the given operation. If it's null then it will be created and returned.- Parameters:
operation- Operation- Returns:
- APIResponses
-
getPropertySchema
public static org.eclipse.microprofile.openapi.models.media.Schema getPropertySchema(org.eclipse.microprofile.openapi.models.media.Schema schema, String name)Gets theSchemaassociated with the named property of the given schema. When the property is not found or when no properties exist on the schema, returns null.- Parameters:
schema- the schema from which to retrieve the propertyname- name of the property- Returns:
- schema for the named property if set, otherwise null
-
parameterHasSchema
public static boolean parameterHasSchema(org.eclipse.microprofile.openapi.models.parameters.Parameter parameter)
Returns true only if the givenParameterhas a schema defined for it. A schema can be defined either via the parameter's "schema" property, or any "content.*.schema" property.- Parameters:
parameter- Parameter- Returns:
- Whether the parameter has a schema
-
getParameterSchemas
public static List<org.eclipse.microprofile.openapi.models.media.Schema> getParameterSchemas(org.eclipse.microprofile.openapi.models.parameters.Parameter parameter)
Returns the list ofSchemas defined for the givenParameter. A schema can be defined either via the parameter's "schema" property, or any "content.*.schema" property.- Parameters:
parameter- Parameter- Returns:
- list of schemas, never null
-
setParameterSchema
public static void setParameterSchema(org.eclipse.microprofile.openapi.models.parameters.Parameter parameter, org.eclipse.microprofile.openapi.models.media.Schema schema)Sets the givenSchemaon the givenParameter. This is tricky because the paramater may EITHER have a schema property or it may have aContentchild which itself has zero or moreMediaTypechildren which will contain theSchema. The OpenAPI specification requires that a parameter have *either* a schema or a content, but not both.- Parameters:
parameter- Parameterschema- Schema
-
requestBodyHasSchema
public static boolean requestBodyHasSchema(org.eclipse.microprofile.openapi.models.parameters.RequestBody requestBody)
Returns true only if the givenRequestBodyhas a schema defined for it. A schema would be found within the request body's Content/MediaType children.- Parameters:
requestBody- RequestBody- Returns:
- Whether RequestBody has a schema
-
setRequestBodySchema
public static void setRequestBodySchema(org.eclipse.microprofile.openapi.models.parameters.RequestBody requestBody, org.eclipse.microprofile.openapi.models.media.Schema schema, String[] mediaTypes)Sets the givenSchemaon the givenRequestBody.- Parameters:
requestBody- RequestBodyschema- SchemamediaTypes- String array
-
nameFromRef
public static String nameFromRef(String ref)
Returns the name component of the ref.- Parameters:
ref- String- Returns:
- Name
-
replace
public static <V> Map<String,V> replace(Map<String,V> modified, UnaryOperator<Map<String,V>> factory)
-
add
public static <V> Map<String,V> add(String key, V value, Map<String,V> map, Supplier<Map<String,V>> factory)
-
replace
public static <V> List<V> replace(List<V> modified, UnaryOperator<List<V>> factory)
-
remove
public static <V> void remove(List<V> list, V value)
-
supply
public static <T> T supply(Supplier<T> source)
-
-