Class ModelUtils
- java.lang.Object
-
- org.openapitools.codegen.utils.ModelUtils
-
public class ModelUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description ModelUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static io.swagger.v3.oas.models.media.Schema
getAdditionalProperties(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 specificationstatic 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,ModelsMap> models)
Searches for the model by name in the map of models and returns itstatic 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 another 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 another 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 another 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 another 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 RequestBodystatic io.swagger.v3.oas.models.media.Schema
getSchemaFromResponse(io.swagger.v3.oas.models.responses.ApiResponse response)
Return the first defined Schema for a ApiResponsestatic 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 timestatic 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 specificationstatic boolean
hasAllOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains allOf and may or may not have properties/oneOf/anyOf defined.static boolean
hasAnyOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains anyOf and may or may not have properties/allOf/oneOf defined.static boolean
hasCommonAttributesDefined(io.swagger.v3.oas.models.media.Schema schema)
Returns true if any of the common attributes of the schema (e.g.static boolean
hasOneOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains oneOf and may or may not have properties/allOf/anyOf defined.static boolean
hasSelfReference(io.swagger.v3.oas.models.OpenAPI openAPI, io.swagger.v3.oas.models.media.Schema schema)
Has self reference?static boolean
hasSelfReference(io.swagger.v3.oas.models.OpenAPI openAPI, io.swagger.v3.oas.models.media.Schema schema, Set<String> visitedSchemaNames)
Has self reference?static boolean
hasValidation(io.swagger.v3.oas.models.media.Schema sc)
static boolean
isAllOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains allOf but no properties/oneOf/anyOf defined.static boolean
isAllOfWithProperties(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains allOf and properties, and no oneOf/anyOf defined.static boolean
isAnyOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains anyOf but no properties/allOf/anyOf defined.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 schemasstatic 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
isComplexComposedSchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is composed with more than one of the following: 'oneOf', 'anyOf' or 'allOf'.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
isExtensionParent(io.swagger.v3.oas.models.media.Schema schema)
If it's a boolean, returns the value of the extension `x-parent`.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.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 modelstatic boolean
isModelWithPropertiesOnly(io.swagger.v3.oas.models.media.Schema schema)
Check to see if the schema is a model with properties only (non-composed 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
isOneOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains oneOf but no properties/allOf/anyOf defined.static boolean
isParent(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema is a parent (with discriminator).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 casesstatic boolean
isUnsignedIntegerSchema(io.swagger.v3.oas.models.media.Schema schema)
static boolean
isUnsignedLongSchema(io.swagger.v3.oas.models.media.Schema schema)
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> schemaMappings)
Get the actual schema from aliases.
-
-
-
Method Detail
-
isDisallowAdditionalPropertiesIfNotPresent
public static boolean isDisallowAdditionalPropertiesIfNotPresent()
-
setDisallowAdditionalPropertiesIfNotPresent
public static void setDisallowAdditionalPropertiesIfNotPresent(boolean value)
-
isGenerateAliasAsModel
public static boolean isGenerateAliasAsModel()
-
setGenerateAliasAsModel
public static void setGenerateAliasAsModel(boolean value)
-
isGenerateAliasAsModel
public static boolean isGenerateAliasAsModel(io.swagger.v3.oas.models.media.Schema schema)
-
getModelByName
public static CodegenModel getModelByName(String name, Map<String,ModelsMap> models)
Searches for the model by name in the map of models and returns it- Parameters:
name
- Name of the modelmodels
- Map of models- Returns:
- model
-
getAllUsedSchemas
public 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- Parameters:
openAPI
- specification- Returns:
- schemas a list of used schemas
-
getUnusedSchemas
public 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- Parameters:
openAPI
- specification- Returns:
- schemas a list of unused schemas
-
getSchemasUsedOnlyInFormParam
public 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- Parameters:
openAPI
- specification- Returns:
- schemas a list of schemas
-
isTypeObjectSchema
public 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- Parameters:
schema
- the OAS schema- Returns:
- true if the specified schema is an Object schema.
-
isObjectSchema
public 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.A ObjectSchema differs from a MapSchema in the following way: - An ObjectSchema is not extensible, i.e. it has a fixed number of properties. - A MapSchema is an object that can be extended with an arbitrary set of properties. The payload may include dynamic properties.
For example, an OpenAPI schema is considered an ObjectSchema in the following scenarios:
type: object additionalProperties: false properties: name: type: string address: type: string
- Parameters:
schema
- the OAS schema- Returns:
- true if the specified schema is an Object schema.
-
isComposedSchema
public static boolean isComposedSchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is composed, i.e. if it uses 'oneOf', 'anyOf' or 'allOf'.- Parameters:
schema
- the OAS schema- Returns:
- true if the specified schema is a Composed schema.
-
isComplexComposedSchema
public static boolean isComplexComposedSchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is composed with more than one of the following: 'oneOf', 'anyOf' or 'allOf'.- Parameters:
schema
- the OAS schema- Returns:
- true if the specified schema is a Composed schema.
-
isMapSchema
public 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. Additional properties means a Schema should support all explicitly defined properties plus any undeclared properties.A MapSchema differs from an ObjectSchema in the following way: - An ObjectSchema is not extensible, i.e. it has a fixed number of properties. - A MapSchema is an object that can be extended with an arbitrary set of properties. The payload may include dynamic properties.
Note that isMapSchema returns true for a composed schema (allOf, anyOf, oneOf) that also defines additionalproperties.
For example, an OpenAPI schema is considered a MapSchema in the following scenarios:
type: object additionalProperties: true type: object additionalProperties: type: object properties: code: type: integer allOf: - $ref: '#/components/schemas/Class1' - $ref: '#/components/schemas/Class2' additionalProperties: true
- Parameters:
schema
- the OAS schema- Returns:
- true if the specified schema is a Map schema.
-
isArraySchema
public static boolean isArraySchema(io.swagger.v3.oas.models.media.Schema schema)
Return true if the specified schema is an array of items.- Parameters:
schema
- the OAS schema- Returns:
- true if the specified schema is an Array schema.
-
isSet
public static boolean isSet(io.swagger.v3.oas.models.media.Schema schema)
-
isStringSchema
public static boolean isStringSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isIntegerSchema
public static boolean isIntegerSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isShortSchema
public static boolean isShortSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isUnsignedIntegerSchema
public static boolean isUnsignedIntegerSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isLongSchema
public static boolean isLongSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isUnsignedLongSchema
public static boolean isUnsignedLongSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isBooleanSchema
public static boolean isBooleanSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isNumberSchema
public static boolean isNumberSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isFloatSchema
public static boolean isFloatSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isDoubleSchema
public static boolean isDoubleSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isDateSchema
public static boolean isDateSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isDateTimeSchema
public static boolean isDateTimeSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isPasswordSchema
public static boolean isPasswordSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isByteArraySchema
public static boolean isByteArraySchema(io.swagger.v3.oas.models.media.Schema schema)
-
isBinarySchema
public static boolean isBinarySchema(io.swagger.v3.oas.models.media.Schema schema)
-
isFileSchema
public static boolean isFileSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isUUIDSchema
public static boolean isUUIDSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isURISchema
public static boolean isURISchema(io.swagger.v3.oas.models.media.Schema schema)
-
isEmailSchema
public static boolean isEmailSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isDecimalSchema
public static boolean isDecimalSchema(io.swagger.v3.oas.models.media.Schema schema)
-
isModel
public static boolean isModel(io.swagger.v3.oas.models.media.Schema schema)
Check to see if the schema is a model- Parameters:
schema
- potentially containing a '$ref'- Returns:
- true if it's a model with at least one properties
-
isModelWithPropertiesOnly
public static boolean isModelWithPropertiesOnly(io.swagger.v3.oas.models.media.Schema schema)
Check to see if the schema is a model with properties only (non-composed model)- Parameters:
schema
- potentially containing a '$ref'- Returns:
- true if it's a model with at least one properties
-
hasValidation
public static boolean hasValidation(io.swagger.v3.oas.models.media.Schema sc)
-
isFreeFormObject
public static boolean isFreeFormObject(io.swagger.v3.oas.models.media.Schema schema)
Check to see if the schema is a free form object.A free form object is an object (i.e. 'type: object' in a OAS document) that: 1) Does not define properties, and 2) Is not a composed schema (no anyOf, oneOf, allOf), and 3) additionalproperties is not defined, or additionalproperties: true, or additionalproperties: {}.
Examples:
components: schemas: arbitraryObject: type: object description: This is a free-form object. The value must be a map of strings to values. The value cannot be 'null'. It cannot be array, string, integer, number. arbitraryNullableObject: type: object description: This is a free-form object. The value must be a map of strings to values. The value can be 'null', It cannot be array, string, integer, number. nullable: true arbitraryTypeValue: description: This is NOT a free-form object. The value can be any type except the 'null' value.
- Parameters:
schema
- potentially containing a '$ref'- Returns:
- true if it's a free-form object
-
getReferencedSchema
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)
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.- Parameters:
openAPI
- specification being checkedschema
- potentially containing a '$ref'- Returns:
- schema without '$ref'
-
getSchema
public static io.swagger.v3.oas.models.media.Schema getSchema(io.swagger.v3.oas.models.OpenAPI openAPI, String name)
-
getSchemas
public 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. The returned Map only includes the direct children of /components/schemas in the OAS document; the Map does not include inlined schemas.- Parameters:
openAPI
- the OpenAPI document.- Returns:
- a map of schemas in the OAS document.
-
getAllSchemas
public 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.- Parameters:
openAPI
- OpenAPI document- Returns:
- a list of schemas
-
getReferencedRequestBody
public 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 another RequestBody with '$ref', returns the referenced RequestBody if it is found or the actual RequestBody in the other cases.- Parameters:
openAPI
- specification being checkedrequestBody
- potentially containing a '$ref'- Returns:
- requestBody without '$ref'
-
getRequestBody
public static io.swagger.v3.oas.models.parameters.RequestBody getRequestBody(io.swagger.v3.oas.models.OpenAPI openAPI, String name)
-
getReferencedApiResponse
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)
If a ApiResponse contains a reference to another ApiResponse with '$ref', returns the referenced ApiResponse if it is found or the actual ApiResponse in the other cases.- Parameters:
openAPI
- specification being checkedapiResponse
- potentially containing a '$ref'- Returns:
- apiResponse without '$ref'
-
getApiResponse
public static io.swagger.v3.oas.models.responses.ApiResponse getApiResponse(io.swagger.v3.oas.models.OpenAPI openAPI, String name)
-
getReferencedParameter
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)
If a Parameter contains a reference to another Parameter with '$ref', returns the referenced Parameter if it is found or the actual Parameter in the other cases.- Parameters:
openAPI
- specification being checkedparameter
- potentially containing a '$ref'- Returns:
- parameter without '$ref'
-
getParameter
public static io.swagger.v3.oas.models.parameters.Parameter getParameter(io.swagger.v3.oas.models.OpenAPI openAPI, String name)
-
getReferencedCallback
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)
If a Callback contains a reference to another Callback with '$ref', returns the referenced Callback if it is found or the actual Callback in the other cases.- Parameters:
openAPI
- specification being checkedcallback
- potentially containing a '$ref'- Returns:
- callback without '$ref'
-
getCallback
public static io.swagger.v3.oas.models.callbacks.Callback getCallback(io.swagger.v3.oas.models.OpenAPI openAPI, String name)
-
getSchemaFromRequestBody
public 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- Parameters:
requestBody
- request body of the operation- Returns:
- first schema
-
getSchemaFromResponse
public 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- Parameters:
response
- api response of the operation- Returns:
- firstSchema
-
hasSelfReference
public static boolean hasSelfReference(io.swagger.v3.oas.models.OpenAPI openAPI, io.swagger.v3.oas.models.media.Schema schema)
Has self reference?- Parameters:
openAPI
- OpenAPI spec.schema
- Schema- Returns:
- boolean true if it has at least one self reference
-
hasSelfReference
public static boolean hasSelfReference(io.swagger.v3.oas.models.OpenAPI openAPI, io.swagger.v3.oas.models.media.Schema schema, Set<String> visitedSchemaNames)
Has self reference?- Parameters:
openAPI
- OpenAPI spec.schema
- SchemavisitedSchemaNames
- A set of visited schema names- Returns:
- boolean true if it has at least one self reference
-
unaliasSchema
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)
Get the actual schema from aliases. If the provided schema is not an alias, the schema itself will be returned.- Parameters:
openAPI
- specification being checkedschema
- schema (alias or direct reference)- Returns:
- actual schema
-
unaliasSchema
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> schemaMappings)
Get the actual schema from aliases. If the provided schema is not an alias, the schema itself will be returned.- Parameters:
openAPI
- OpenAPI document containing the schemas.schema
- schema (alias or direct reference)schemaMappings
- mappings of external types to be omitted by unaliasing- Returns:
- actual schema
-
getAdditionalProperties
public static io.swagger.v3.oas.models.media.Schema getAdditionalProperties(io.swagger.v3.oas.models.media.Schema schema)
Returns the additionalProperties Schema for the specified input schema.The additionalProperties keyword is used to control the handling of additional, undeclared properties, that is, properties whose names are not listed in the properties keyword. The additionalProperties keyword may be either a boolean or an object. If additionalProperties is a boolean and set to false, no additional properties are allowed. By default when the additionalProperties keyword is not specified in the input schema, any additional properties are allowed. This is equivalent to setting additionalProperties to the boolean value True or setting additionalProperties: {}
- Parameters:
schema
- the input schema that may or may not have the additionalProperties keyword.- Returns:
- the Schema of the additionalProperties. The null value is returned if no additional properties are allowed.
-
getReferencedHeader
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)
-
getHeader
public static io.swagger.v3.oas.models.headers.Header getHeader(io.swagger.v3.oas.models.OpenAPI openAPI, String name)
-
getChildrenMap
public static Map<String,List<String>> getChildrenMap(io.swagger.v3.oas.models.OpenAPI openAPI)
-
getInterfaces
public 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)- Parameters:
composed
- schema (alias or direct reference)- Returns:
- a list of schema defined in allOf, anyOf or oneOf
-
getParentName
public 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). It traverses the OAS model (possibly resolving $ref) to determine schemas that specify a determinator. If there are multiple elements in the composed schema and it is not clear which one should be the parent, return null.For example, given the following OAS spec, the parent of 'Dog' is Animal because 'Animal' specifies a discriminator.
animal: type: object discriminator: propertyName: type properties: type: string
dog: allOf: - $ref: '#/components/schemas/animal' - type: object properties: breed: string
- Parameters:
composedSchema
- schema (alias or direct reference)allSchemas
- all schemas- Returns:
- the name of the parent model
-
getAllParentsName
public 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).- Parameters:
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.- Returns:
- the name of the parent model
-
isExtensionParent
public static boolean isExtensionParent(io.swagger.v3.oas.models.media.Schema schema)
If it's a boolean, returns the value of the extension `x-parent`. If it's string, return true if it's non-empty. If the return value is `true`, the schema is a parent.- Parameters:
schema
- Schema- Returns:
- boolean
-
isNullable
public 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. if the value of the property can be the null value.In addition, if the OAS document is 3.1 or above, isNullable returns true if the input schema is a 'oneOf' composed document with at most two children, and one of the children is the 'null' type.
The caller is responsible for resolving schema references before invoking isNullable. If the input schema is a $ref and the referenced schema has 'nullable: true', this method returns false (because the nullable attribute is defined in the referenced schema).
The 'nullable' attribute was introduced in OAS 3.0. The 'nullable' attribute is deprecated in OAS 3.1. In a OAS 3.1 document, the preferred way to specify nullable properties is to use the 'null' type.
- Parameters:
schema
- the OAS schema.- Returns:
- true if the schema is nullable.
-
isNullableComposedSchema
public 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.The 'null' type is supported in OAS 3.1 and above. In the example below, the 'OptionalOrder' can have the null value because the 'null' type is one of the elements under 'oneOf'.
OptionalOrder: oneOf: - type: 'null' - $ref: '#/components/schemas/Order'
- Parameters:
schema
- the OAS composed schema.- Returns:
- true if the composed schema is nullable.
-
isNullType
public static boolean isNullType(io.swagger.v3.oas.models.media.Schema schema)
isNullType returns true if the input schema is the 'null' type.The 'null' type is supported in OAS 3.1 and above. It is not supported in OAS 2.0 and OAS 3.0.x.
For example, the "null" type could be used to specify that a value must either be null or a specified type:
OptionalOrder: oneOf: - type: 'null' - $ref: '#/components/schemas/Order'
- Parameters:
schema
- the OpenAPI schema- Returns:
- true if the schema is the 'null' type
-
isAnyType
public 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- Parameters:
schema
- the schema that we are checking- Returns:
- boolean
-
syncValidationProperties
public static void syncValidationProperties(io.swagger.v3.oas.models.media.Schema schema, IJsonSchemaValidationProperties target)
-
readWithInfo
public static com.fasterxml.jackson.databind.JsonNode readWithInfo(String location, List<io.swagger.v3.parser.core.models.AuthorizationValue> auths) throws Exception
Parse and return a JsonNode representation of the input OAS document.- Parameters:
location
- the URL of the OAS document.auths
- the list of authorization values to access the remote URL.- Returns:
- A JsonNode representation of the input OAS document.
- Throws:
Exception
- if an error occurs while retrieving the OpenAPI document.
-
getOpenApiVersion
public 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.For OAS 2.0 documents, return the value of the 'swagger' attribute. For OAS 3.x documents, return the value of the 'openapi' attribute.
- Parameters:
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.- Returns:
- the version of the OpenAPI document.
-
isAllOf
public static boolean isAllOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains allOf but no properties/oneOf/anyOf defined.- Parameters:
schema
- the schema- Returns:
- true if the schema contains allOf but no properties/oneOf/anyOf defined.
-
hasAllOf
public static boolean hasAllOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains allOf and may or may not have properties/oneOf/anyOf defined.- Parameters:
schema
- the schema- Returns:
- true if allOf is not empty
-
isAllOfWithProperties
public static boolean isAllOfWithProperties(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains allOf and properties, and no oneOf/anyOf defined.- Parameters:
schema
- the schema- Returns:
- true if the schema contains allOf but no properties/oneOf/anyOf defined.
-
isOneOf
public static boolean isOneOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains oneOf but no properties/allOf/anyOf defined.- Parameters:
schema
- the schema- Returns:
- true if the schema contains oneOf but no properties/allOf/anyOf defined.
-
hasOneOf
public static boolean hasOneOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains oneOf and may or may not have properties/allOf/anyOf defined.- Parameters:
schema
- the schema- Returns:
- true if allOf is not empty
-
isAnyOf
public static boolean isAnyOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains anyOf but no properties/allOf/anyOf defined.- Parameters:
schema
- the schema- Returns:
- true if the schema contains oneOf but no properties/allOf/anyOf defined.
-
hasAnyOf
public static boolean hasAnyOf(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema contains anyOf and may or may not have properties/allOf/oneOf defined.- Parameters:
schema
- the schema- Returns:
- true if anyOf is not empty
-
hasCommonAttributesDefined
public static boolean hasCommonAttributesDefined(io.swagger.v3.oas.models.media.Schema schema)
Returns true if any of the common attributes of the schema (e.g. readOnly, default, maximum, etc) is defined.- Parameters:
schema
- the schema- Returns:
- true if allOf is not empty
-
isParent
public static boolean isParent(io.swagger.v3.oas.models.media.Schema schema)
Returns true if the schema is a parent (with discriminator).- Parameters:
schema
- the schema.- Returns:
- true if the schema is a parent.
-
-