public class ModelUtils extends Object
| Constructor and Description |
|---|
ModelUtils() |
| Modifier and Type | Method and Description |
|---|---|
static io.swagger.v3.oas.models.media.Schema |
getAdditionalProperties(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
Returns the additionalProperties Schema for the specified input schema.
|
static List<String> |
getAllParentsName(io.swagger.v3.oas.models.media.ComposedSchema composedSchema,
Map<String,io.swagger.v3.oas.models.media.Schema> allSchemas,
boolean includeAncestors)
Get the list of parent model names from the schemas (allOf, anyOf, oneOf).
|
static List<io.swagger.v3.oas.models.media.Schema> |
getAllSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
Return the list of all schemas in the 'components/schemas' section of an openAPI specification,
including inlined schemas and children of composed schemas.
|
static List<String> |
getAllUsedSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
Return the list of all schemas in the 'components/schemas' section used in the openAPI specification
|
static io.swagger.v3.oas.models.responses.ApiResponse |
getApiResponse(io.swagger.v3.oas.models.OpenAPI openAPI,
String name) |
static io.swagger.v3.oas.models.callbacks.Callback |
getCallback(io.swagger.v3.oas.models.OpenAPI openAPI,
String name) |
static Map<String,List<String>> |
getChildrenMap(io.swagger.v3.oas.models.OpenAPI openAPI) |
static io.swagger.v3.oas.models.headers.Header |
getHeader(io.swagger.v3.oas.models.OpenAPI openAPI,
String name) |
static List<io.swagger.v3.oas.models.media.Schema> |
getInterfaces(io.swagger.v3.oas.models.media.ComposedSchema composed)
Get the interfaces from the schema (composed)
|
static CodegenModel |
getModelByName(String name,
Map<String,Object> models)
Searches for the model by name in the map of models and returns it
|
static SemVer |
getOpenApiVersion(io.swagger.v3.oas.models.OpenAPI openAPI,
String location,
List<io.swagger.v3.parser.core.models.AuthorizationValue> auths)
Parse the OAS document at the specified location, get the swagger or openapi version
as specified in the source document, and return the version.
|
static io.swagger.v3.oas.models.parameters.Parameter |
getParameter(io.swagger.v3.oas.models.OpenAPI openAPI,
String name) |
static String |
getParentName(io.swagger.v3.oas.models.media.ComposedSchema composedSchema,
Map<String,io.swagger.v3.oas.models.media.Schema> allSchemas)
Get the parent model name from the composed schema (allOf, anyOf, oneOf).
|
static io.swagger.v3.oas.models.responses.ApiResponse |
getReferencedApiResponse(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.responses.ApiResponse apiResponse)
If a ApiResponse contains a reference to an other ApiResponse with '$ref', returns the referenced ApiResponse if it is found or the actual ApiResponse in the other cases.
|
static io.swagger.v3.oas.models.callbacks.Callback |
getReferencedCallback(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.callbacks.Callback callback)
If a Callback contains a reference to an other Callback with '$ref', returns the referenced Callback if it is found or the actual Callback in the other cases.
|
static io.swagger.v3.oas.models.headers.Header |
getReferencedHeader(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.headers.Header header) |
static io.swagger.v3.oas.models.parameters.Parameter |
getReferencedParameter(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.parameters.Parameter parameter)
If a Parameter contains a reference to an other Parameter with '$ref', returns the referenced Parameter if it is found or the actual Parameter in the other cases.
|
static io.swagger.v3.oas.models.parameters.RequestBody |
getReferencedRequestBody(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.parameters.RequestBody requestBody)
If a RequestBody contains a reference to an other RequestBody with '$ref', returns the referenced RequestBody if it is found or the actual RequestBody in the other cases.
|
static io.swagger.v3.oas.models.media.Schema |
getReferencedSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
If a Schema contains a reference to another Schema with '$ref', returns the referenced Schema if it is found or the actual Schema in the other cases.
|
static io.swagger.v3.oas.models.parameters.RequestBody |
getRequestBody(io.swagger.v3.oas.models.OpenAPI openAPI,
String name) |
static io.swagger.v3.oas.models.media.Schema |
getSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
String name) |
static io.swagger.v3.oas.models.media.Schema |
getSchemaFromRequestBody(io.swagger.v3.oas.models.parameters.RequestBody requestBody)
Return the first defined Schema for a RequestBody
|
static io.swagger.v3.oas.models.media.Schema |
getSchemaFromResponse(io.swagger.v3.oas.models.responses.ApiResponse response)
Return the first defined Schema for a ApiResponse
|
static Map<String,io.swagger.v3.oas.models.media.Schema> |
getSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
Return a Map of the schemas defined under /components/schemas in the OAS document.
|
static List<String> |
getSchemasUsedOnlyInFormParam(io.swagger.v3.oas.models.OpenAPI openAPI)
Return the list of schemas in the 'components/schemas' used only in a 'application/x-www-form-urlencoded' or 'multipart/form-data' mime time
|
static String |
getSimpleRef(String ref) |
static List<String> |
getUnusedSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
Return the list of unused schemas in the 'components/schemas' section of an openAPI specification
|
static boolean |
hasValidation(io.swagger.v3.oas.models.media.Schema sc) |
static boolean |
isAnyType(io.swagger.v3.oas.models.media.Schema schema)
For when a type is not defined on a schema
Note: properties, additionalProperties, enums, validations, items, and composed schemas (oneOf/anyOf/allOf)
can be defined or omitted on these any type schemas
|
static boolean |
isArraySchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is an array of items.
|
static boolean |
isBinarySchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isBooleanSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isByteArraySchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isComposedSchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is composed, i.e.
|
static boolean |
isDateSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isDateTimeSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isDecimalSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isDisallowAdditionalPropertiesIfNotPresent() |
static boolean |
isDoubleSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isEmailSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isFileSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isFloatSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isFreeFormObject(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
Check to see if the schema is a free form object.
|
static boolean |
isGenerateAliasAsModel() |
static boolean |
isGenerateAliasAsModel(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isIntegerSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isLongSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isMapSchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified 'schema' is an object that can be extended with additional properties.
|
static boolean |
isModel(io.swagger.v3.oas.models.media.Schema schema)
Check to see if the schema is a model
|
static boolean |
isNullable(io.swagger.v3.oas.models.media.Schema schema)
Return true if the 'nullable' attribute is set to true in the schema, i.e.
|
static boolean |
isNullableComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema schema)
Return true if the specified composed schema is 'oneOf', contains one or two elements,
and at least one of the elements is the 'null' type.
|
static boolean |
isNullType(io.swagger.v3.oas.models.media.Schema schema)
isNullType returns true if the input schema is the 'null' type.
|
static boolean |
isNumberSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isObjectSchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is an object with a fixed number of properties.
|
static boolean |
isPasswordSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isSet(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isShortSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isStringSchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isTypeObjectSchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is type object
We can't use isObjectSchema because it requires properties to exist which is not required
We can't use isMap because it is true for AnyType use cases
|
static boolean |
isURISchema(io.swagger.v3.oas.models.media.Schema schema) |
static boolean |
isUUIDSchema(io.swagger.v3.oas.models.media.Schema schema) |
static com.fasterxml.jackson.databind.JsonNode |
readWithInfo(String location,
List<io.swagger.v3.parser.core.models.AuthorizationValue> auths)
Parse and return a JsonNode representation of the input OAS document.
|
static void |
setDisallowAdditionalPropertiesIfNotPresent(boolean value) |
static void |
setGenerateAliasAsModel(boolean value) |
static void |
syncValidationProperties(io.swagger.v3.oas.models.media.Schema schema,
IJsonSchemaValidationProperties target) |
static io.swagger.v3.oas.models.media.Schema |
unaliasSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
Get the actual schema from aliases.
|
static io.swagger.v3.oas.models.media.Schema |
unaliasSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema,
Map<String,String> importMappings)
Get the actual schema from aliases.
|
public static void setDisallowAdditionalPropertiesIfNotPresent(boolean value)
public static boolean isDisallowAdditionalPropertiesIfNotPresent()
public static void setGenerateAliasAsModel(boolean value)
public static boolean isGenerateAliasAsModel()
public static boolean isGenerateAliasAsModel(io.swagger.v3.oas.models.media.Schema schema)
public static CodegenModel getModelByName(String name, Map<String,Object> models)
name - Name of the modelmodels - Map of modelspublic static List<String> getAllUsedSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
openAPI - specificationpublic static List<String> getUnusedSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
openAPI - specificationpublic static List<String> getSchemasUsedOnlyInFormParam(io.swagger.v3.oas.models.OpenAPI openAPI)
openAPI - specificationpublic static boolean isTypeObjectSchema(io.swagger.v3.oas.models.media.Schema schema)
schema - the OAS schemapublic static boolean isObjectSchema(io.swagger.v3.oas.models.media.Schema schema)
schema - the OAS schemapublic static boolean isComposedSchema(io.swagger.v3.oas.models.media.Schema schema)
schema - the OAS schemapublic static boolean isMapSchema(io.swagger.v3.oas.models.media.Schema schema)
schema - the OAS schemapublic static boolean isArraySchema(io.swagger.v3.oas.models.media.Schema schema)
schema - the OAS schemapublic static boolean isSet(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isStringSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isIntegerSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isShortSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isLongSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isBooleanSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isNumberSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isFloatSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isDoubleSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isDateSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isDateTimeSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isPasswordSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isByteArraySchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isBinarySchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isFileSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isUUIDSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isURISchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isEmailSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isDecimalSchema(io.swagger.v3.oas.models.media.Schema schema)
public static boolean isModel(io.swagger.v3.oas.models.media.Schema schema)
schema - potentially containing a '$ref'public static boolean hasValidation(io.swagger.v3.oas.models.media.Schema sc)
public static boolean isFreeFormObject(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
openAPI - the object that encapsulates the OAS document.schema - potentially containing a '$ref'public static io.swagger.v3.oas.models.media.Schema getReferencedSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
openAPI - specification being checkedschema - potentially containing a '$ref'public static io.swagger.v3.oas.models.media.Schema getSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
String name)
public static Map<String,io.swagger.v3.oas.models.media.Schema> getSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
openAPI - the OpenAPI document.public static List<io.swagger.v3.oas.models.media.Schema> getAllSchemas(io.swagger.v3.oas.models.OpenAPI openAPI)
openAPI - OpenAPI documentpublic static io.swagger.v3.oas.models.parameters.RequestBody getReferencedRequestBody(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.parameters.RequestBody requestBody)
openAPI - specification being checkedrequestBody - potentially containing a '$ref'public static io.swagger.v3.oas.models.parameters.RequestBody getRequestBody(io.swagger.v3.oas.models.OpenAPI openAPI,
String name)
public static io.swagger.v3.oas.models.responses.ApiResponse getReferencedApiResponse(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.responses.ApiResponse apiResponse)
openAPI - specification being checkedapiResponse - potentially containing a '$ref'public static io.swagger.v3.oas.models.responses.ApiResponse getApiResponse(io.swagger.v3.oas.models.OpenAPI openAPI,
String name)
public static io.swagger.v3.oas.models.parameters.Parameter getReferencedParameter(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.parameters.Parameter parameter)
openAPI - specification being checkedparameter - potentially containing a '$ref'public static io.swagger.v3.oas.models.parameters.Parameter getParameter(io.swagger.v3.oas.models.OpenAPI openAPI,
String name)
public static io.swagger.v3.oas.models.callbacks.Callback getReferencedCallback(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.callbacks.Callback callback)
openAPI - specification being checkedcallback - potentially containing a '$ref'public static io.swagger.v3.oas.models.callbacks.Callback getCallback(io.swagger.v3.oas.models.OpenAPI openAPI,
String name)
public static io.swagger.v3.oas.models.media.Schema getSchemaFromRequestBody(io.swagger.v3.oas.models.parameters.RequestBody requestBody)
requestBody - request body of the operationpublic static io.swagger.v3.oas.models.media.Schema getSchemaFromResponse(io.swagger.v3.oas.models.responses.ApiResponse response)
response - api response of the operationpublic static io.swagger.v3.oas.models.media.Schema unaliasSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
openAPI - specification being checkedschema - schema (alias or direct reference)public static io.swagger.v3.oas.models.media.Schema unaliasSchema(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema,
Map<String,String> importMappings)
openAPI - OpenAPI document containing the schemas.schema - schema (alias or direct reference)importMappings - mappings of external types to be omitted by unaliasingpublic static io.swagger.v3.oas.models.media.Schema getAdditionalProperties(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.media.Schema schema)
openAPI - the object that encapsulates the OAS document.schema - the input schema that may or may not have the additionalProperties keyword.public static io.swagger.v3.oas.models.headers.Header getReferencedHeader(io.swagger.v3.oas.models.OpenAPI openAPI,
io.swagger.v3.oas.models.headers.Header header)
public static io.swagger.v3.oas.models.headers.Header getHeader(io.swagger.v3.oas.models.OpenAPI openAPI,
String name)
public static Map<String,List<String>> getChildrenMap(io.swagger.v3.oas.models.OpenAPI openAPI)
public static List<io.swagger.v3.oas.models.media.Schema> getInterfaces(io.swagger.v3.oas.models.media.ComposedSchema composed)
composed - schema (alias or direct reference)public static String getParentName(io.swagger.v3.oas.models.media.ComposedSchema composedSchema, Map<String,io.swagger.v3.oas.models.media.Schema> allSchemas)
composedSchema - schema (alias or direct reference)allSchemas - all schemaspublic static List<String> getAllParentsName(io.swagger.v3.oas.models.media.ComposedSchema composedSchema, Map<String,io.swagger.v3.oas.models.media.Schema> allSchemas, boolean includeAncestors)
composedSchema - schema (alias or direct reference)allSchemas - all schemasincludeAncestors - if true, include the indirect ancestors in the return value. If false, return the direct parents.public static boolean isNullable(io.swagger.v3.oas.models.media.Schema schema)
schema - the OAS schema.public static boolean isNullableComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema schema)
schema - the OAS composed schema.public static boolean isNullType(io.swagger.v3.oas.models.media.Schema schema)
schema - the OpenAPI schemapublic static boolean isAnyType(io.swagger.v3.oas.models.media.Schema schema)
schema - the schema that we are checkingpublic static void syncValidationProperties(io.swagger.v3.oas.models.media.Schema schema,
IJsonSchemaValidationProperties target)
public static com.fasterxml.jackson.databind.JsonNode readWithInfo(String location, List<io.swagger.v3.parser.core.models.AuthorizationValue> auths) throws Exception
location - the URL of the OAS document.auths - the list of authorization values to access the remote URL.Exception - if an error occurs while retrieving the OpenAPI document.public static SemVer getOpenApiVersion(io.swagger.v3.oas.models.OpenAPI openAPI, String location, List<io.swagger.v3.parser.core.models.AuthorizationValue> auths)
openAPI - the object that encapsulates the OAS document.location - the URL of the OAS document.auths - the list of authorization values to access the remote URL.Copyright © 2021. All rights reserved.