Package com.styra.opa.openapi.utils
Class Utils
java.lang.Object
com.styra.opa.openapi.utils.Utils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic final classstatic enumstatic final class -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallowIntrospection(Class<?> cls) static <T> TasType(EventStreamMessage x, com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) static Utils.HttpResponseCachedcache(HttpResponse<InputStream> response) Fully reads the body of the given response and caches it in memory.static voidcheckArgument(boolean expression, String message) static <T> TcheckNotNull(T object, String name) static HTTPRequestconfigureSecurity(HTTPRequest request, Object security) static booleancontentTypeMatches(String contentType, String pattern) static ObjectconvertToShape(Object o, Utils.JsonShape shape, com.fasterxml.jackson.core.type.TypeReference<?> typeReference) static com.fasterxml.jackson.databind.JavaTypeconvertToStringShape(com.fasterxml.jackson.databind.type.TypeFactory f, com.fasterxml.jackson.databind.JavaType a) static HttpRequest.Buildercopy(HttpRequest request) Returns anHttpRequest.Builderwhich is initialized with the state of the givenHttpRequest.static HttpRequest.Buildercopy(HttpRequest request, BiPredicate<String, String> filter) Returns anHttpRequest.Builderwhich is initialized with the state of the givenHttpRequest.static HTTPClientcreateTestHTTPClient(SpeakeasyHTTPClient client, String testName) static HTTPClientcreateTestHTTPClient(String testName) static Stringstatic <K,V> Map<K, V> emptyMapIfNull(Map<K, V> map) static StringenvironmentVariable(String name, String defaultValue) Internal use.static byte[]extractByteArrayFromBody(HttpResponse<InputStream> response) static <T> StringgenerateURL(Class<T> type, String baseURL, String path, Optional<? extends T> params, Map<String, Map<String, Map<String, Object>>> globals) static <T> StringgenerateURL(Class<T> type, String baseURL, String path, org.openapitools.jackson.nullable.JsonNullable<? extends T> params, Map<String, Map<String, Map<String, Object>>> globals) static <T> StringgenerateURL(Class<T> type, String baseURL, String path, T params, Map<String, Map<String, Map<String, Object>>> globals) static StringgenerateURL(String baseURL, String path) static <T> List<QueryParameter>getQueryParams(Class<T> type, Optional<? extends T> params, Map<String, Map<String, Map<String, Object>>> globals) static <T> List<QueryParameter>getQueryParams(Class<T> type, org.openapitools.jackson.nullable.JsonNullable<? extends T> params, Map<String, Map<String, Map<String, Object>>> globals) static <T> List<QueryParameter>static booleanisPresentAndNotNull(Optional<?> x) static booleanisPresentAndNotNull(org.openapitools.jackson.nullable.JsonNullable<?> x) static Stringjson(EventStreamMessage m, com.fasterxml.jackson.databind.ObjectMapper mapper, boolean dataIsPlainText) static com.fasterxml.jackson.databind.ObjectMappermapper()static ObjectpopulateGlobal(Object value, String fieldName, String paramType, Map<String, Map<String, Map<String, Object>>> globals) static StringprefixBearer(String authHeaderValue) static byte[]static byte[]readBytes(InputStream in) static byte[]static byte[]static <T> TreadDefaultOrConstValue(String name, String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) static voidrecordTest(String id) static booleanreferenceEquals(Object a, Object b) static Objectstatic SerializedBodyserializeRequestBody(Object request, String requestField, String serializationMethod, boolean nullable) static StringsessionKey(String... items) static voidsetSseSentinel(Object o, String value) static StringsortJSONObjectKeys(String json, String... fields) static StringReturns an equivalent url with query parameters sorted by name.static ObjectsortSerializedMaps(Object input, String regex, String delim) static booleanstatusCodeMatches(int statusCode, String... expectedStatusCodes) static booleanstatusCodeMatchesOne(int statusCode, String expectedStatusCode) static <T> Stream<T>stream(Callable<Optional<T>> first, Utils.Function<T, Optional<T>> next) static StringtemplateUrl(String url, Map<String, String> params) static byte[]static StringtoHex(byte[] bytes) static List<?>static <T> Optional<T>toOptional(org.openapitools.jackson.nullable.JsonNullable<T> a) static Stringstatic Stringstatic StringvalToString(Object value) static <T> TvalueOrElse(Optional<T> value, T valueIfNotPresent) static <T> TvalueOrElse(org.openapitools.jackson.nullable.JsonNullable<T> value, T valueIfNotPresent) static <T> TvalueOrElse(T value, T valueIfNotPresent) static <T> TvalueOrNull(Optional<T> value) static <T> TvalueOrNull(org.openapitools.jackson.nullable.JsonNullable<T> value) static <T> TvalueOrNull(T value)
-
Method Details
-
referenceEquals
-
generateURL
public static String generateURL(String baseURL, String path) throws IllegalArgumentException, IllegalAccessException -
generateURL
public static <T> String generateURL(Class<T> type, String baseURL, String path, org.openapitools.jackson.nullable.JsonNullable<? extends T> params, Map<String, Map<String, throws com.fasterxml.jackson.core.JsonProcessingException, IllegalArgumentException, IllegalAccessExceptionMap<String, Object>>> globals) - Throws:
com.fasterxml.jackson.core.JsonProcessingExceptionIllegalArgumentExceptionIllegalAccessException
-
generateURL
public static <T> String generateURL(Class<T> type, String baseURL, String path, Optional<? extends T> params, Map<String, Map<String, throws com.fasterxml.jackson.core.JsonProcessingException, IllegalArgumentException, IllegalAccessExceptionMap<String, Object>>> globals) - Throws:
com.fasterxml.jackson.core.JsonProcessingExceptionIllegalArgumentExceptionIllegalAccessException
-
generateURL
public static <T> String generateURL(Class<T> type, String baseURL, String path, T params, Map<String, Map<String, throws IllegalArgumentException, IllegalAccessException, com.fasterxml.jackson.core.JsonProcessingExceptionMap<String, Object>>> globals) - Throws:
IllegalArgumentExceptionIllegalAccessExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
contentTypeMatches
-
allowIntrospection
-
serializeRequestBody
public static SerializedBody serializeRequestBody(Object request, String requestField, String serializationMethod, boolean nullable) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, UnsupportedOperationException, IOException -
getQueryParams
public static <T> List<QueryParameter> getQueryParams(Class<T> type, Optional<? extends T> params, Map<String, Map<String, throws ExceptionMap<String, Object>>> globals) - Throws:
Exception
-
getQueryParams
public static <T> List<QueryParameter> getQueryParams(Class<T> type, org.openapitools.jackson.nullable.JsonNullable<? extends T> params, Map<String, Map<String, throws ExceptionMap<String, Object>>> globals) - Throws:
Exception
-
getQueryParams
public static <T> List<QueryParameter> getQueryParams(Class<T> type, T params, Map<String, Map<String, throws ExceptionMap<String, Object>>> globals) - Throws:
Exception
-
configureSecurity
- Throws:
Exception
-
templateUrl
-
getHeadersFromMetadata
public static Map<String,List<String>> getHeadersFromMetadata(Object headers, Map<String, Map<String, throws ExceptionMap<String, Object>>> globals) - Throws:
Exception
-
valToString
-
prefixBearer
-
populateGlobal
-
checkNotNull
-
checkArgument
-
emptyMapIfNull
-
toString
-
resolveOptionals
-
toList
-
readDefaultOrConstValue
-
extractByteArrayFromBody
public static byte[] extractByteArrayFromBody(HttpResponse<InputStream> response) throws IOException - Throws:
IOException
-
toByteArrayAndClose
- Throws:
IOException
-
toUtf8AndClose
- Throws:
IOException
-
convertToShape
public static Object convertToShape(Object o, Utils.JsonShape shape, com.fasterxml.jackson.core.type.TypeReference<?> typeReference) -
convertToStringShape
public static com.fasterxml.jackson.databind.JavaType convertToStringShape(com.fasterxml.jackson.databind.type.TypeFactory f, com.fasterxml.jackson.databind.JavaType a) -
stream
-
statusCodeMatches
-
statusCodeMatchesOne
-
copy
Returns anHttpRequest.Builderwhich is initialized with the state of the givenHttpRequest.- Parameters:
request- request to copy- Returns:
- a builder initialized with values from
request
-
copy
Returns anHttpRequest.Builderwhich is initialized with the state of the givenHttpRequest.- Parameters:
request- request to copyfilter- selects which header key-values to include in the copied request- Returns:
- a builder initialized with values from
request
-
mapper
public static com.fasterxml.jackson.databind.ObjectMapper mapper() -
asType
public static <T> T asType(EventStreamMessage x, com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) -
json
public static String json(EventStreamMessage m, com.fasterxml.jackson.databind.ObjectMapper mapper, boolean dataIsPlainText) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
cache
Fully reads the body of the given response and caches it in memory. The returned response has utility methods to view the body (bodyAsUtf8(), bodyAsBytes()and thebody()method can be called multiple times, each returning a freshInputStreamthat will read from the cached byte array.This method is most likely to be used in a diagnostic/logging situtation so that the contents of a response can be viewed without affecting processing. Using this method with a very large body may be problematic in terms of memory use.
- Parameters:
response- response to cache- Returns:
- response with a cached body
- Throws:
IOException
-
readBytes
-
readBytes
-
readBytesAndClose
-
readBytes
-
toHex
-
discriminatorToString
-
recordTest
-
sortQueryParameters
Returns an equivalent url with query parameters sorted by name. Sort is stable in that parameters with the same name will not be reordered.- Parameters:
url- input- Returns:
- url with query parameters sorted by name
-
sortSerializedMaps
-
isPresentAndNotNull
-
isPresentAndNotNull
public static boolean isPresentAndNotNull(org.openapitools.jackson.nullable.JsonNullable<?> x) -
setSseSentinel
-
sessionKey
-
createTestHTTPClient
-
createTestHTTPClient
-
environmentVariable
Internal use. Returns the system property withkey = "env." + nameand if doesn't exist returns the value of the environment variable with the given name of if it doesn't exist returnsdefaultValue.- Parameters:
name- variable namedefaultValue- default value if system property and environment variable don't exist- Returns:
- system property with name prepended with ".env" or environment variable of given name or default value
-
toOptional
-
sortJSONObjectKeys
-
valueOrElse
public static <T> T valueOrElse(T value, T valueIfNotPresent) -
valueOrElse
-
valueOrElse
public static <T> T valueOrElse(org.openapitools.jackson.nullable.JsonNullable<T> value, T valueIfNotPresent) -
valueOrNull
public static <T> T valueOrNull(T value) -
valueOrNull
-
valueOrNull
public static <T> T valueOrNull(org.openapitools.jackson.nullable.JsonNullable<T> value)
-