Class ModelUtils


  • public final class ModelUtils
    extends Object
    • 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.HttpMethod applied 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 new Operation, and inserts it into the PathItem.
        Parameters:
        pathItem - the PathItem to add the Operation to.
        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)
      • getAccessorName

        public static String getAccessorName​(String fieldName)
      • 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 the Schema.SchemaType that corresponds to a given class.
        Parameters:
        typeName - the class to map.
        Returns:
        the schema type the class corresponds to.
      • 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 a Schema.SchemaType that 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.SchemaType that 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)
      • getSimpleName

        public static String getSimpleName​(String fqn)
      • readOnlyView

        public static <K,​V> Map<K,​V> readOnlyView​(Map<K,​V> map)
      • readOnlyView

        public static <T> List<T> readOnlyView​(List<T> list)
      • 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()
      • createMap

        public static <K,​V> Map<K,​V> createMap​(Map<? extends K,​? extends V> items)
      • createOrderedMap

        public static <K,​V> Map<K,​V> createOrderedMap()
      • createOrderedMap

        public static <K,​V> Map<K,​V> createOrderedMap​(Map<? extends K,​? extends V> items)