Package com.boomi.connector.openapi.util
Class OpenAPIUtil
- java.lang.Object
-
- com.boomi.connector.openapi.util.OpenAPIUtil
-
public class OpenAPIUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JsonNode
buildSchema(io.swagger.v3.oas.models.media.Schema<?> schema, io.swagger.v3.oas.models.OpenAPI api, OpenAPIParseOption parseOption)
Build a JSON schema based on the providedSchema
.static String
getDelimiter(String name, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style)
Returns a delimiterString
corresponding to the Open Api parameter style enum and parameter name.static String
getFirstRequestContentType(io.swagger.v3.oas.models.Operation operation)
Fetches the first request content type from the given operation.static io.swagger.v3.oas.models.PathItem.HttpMethod
getHttpMethod(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Retrieves the HTTP method based off of the "name" field of the operationstatic JSONUtil.NodeType
getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema)
Fetches theJSONUtil.NodeType
based off of the Schema definitionstatic JSONUtil.NodeType
getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema, JSONUtil.NodeType defaultValue)
Fetches theJSONUtil.NodeType
based off of the schema definition.static io.swagger.v3.oas.models.Operation
getOperation(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.PathItem.HttpMethod method, String path)
Fetch the Operation by path and method.static io.swagger.v3.oas.models.Operation
getOperation(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Retrieves the operation by the "name" field of the operation.static List<io.swagger.v3.oas.models.parameters.Parameter>
getParametersFromOperation(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.Operation operation)
Retrieves all of the valid supported parametersOpenAPIParameterType
for this operation.static List<io.swagger.v3.oas.models.parameters.Parameter>
getParametersFromOperationByType(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.Operation operation, OpenAPIParameterType filterType)
Retrieves the specifiedOpenAPIParameterType
parameter for this operation.static String
getPath(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Returns the path based off of the Operation IDprotected static io.swagger.v3.oas.models.Paths
getPaths(io.swagger.v3.oas.models.OpenAPI api)
static io.swagger.v3.oas.models.parameters.RequestBody
getRequestBody(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.PathItem.HttpMethod method, String path)
Retrieves the request body by http method and path.static io.swagger.v3.oas.models.parameters.RequestBody
getRequestBody(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Retrieves the request body for the operation, based off of the "name" field of the operation.static io.swagger.v3.oas.models.media.Content
getRequestContent(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.PathItem.HttpMethod method, String path)
Fetches the request content type based off of thePathItem.HttpMethod
and the path.static io.swagger.v3.oas.models.media.Content
getResponseContent(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.Operation operation, Pattern pattern)
Attempts to fetch the first Response content based off of a response code pattern.static io.swagger.v3.oas.models.media.Schema<?>
getSchema(io.swagger.v3.oas.models.media.Content content)
Fetches the schema object from the givenContent
.static io.swagger.v3.oas.models.media.Schema<?>
getSchema(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.media.Content content)
Fetches the schema object fromContent
type map.static io.swagger.v3.oas.models.media.Schema<?>
getSchema(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.media.Schema<?> schema)
Fetches the schema, if this is a referenced / shared schema, then the reference will be resolved for youstatic io.swagger.v3.oas.models.media.Schema<?>
getSchema(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.RequestBody request)
Fetches the schema for the request body.static String
getSerializedHeaderParameter(String name, String parameterValue, OpenAPIDataType dataType)
Updates input header parameter value according to the data type value from Open Api Specification.static String
getSerializedPathParameter(String name, String parameterValue, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style, boolean explode, OpenAPIDataType dataType)
Updates input path parameter value according to the style, explode and data type values from Open Api Specification.static List<Map.Entry<String,String>>
getSerializedQueryParameter(String name, String parameterValue, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style, boolean explode, OpenAPIDataType dataType)
Updates input query parameter value according to the style, explode and data type values from Open Api Specification.static io.swagger.v3.oas.models.parameters.Parameter
getSharedParameter(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared parameter under the "components" section based off of the $ref valuestatic io.swagger.v3.oas.models.parameters.RequestBody
getSharedRequest(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared response under the "components" section based off of the $ref valuestatic io.swagger.v3.oas.models.responses.ApiResponse
getSharedResponse(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared response under the "components" section based off of the $ref valuestatic io.swagger.v3.oas.models.media.Schema<?>
getSharedSchema(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared schema under the "components" section based off of the $ref value.static boolean
isParameterSupported(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.Parameter parameter)
Returns true if the parameter is supported.static boolean
isRequestBodyRequired(io.swagger.v3.oas.models.Operation operation)
Returns a boolean value of the "required" attribute from request body.static boolean
isSimpleSchema(io.swagger.v3.oas.models.media.Schema<?> schema)
Returns true ifSchema.getType()
is Boolean, Number, Integer, String.static boolean
isStructured(io.swagger.v3.oas.models.media.Content content)
Content is considered structured if the schema associated with it is not null.static io.swagger.v3.oas.models.parameters.Parameter
resolveParameter(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.Parameter parameter)
If the incoming parameter is a reference parameter, then this will resolve and return the reference parameter.static io.swagger.v3.oas.models.parameters.RequestBody
resolveRequestBody(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.RequestBody requestBody)
If the incoming response is a reference request, then this will resolve and return the reference request.static io.swagger.v3.oas.models.responses.ApiResponse
resolveResponse(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.responses.ApiResponse response)
If the incoming response is a reference response, then this will resolve and return the reference response.static void
validateSpecFileLocation(String spec)
Validates that the spec file path passed in is usable
-
-
-
Method Detail
-
getSchema
public static io.swagger.v3.oas.models.media.Schema<?> getSchema(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.RequestBody request)
Fetches the schema for the request body. If this is a referenced / shared schema, then the reference will be resolved for you- Parameters:
api
- the api definitionrequest
- the selected request- Returns:
- the actual schema definition
-
getSchema
public static io.swagger.v3.oas.models.media.Schema<?> getSchema(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.media.Content content)
Fetches the schema object fromContent
type map. Currently only supports extracting schema objects fromMediaType
of typeCONTENT_TYPE
. Also resolves any $ref pointers in the schema if present.- Parameters:
api
- the api definitioncontent
- the selected content- Returns:
- the actual schema
-
getSchema
public static io.swagger.v3.oas.models.media.Schema<?> getSchema(io.swagger.v3.oas.models.media.Content content)
Fetches the schema object from the givenContent
. This will NOT resolve $ref for you as just has knowledge of the incomingContent
object. Returns null if no content is found withinContent
- Parameters:
content
- the selected content- Returns:
- the content
-
getSchema
public static io.swagger.v3.oas.models.media.Schema<?> getSchema(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.media.Schema<?> schema)
Fetches the schema, if this is a referenced / shared schema, then the reference will be resolved for you- Parameters:
api
- the api definitionschema
- the selected schema- Returns:
- the actual schema definition
-
getSharedSchema
public static io.swagger.v3.oas.models.media.Schema<?> getSharedSchema(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared schema under the "components" section based off of the $ref value.- Parameters:
api
- the api definitionref
- the reference path- Returns:
- the shared schema
-
getSharedParameter
public static io.swagger.v3.oas.models.parameters.Parameter getSharedParameter(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared parameter under the "components" section based off of the $ref value- Parameters:
api
- the api definitionref
- the reference path- Returns:
- the shared parameter
-
getNodeType
public static JSONUtil.NodeType getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema)
Fetches theJSONUtil.NodeType
based off of the Schema definition- Parameters:
schema
- the selected schema- Returns:
- the NodeType
-
getNodeType
public static JSONUtil.NodeType getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema, JSONUtil.NodeType defaultValue)
Fetches theJSONUtil.NodeType
based off of the schema definition. Will use default if not given / invalid.- Parameters:
schema
- the selected schemadefaultValue
- default value if node type isn't given- Returns:
- the nodetype
-
isStructured
public static boolean isStructured(io.swagger.v3.oas.models.media.Content content)
Content is considered structured if the schema associated with it is not null.- Parameters:
content
- the selected content- Returns:
- true if content is Structured, false otherwise.
-
isSimpleSchema
public static boolean isSimpleSchema(io.swagger.v3.oas.models.media.Schema<?> schema)
Returns true ifSchema.getType()
is Boolean, Number, Integer, String. Returns false otherwise- Parameters:
schema
-- Returns:
- true if it's a simple schema, false otherwise
-
getResponseContent
public static io.swagger.v3.oas.models.media.Content getResponseContent(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.Operation operation, Pattern pattern)
Attempts to fetch the first Response content based off of a response code pattern. If a response code pattern is not matched, then it will attempt to return the value from the "default" in the response. null if nothing is found.- Parameters:
api
- the api definitionoperation
- the selected operationpattern
- the response pattern- Returns:
- the Content
-
resolveResponse
public static io.swagger.v3.oas.models.responses.ApiResponse resolveResponse(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.responses.ApiResponse response)
If the incoming response is a reference response, then this will resolve and return the reference response. Otherwise, it will return the response itself- Parameters:
api
- the api definitionresponse
- the response- Returns:
- the shared parameter
-
getSharedResponse
public static io.swagger.v3.oas.models.responses.ApiResponse getSharedResponse(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared response under the "components" section based off of the $ref value- Parameters:
api
- the api definitionref
- the reference path- Returns:
- the shared parameter
-
resolveRequestBody
public static io.swagger.v3.oas.models.parameters.RequestBody resolveRequestBody(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.RequestBody requestBody)
If the incoming response is a reference request, then this will resolve and return the reference request. Otherwise, it will return the request itself- Parameters:
api
- the api definitionrequestBody
- the requestBody- Returns:
- the shared parameter
-
getSharedRequest
public static io.swagger.v3.oas.models.parameters.RequestBody getSharedRequest(io.swagger.v3.oas.models.OpenAPI api, String ref)
Retrieves the shared response under the "components" section based off of the $ref value- Parameters:
api
- the api definitionref
- the reference path- Returns:
- the shared parameter
-
getOperation
public static io.swagger.v3.oas.models.Operation getOperation(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.PathItem.HttpMethod method, String path)
Fetch the Operation by path and method. This will return null if no operations were found. This will throw an IllegalArgument exception when the following holds true: 1. Invalid path on the Api specs 2. Invalid Method passed in- Parameters:
api
- the api definitionmethod
- the selected http methodpath
- the selected path- Returns:
- the operation
-
getParametersFromOperation
public static List<io.swagger.v3.oas.models.parameters.Parameter> getParametersFromOperation(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.Operation operation)
Retrieves all of the valid supported parametersOpenAPIParameterType
for this operation. If the parameters are reference parameters ($ref), then this utility will resolve the parameter reference for you.- Parameters:
api
- the api definitionoperation
- the selected operation- Returns:
- list of parameters
-
getParametersFromOperationByType
public static List<io.swagger.v3.oas.models.parameters.Parameter> getParametersFromOperationByType(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.Operation operation, OpenAPIParameterType filterType)
Retrieves the specifiedOpenAPIParameterType
parameter for this operation. If the parameters are reference parameters ($ref), then this utility will resolve the parameter reference for you.- Parameters:
api
- the api definitionoperation
- the selected operationfilterType
- the parameter to filter upon- Returns:
- list of parameters
-
resolveParameter
public static io.swagger.v3.oas.models.parameters.Parameter resolveParameter(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.Parameter parameter)
If the incoming parameter is a reference parameter, then this will resolve and return the reference parameter. Otherwise, it will return the parameter itself.- Parameters:
api
- the api definitionparameter
- the parameter to resolve- Returns:
- the resolved parameter
-
isParameterSupported
public static boolean isParameterSupported(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.parameters.Parameter parameter)
Returns true if the parameter is supported. The following are not supported: Cookie Parameters Header Parameters with values of: "ACCEPT", "CONTENT-TYPE", "AUTHORIZATION"- Parameters:
api
-parameter
-- Returns:
- true if the parameter is supported, false otherwise
-
getOperation
public static io.swagger.v3.oas.models.Operation getOperation(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Retrieves the operation by the "name" field of the operation.- Parameters:
api
- the api definitionoperationId
- the operation's id- Returns:
- the operation
-
getHttpMethod
public static io.swagger.v3.oas.models.PathItem.HttpMethod getHttpMethod(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Retrieves the HTTP method based off of the "name" field of the operation- Parameters:
api
- the api definitionoperationId
- the operation id- Returns:
- the httpMethod
-
getRequestBody
public static io.swagger.v3.oas.models.parameters.RequestBody getRequestBody(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.PathItem.HttpMethod method, String path)
Retrieves the request body by http method and path.- Parameters:
api
- the api definitionmethod
- the selected http methodpath
- the selected path- Returns:
- the RequestBody
-
getRequestBody
public static io.swagger.v3.oas.models.parameters.RequestBody getRequestBody(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Retrieves the request body for the operation, based off of the "name" field of the operation.- Parameters:
api
- the api definitionoperationId
- the operation id- Returns:
- the RequestBody
-
isRequestBodyRequired
public static boolean isRequestBodyRequired(io.swagger.v3.oas.models.Operation operation)
Returns a boolean value of the "required" attribute from request body. Returns false if request body is null/missing or "required" attribute is null/missing.- Parameters:
operation
- the selected operation- Returns:
- true if the request body is required, false otherwise
-
getRequestContent
public static io.swagger.v3.oas.models.media.Content getRequestContent(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.PathItem.HttpMethod method, String path)
Fetches the request content type based off of thePathItem.HttpMethod
and the path. If no content is given, then an empty content is returned.- Parameters:
api
- the api definitionmethod
- the selected http methodpath
- the selected path- Returns:
- the Content
-
getFirstRequestContentType
public static String getFirstRequestContentType(io.swagger.v3.oas.models.Operation operation)
Fetches the first request content type from the given operation. If the request body is not defined or the content type is not given, then a null string is returned.- Parameters:
operation
- the selected operation- Returns:
- the request content type as String
-
getPath
public static String getPath(io.swagger.v3.oas.models.OpenAPI api, String operationId)
Returns the path based off of the Operation ID- Parameters:
api
- the api definitionoperationId
- the selected operation id- Returns:
- the Path
-
getPaths
protected static io.swagger.v3.oas.models.Paths getPaths(io.swagger.v3.oas.models.OpenAPI api)
-
getSerializedPathParameter
public static String getSerializedPathParameter(String name, String parameterValue, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style, boolean explode, OpenAPIDataType dataType)
Updates input path parameter value according to the style, explode and data type values from Open Api Specification. Refer Open Api Parameter Serialization doc for more information.- Parameters:
name
- Path parameter name.parameterValue
- Path parameter value.style
- Path parameter style.explode
- boolean explode property from OpenAPI spec: specifies whether arrays and objects should generate separate parameters for each array item or object property.dataType
-OpenAPIDataType
of the parameter.- Returns:
- Updated path parameter value based on the style, explode and data type values.
-
getSerializedQueryParameter
public static List<Map.Entry<String,String>> getSerializedQueryParameter(String name, String parameterValue, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style, boolean explode, OpenAPIDataType dataType)
Updates input query parameter value according to the style, explode and data type values from Open Api Specification. Refer Open Api Parameter Serialization doc for more information.- Parameters:
name
- Query parameter name.parameterValue
- Query parameter value.style
- Query parameter style.explode
- boolean explode property from OpenAPI spec: specifies whether arrays and objects should generate separate parameters for each array item or object property.dataType
-OpenAPIDataType
of the parameter.- Returns:
- Updated query parameter value based on the style, explode and data type values.
-
getSerializedHeaderParameter
public static String getSerializedHeaderParameter(String name, String parameterValue, OpenAPIDataType dataType)
Updates input header parameter value according to the data type value from Open Api Specification. Refer Open Api Parameter Serialization doc for more information.- Parameters:
name
- Header parameter name.parameterValue
- Header parameter value.dataType
-OpenAPIDataType
of the parameter.- Returns:
- Updated header parameter value based on the data type values.
-
getDelimiter
public static String getDelimiter(String name, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style)
Returns a delimiterString
corresponding to the Open Api parameter style enum and parameter name.- Parameters:
name
- Open Api Parameter Name.style
- Open Api Parameter Style Enum.- Returns:
- the delimiter
-
buildSchema
public static JsonNode buildSchema(io.swagger.v3.oas.models.media.Schema<?> schema, io.swagger.v3.oas.models.OpenAPI api, OpenAPIParseOption parseOption)
Build a JSON schema based on the providedSchema
. Currently only supports building schemas with root type of "object". Supports building schemas withComposedSchema
elements by resolving "allOf", "anyOf", "oneOf" keywords used to combine schemas.- Parameters:
schema
- the schemaapi
- the OpenAPI specificationparseOption
- parse options for the spec- Returns:
- JsonNode containing the schema
- Throws:
IllegalArgumentException
- if the schema is nullIllegalArgumentException
- ifSchema.getType()
is notJSONUtil.NodeType.OBJECT
-
validateSpecFileLocation
public static void validateSpecFileLocation(String spec)
Validates that the spec file path passed in is usable- Parameters:
spec
- path to spec file- Throws:
IllegalArgumentException
- if the spec file path is not referencing a file that is readable and accessible by the running application
-
-