public class OpenAPIUtil extends Object
| Modifier and Type | Method and 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 provided
Schema. |
static String |
getDelimiter(String name,
io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style)
Returns a delimiter
String 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 operation
|
static JSONUtil.NodeType |
getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema)
Fetches the
JSONUtil.NodeType based off of the Schema definition |
static JSONUtil.NodeType |
getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema,
JSONUtil.NodeType defaultValue)
Fetches the
JSONUtil.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 parameters
OpenAPIParameterType 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 specified
OpenAPIParameterType parameter for this operation. |
static String |
getPath(io.swagger.v3.oas.models.OpenAPI api,
String operationId)
Returns the path based off of the Operation ID
|
protected 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 the
PathItem.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 given
Content. |
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 from
Content type map. |
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.
|
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
|
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 value
|
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
|
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
|
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.
|
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 if
Schema.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
|
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)
api - the api definitionrequest - the selected requestpublic static io.swagger.v3.oas.models.media.Schema<?> getSchema(io.swagger.v3.oas.models.OpenAPI api,
io.swagger.v3.oas.models.media.Content content)
Content type map. Currently only supports extracting schema objects
from MediaType of type CONTENT_TYPE. Also resolves any $ref pointers in the schema if present.api - the api definitioncontent - the selected contentpublic static io.swagger.v3.oas.models.media.Schema<?> getSchema(io.swagger.v3.oas.models.media.Content content)
Content. This will NOT resolve $ref for you as just has knowledge
of the incoming Content object. Returns null if no content is found within Contentcontent - the selected contentpublic static io.swagger.v3.oas.models.media.Schema<?> getSchema(io.swagger.v3.oas.models.OpenAPI api,
io.swagger.v3.oas.models.media.Schema<?> schema)
api - the api definitionschema - the selected schemapublic static io.swagger.v3.oas.models.media.Schema<?> getSharedSchema(io.swagger.v3.oas.models.OpenAPI api,
String ref)
api - the api definitionref - the reference pathpublic static io.swagger.v3.oas.models.parameters.Parameter getSharedParameter(io.swagger.v3.oas.models.OpenAPI api,
String ref)
api - the api definitionref - the reference pathpublic static JSONUtil.NodeType getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema)
JSONUtil.NodeType based off of the Schema definitionschema - the selected schemapublic static JSONUtil.NodeType getNodeType(io.swagger.v3.oas.models.media.Schema<?> schema, JSONUtil.NodeType defaultValue)
JSONUtil.NodeType based off of the schema definition. Will use default if not given / invalid.schema - the selected schemadefaultValue - default value if node type isn't givenpublic static boolean isStructured(io.swagger.v3.oas.models.media.Content content)
content - the selected contentpublic static boolean isSimpleSchema(io.swagger.v3.oas.models.media.Schema<?> schema)
Schema.getType() is Boolean, Number, Integer, String. Returns false otherwiseschema - 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)
api - the api definitionoperation - the selected operationpattern - the response patternpublic static io.swagger.v3.oas.models.responses.ApiResponse resolveResponse(io.swagger.v3.oas.models.OpenAPI api,
io.swagger.v3.oas.models.responses.ApiResponse response)
api - the api definitionresponse - the responsepublic static io.swagger.v3.oas.models.responses.ApiResponse getSharedResponse(io.swagger.v3.oas.models.OpenAPI api,
String ref)
api - the api definitionref - the reference pathpublic static io.swagger.v3.oas.models.parameters.RequestBody resolveRequestBody(io.swagger.v3.oas.models.OpenAPI api,
io.swagger.v3.oas.models.parameters.RequestBody requestBody)
api - the api definitionrequestBody - the requestBodypublic static io.swagger.v3.oas.models.parameters.RequestBody getSharedRequest(io.swagger.v3.oas.models.OpenAPI api,
String ref)
api - the api definitionref - the reference pathpublic 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)
api - the api definitionmethod - the selected http methodpath - the selected pathpublic static List<io.swagger.v3.oas.models.parameters.Parameter> getParametersFromOperation(io.swagger.v3.oas.models.OpenAPI api, io.swagger.v3.oas.models.Operation operation)
OpenAPIParameterType for this operation. If the
parameters are reference parameters ($ref), then this utility will resolve the parameter reference for you.api - the api definitionoperation - the selected operationpublic 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)
OpenAPIParameterType parameter for this operation. If the parameters are
reference parameters ($ref), then this utility will resolve the parameter reference for you.api - the api definitionoperation - the selected operationfilterType - the parameter to filter uponpublic static io.swagger.v3.oas.models.parameters.Parameter resolveParameter(io.swagger.v3.oas.models.OpenAPI api,
io.swagger.v3.oas.models.parameters.Parameter parameter)
api - the api definitionparameter - the parameter to resolvepublic static boolean isParameterSupported(io.swagger.v3.oas.models.OpenAPI api,
io.swagger.v3.oas.models.parameters.Parameter parameter)
api - parameter - public static io.swagger.v3.oas.models.Operation getOperation(io.swagger.v3.oas.models.OpenAPI api,
String operationId)
api - the api definitionoperationId - the operation's idpublic static io.swagger.v3.oas.models.PathItem.HttpMethod getHttpMethod(io.swagger.v3.oas.models.OpenAPI api,
String operationId)
api - the api definitionoperationId - the operation idpublic 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)
api - the api definitionmethod - the selected http methodpath - the selected pathpublic static io.swagger.v3.oas.models.parameters.RequestBody getRequestBody(io.swagger.v3.oas.models.OpenAPI api,
String operationId)
api - the api definitionoperationId - the operation idpublic static boolean isRequestBodyRequired(io.swagger.v3.oas.models.Operation operation)
operation - the selected operationpublic 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)
PathItem.HttpMethod and the path. If no content is given,
then an empty content is returned.api - the api definitionmethod - the selected http methodpath - the selected pathpublic static String getFirstRequestContentType(io.swagger.v3.oas.models.Operation operation)
operation - the selected operationpublic static String getPath(io.swagger.v3.oas.models.OpenAPI api, String operationId)
api - the api definitionoperationId - the selected operation idprotected static io.swagger.v3.oas.models.Paths getPaths(io.swagger.v3.oas.models.OpenAPI api)
public static String getSerializedPathParameter(String name, String parameterValue, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style, boolean explode, OpenAPIDataType dataType)
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.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)
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.public static String getSerializedHeaderParameter(String name, String parameterValue, OpenAPIDataType dataType)
name - Header parameter name.parameterValue - Header parameter value.dataType - OpenAPIDataType of the parameter.public static String getDelimiter(String name, io.swagger.v3.oas.models.parameters.Parameter.StyleEnum style)
String corresponding to the Open Api parameter style enum and parameter name.name - Open Api Parameter Name.style - Open Api Parameter Style Enum.public static JsonNode buildSchema(io.swagger.v3.oas.models.media.Schema<?> schema, io.swagger.v3.oas.models.OpenAPI api, OpenAPIParseOption parseOption)
Schema. Currently only supports building schemas with root
type of "object". Supports building schemas with ComposedSchema elements by resolving "allOf", "anyOf",
"oneOf" keywords used to combine schemas.schema - the schemaapi - the OpenAPI specificationparseOption - parse options for the specIllegalArgumentException - if the schema is nullIllegalArgumentException - if Schema.getType() is not JSONUtil.NodeType.OBJECTpublic static void validateSpecFileLocation(String spec)
spec - path to spec fileIllegalArgumentException - if the spec file path is not referencing a file that is readable and
accessible by the running application