Class ModelUtils
- java.lang.Object
-
- fish.payara.microprofile.openapi.impl.model.util.ModelUtils
-
public final class ModelUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringUNKNOWN_ELEMENT_NAMEThe name of a variable in the model tree that is unrecognised.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidapplyReference(org.eclipse.microprofile.openapi.models.Reference<?> referee, String reference)Set the reference property of an object, and clear every other field.static Map<String,Set<String>>buildEndpoints(Map<String,Set<String>> original, String contextRoot, Set<String> paths)static <T> List<T>createList()static <T> List<T>createList(Collection<? extends T> items)static <K,V>
Map<K,V>createMap()static <K,V>
Map<K,V>createMap(Map<? extends K,? extends V> items)static <K,V>
Map<K,V>createOrderedMap()static <K,V>
Map<K,V>createOrderedMap(Map<? extends K,? extends V> items)static <T> voidextractAnnotations(org.glassfish.hk2.classmodel.reflect.AnnotationModel annotationModel, ApiContext context, String type, String key, BiFunction<org.glassfish.hk2.classmodel.reflect.AnnotationModel,ApiContext,T> factory, BiConsumer<String,T> wrapperAddFunction)static <T> voidextractAnnotations(org.glassfish.hk2.classmodel.reflect.AnnotationModel annotationModel, ApiContext context, String type, BiFunction<org.glassfish.hk2.classmodel.reflect.AnnotationModel,ApiContext,T> factory, Consumer<T> wrapperAddFunction)static org.eclipse.microprofile.openapi.models.OperationfindOperation(OpenApiContext context, org.eclipse.microprofile.openapi.models.OpenAPI api, org.glassfish.hk2.classmodel.reflect.MethodModel method, String path)static StringgetAccessorName(String fieldName)static org.eclipse.microprofile.openapi.models.PathItem.HttpMethodgetHttpMethod(OpenApiContext context, org.glassfish.hk2.classmodel.reflect.MethodModel method)static org.eclipse.microprofile.openapi.models.PathItem.HttpMethodgetHttpMethod(String method)static org.eclipse.microprofile.openapi.models.OperationgetOrCreateOperation(org.eclipse.microprofile.openapi.models.PathItem pathItem, org.eclipse.microprofile.openapi.models.PathItem.HttpMethod httpMethod)Creates a newOperation, and inserts it into thePathItem.static StringgetParameterName(ApiContext context, org.glassfish.hk2.classmodel.reflect.Parameter parameter)static org.eclipse.microprofile.openapi.models.parameters.Parameter.IngetParameterType(ApiContext context, org.glassfish.hk2.classmodel.reflect.Parameter parameter)static org.eclipse.microprofile.openapi.models.media.Schema.SchemaTypegetParentSchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType type1, org.eclipse.microprofile.openapi.models.media.Schema.SchemaType type2)Finds aSchema.SchemaTypethat can represent both of the given types.static StringgetSchemaName(ApiContext context, org.glassfish.hk2.classmodel.reflect.AnnotatedElement type)static org.eclipse.microprofile.openapi.models.media.Schema.SchemaTypegetSchemaType(String typeName, ApiContext context)Finds theSchema.SchemaTypethat corresponds to a given class.static org.eclipse.microprofile.openapi.models.media.Schema.SchemaTypegetSchemaType(org.glassfish.hk2.classmodel.reflect.ParameterizedType type, ApiContext context)static StringgetSimpleName(String fqn)static booleanisAnnotationNull(Annotation annotation)static booleanisMap(String typeName, ApiContext context)static booleanisRequestBody(ApiContext context, org.glassfish.hk2.classmodel.reflect.Parameter parameter)static booleanisVoid(org.glassfish.hk2.classmodel.reflect.ParameterizedType type)static <T> voidmerge(T from, T to, boolean override)static <T> voidmergeImmutableList(List<T> from, List<T> to, Consumer<List<T>> setFunction)static BooleanmergeProperty(boolean current, boolean offer, boolean override)static BooleanmergeProperty(boolean current, Boolean offer, boolean override)static <E> EmergeProperty(E current, E offer, boolean override)static BooleanmergeProperty(Boolean current, boolean offer, boolean override)static StringnormaliseUrl(String path)Normalises a path string.static <T> voidoverwrite(T from, T to)static <T> List<T>readOnlyView(List<T> list)static <K,V>
Map<K,V>readOnlyView(Map<K,V> map)static voidremoveOperation(org.eclipse.microprofile.openapi.models.PathItem pathItem, org.eclipse.microprofile.openapi.models.Operation operation)
-
-
-
Field Detail
-
UNKNOWN_ELEMENT_NAME
public static final String UNKNOWN_ELEMENT_NAME
The name of a variable in the model tree that is unrecognised.- See Also:
- Constant Field Values
-
-
Method Detail
-
normaliseUrl
public static String normaliseUrl(String path)
Normalises a path string. A normalised path has:- no multiple slashes.
- no trailing slash.
- Parameters:
path- the path to be normalised.
-
getHttpMethod
public static org.eclipse.microprofile.openapi.models.PathItem.HttpMethod getHttpMethod(OpenApiContext context, org.glassfish.hk2.classmodel.reflect.MethodModel method)
- Parameters:
context-method- the method to analyse.- Returns:
- the
PathItem.HttpMethodapplied to this method, or null if there is none.
-
getHttpMethod
public static org.eclipse.microprofile.openapi.models.PathItem.HttpMethod getHttpMethod(String method)
-
getOrCreateOperation
public static org.eclipse.microprofile.openapi.models.Operation getOrCreateOperation(org.eclipse.microprofile.openapi.models.PathItem pathItem, org.eclipse.microprofile.openapi.models.PathItem.HttpMethod httpMethod)Creates a newOperation, and inserts it into thePathItem.- Parameters:
pathItem- thePathItemto add theOperationto.httpMethod- the HTTP method of the operation to add.- Returns:
- the newly created
Operation, or the existing operation if available.
-
findOperation
public static org.eclipse.microprofile.openapi.models.Operation findOperation(OpenApiContext context, org.eclipse.microprofile.openapi.models.OpenAPI api, org.glassfish.hk2.classmodel.reflect.MethodModel method, String path)
-
removeOperation
public static void removeOperation(org.eclipse.microprofile.openapi.models.PathItem pathItem, org.eclipse.microprofile.openapi.models.Operation operation)
-
getSchemaName
public static String getSchemaName(ApiContext context, org.glassfish.hk2.classmodel.reflect.AnnotatedElement type)
-
getSchemaType
public static org.eclipse.microprofile.openapi.models.media.Schema.SchemaType getSchemaType(org.glassfish.hk2.classmodel.reflect.ParameterizedType type, ApiContext context)
-
getSchemaType
public static org.eclipse.microprofile.openapi.models.media.Schema.SchemaType getSchemaType(String typeName, ApiContext context)
Finds theSchema.SchemaTypethat corresponds to a given class.- Parameters:
typeName- the class to map.- Returns:
- the schema type the class corresponds to.
-
isMap
public static boolean isMap(String typeName, ApiContext context)
-
getParentSchemaType
public static org.eclipse.microprofile.openapi.models.media.Schema.SchemaType getParentSchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType type1, org.eclipse.microprofile.openapi.models.media.Schema.SchemaType type2)Finds aSchema.SchemaTypethat can represent both of the given types. If one of the input values are null, this function returns the other. If both are null, this function returns null.- Parameters:
type1- the first schema type.type2- the second schema type.- Returns:
- a
Schema.SchemaTypethat can represent both.
-
isRequestBody
public static boolean isRequestBody(ApiContext context, org.glassfish.hk2.classmodel.reflect.Parameter parameter)
-
getParameterType
public static org.eclipse.microprofile.openapi.models.parameters.Parameter.In getParameterType(ApiContext context, org.glassfish.hk2.classmodel.reflect.Parameter parameter)
-
getParameterName
public static String getParameterName(ApiContext context, org.glassfish.hk2.classmodel.reflect.Parameter parameter)
-
isVoid
public static boolean isVoid(org.glassfish.hk2.classmodel.reflect.ParameterizedType type)
-
isAnnotationNull
public static boolean isAnnotationNull(Annotation annotation)
-
extractAnnotations
public static <T> void extractAnnotations(org.glassfish.hk2.classmodel.reflect.AnnotationModel annotationModel, ApiContext context, String type, String key, BiFunction<org.glassfish.hk2.classmodel.reflect.AnnotationModel,ApiContext,T> factory, BiConsumer<String,T> wrapperAddFunction)
-
extractAnnotations
public static <T> void extractAnnotations(org.glassfish.hk2.classmodel.reflect.AnnotationModel annotationModel, ApiContext context, String type, BiFunction<org.glassfish.hk2.classmodel.reflect.AnnotationModel,ApiContext,T> factory, Consumer<T> wrapperAddFunction)
-
mergeImmutableList
public static <T> void mergeImmutableList(List<T> from, List<T> to, Consumer<List<T>> setFunction)
-
mergeProperty
public static Boolean mergeProperty(Boolean current, boolean offer, boolean override)
-
mergeProperty
public static Boolean mergeProperty(boolean current, Boolean offer, boolean override)
-
mergeProperty
public static Boolean mergeProperty(boolean current, boolean offer, boolean override)
-
mergeProperty
public static <E> E mergeProperty(E current, E offer, boolean override)
-
applyReference
public static void applyReference(org.eclipse.microprofile.openapi.models.Reference<?> referee, String reference)Set the reference property of an object, and clear every other field.
-
overwrite
public static <T> void overwrite(T from, T to)
-
merge
public static <T> void merge(T from, T to, boolean override)
-
createList
public static <T> List<T> createList()
-
createList
public static <T> List<T> createList(Collection<? extends T> items)
-
createMap
public static <K,V> Map<K,V> createMap()
-
createOrderedMap
public static <K,V> Map<K,V> createOrderedMap()
-
createOrderedMap
public static <K,V> Map<K,V> createOrderedMap(Map<? extends K,? extends V> items)
-
-