Class ValidationRule
- java.lang.Object
-
- io.apicurio.datamodels.models.visitors.AllNodeVisitor
-
- io.apicurio.datamodels.validation.ValidationRule
-
- All Implemented Interfaces:
AsyncApi20Visitor,AsyncApi21Visitor,AsyncApi22Visitor,AsyncApi23Visitor,AsyncApi24Visitor,AsyncApi25Visitor,AsyncApi26Visitor,AsyncApi30Visitor,AsyncApiVisitor,OpenApi20Visitor,OpenApi30Visitor,OpenApi31Visitor,OpenApiVisitor,CombinedVisitor,TraversingVisitor,Visitor
- Direct Known Subclasses:
AbstractInvalidPropertyValueRule,InvalidApiDescriptionRule,InvalidContactEmailRule,InvalidContactUrlRule,InvalidExternalDocsDescriptionRule,InvalidLicenseUrlRule,InvalidServerDescriptionRule,InvalidServerUrlRule,InvalidTagDescriptionRule,InvalidTermsOfServiceUrlRule,OasBodyAndFormDataMutualExclusivityRule,OasBodyParameterUniquenessValidationRule,OasExampleValueMutualExclusivityRule,OasHeaderExamplesMutualExclusivityRule,OasHeaderSchemaContentMutualExclusivityRule,OasIgnoredContentTypeHeaderRule,OasIgnoredHeaderParameterRule,OasInvalidApiBasePathRule,OasInvalidApiHostRule,OasInvalidCallbackReferenceRule,OasInvalidExampleDescriptionRule,OasInvalidExampleReferenceRule,OasInvalidExternalDocsUrlRule,OasInvalidHeaderDefaultValueRule,OasInvalidHeaderDescriptionRule,OasInvalidHeaderReferenceRule,OasInvalidLinkDescriptionRule,OasInvalidLinkOperationReferenceRule,OasInvalidLinkReferenceRule,OasInvalidOAuthAuthorizationUrlRule,OasInvalidOAuthRefreshUrlRule,OasInvalidOAuthTokenUrlRule,OasInvalidOpenIDConnectUrlRule,OasInvalidOperationConsumesRule,OasInvalidOperationDescriptionRule,OasInvalidOperationProducesRule,OasInvalidParameterDescriptionRule,OasInvalidParameterReferenceRule,OasInvalidPathItemDescriptionRule,OasInvalidPathItemReferenceRule,OasInvalidPropertyNameRule,OasInvalidPropertyTypeValidationRule,OasInvalidRequestBodyDescriptionRule,OasInvalidRequestBodyReferenceRule,OasInvalidResponseDescriptionRule,OasInvalidResponseReferenceRule,OasInvalidSchemaItemsDefaultValueRule,OasInvalidSchemaReferenceRule,OasInvalidSecurityRequirementNameRule,OasInvalidSecuritySchemeAuthUrlRule,OasInvalidSecuritySchemeDescriptionRule,OasInvalidSecuritySchemeReferenceRule,OasInvalidSecuritySchemeTokenUrlRule,OasInvalidServerVariableDescriptionRule,OasInvalidXmlNamespaceUrlRule,OasLinkOperationRefMutualExclusivityRule,OasMediaTypeExamplesMutualExclusivityRule,OasOperationIdUniquenessValidationRule,OasParameterExamplesMutualExclusivityRule,OasParameterSchemaContentMutualExclusivityRule,OasParameterUniquenessValidationRule,OasUnknownPropertyRule,RequiredPropertyValidationRule,SecurityRequirementUniquenessValidationRule,TagUniquenessValidationRule
public abstract class ValidationRule extends AllNodeVisitor implements Visitor, TraversingVisitor
Base class for all validation rule implementations.- Author:
- eric.wittmann@gmail.com
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classValidationRule.PathSegmentType encapsulating information about a path segment.
-
Field Summary
Fields Modifier and Type Field Description protected TraversalContexttraversalContext
-
Constructor Summary
Constructors Constructor Description ValidationRule(ValidationRuleMetaData ruleInfo)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String[]array(String... args)Creates an array.protected booleanequals(Object value1, Object value2)Returns true if the two values are equal.protected StringgetDefinitionName(Node node)Returns the name of the given definition.protected StringgetEncodingName(OpenApiEncoding encoding)Returns the name of an encoding.protected StringgetMappedNodeName(Node node)Gets the name of a mapped node.protected StringgetOperationMethod(Operation operation)Returns the operation method (get, put, post, etc) for the given operation.protected List<ValidationRule.PathSegment>getPathSegments(String pathTemplate)Finds all occurences of path segment patterns in a path template.protected StringgetPathTemplate(OpenApiPathItem pathItem)Returns the path template for the given path item.protected StringgetStatusCode(OpenApiResponse response)Returns the status code of the given response.protected booleanhasValue(Object propertyValue)Check if the property value exists (is not undefined and is not null).protected booleanisDefined(Object propertyValue)Check if a property was defined.protected booleanisDefinition(Node node)Check if the given node is a definitionprotected booleanisNullOrUndefined(Object value)Check if a value is either null or undefined.protected booleanisPathWellFormed(String pathTemplate)Checks the path template against the regular expression and returns match result.protected booleanisValidCommonMark(String propertyValue)Returns true only if the given value is valid CommonMark style markup.protected booleanisValidEmailAddress(String propertyValue)Returns true only if the given value is a valid email address.protected booleanisValidEnumItem(String value, String[] items)Returns true if the given value is an item in the enum list.protected booleanisValidForType(Object value, Node node)Returns true if the given value is valid according to the schema provided.protected booleanisValidGFM(String propertyValue)Returns true only if the given value is valid GFM style markup.protected booleanisValidHttpCode(String statusCode)Returns true if the given status code is a valid HTTP response code.protected booleanisValidMimeType(List<String> propertyValue)Returns true only if the given value is a valid mime-type.protected booleanisValidUrl(String propertyValue)Returns true only if the given value is a valid URL.protected booleanisValidUrlTemplate(String propertyValue)Returns true only if the given value is a valid URL template.protected Map<String,String>map(String... args)Turns a list of args into a map suitable for use as template arguments.protected voidreport(Node node, String property, Map<String,String> messageParams)Called by validation rules to report an error.protected voidreportIf(boolean condition, Node node, String property, Map<String,String> messageParams)Reports a validation error if the given condition is true.protected voidreportIfInvalid(boolean isValid, Node node, String property, Map<String,String> messageParams)Reports a validation error if the property is not valid.protected voidreportPathError(Node node, Map<String,String> messageParams)Utility function to report path related errors.voidsetReporter(IValidationProblemReporter reporter)Sets the validation problem reporter.voidsetTraversalContext(TraversalContext context)protected voidvisitNode(Node node)-
Methods inherited from class io.apicurio.datamodels.models.visitors.AllNodeVisitor
visitBinding, visitCallback, visitChannel, visitChannelBindings, visitChannelItem, visitChannels, visitComponents, visitContact, visitCorrelationID, visitDefinitions, visitDiscriminator, visitDocument, visitEncoding, visitExample, visitExternalDocumentation, visitHeader, visitInfo, visitItems, visitLicense, visitLink, visitMediaType, visitMessage, visitMessageBindings, visitMessageExample, visitMessageTrait, visitMultiFormatSchema, visitOAuthFlow, visitOAuthFlows, visitOneOfMessages, visitOperation, visitOperationBindings, visitOperationReply, visitOperationReplyAddress, visitOperations, visitOperationTrait, visitParameter, visitParameterDefinitions, visitParameters, visitPathItem, visitPaths, visitReference, visitRequestBody, visitResponse, visitResponseDefinitions, visitResponses, visitSchema, visitScopes, visitSecurityDefinitions, visitSecurityRequirement, visitSecurityScheme, visitServer, visitServerBindings, visitServers, visitServerVariable, visitTag, visitXML
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.apicurio.datamodels.models.visitors.Visitor
visitContact, visitDocument, visitExternalDocumentation, visitInfo, visitLicense, visitOperation, visitParameter, visitSchema, visitSecurityScheme, visitTag
-
-
-
-
Field Detail
-
traversalContext
protected TraversalContext traversalContext
-
-
Constructor Detail
-
ValidationRule
public ValidationRule(ValidationRuleMetaData ruleInfo)
Constructor.- Parameters:
ruleInfo-
-
-
Method Detail
-
visitNode
protected void visitNode(Node node)
- Specified by:
visitNodein classAllNodeVisitor
-
setTraversalContext
public void setTraversalContext(TraversalContext context)
- Specified by:
setTraversalContextin interfaceTraversingVisitor- See Also:
TraversingVisitor.setTraversalContext(io.apicurio.datamodels.models.visitors.TraversalContext)
-
setReporter
public void setReporter(IValidationProblemReporter reporter)
Sets the validation problem reporter.- Parameters:
reporter-
-
report
protected void report(Node node, String property, Map<String,String> messageParams)
Called by validation rules to report an error.- Parameters:
node-property-messageParams-
-
reportIfInvalid
protected void reportIfInvalid(boolean isValid, Node node, String property, Map<String,String> messageParams)Reports a validation error if the property is not valid.- Parameters:
isValid-node-property-messageParams-
-
reportIf
protected void reportIf(boolean condition, Node node, String property, Map<String,String> messageParams)Reports a validation error if the given condition is true.- Parameters:
condition-node-property-messageParams-
-
reportPathError
protected void reportPathError(Node node, Map<String,String> messageParams)
Utility function to report path related errors.- Parameters:
node-messageParams-
-
isDefined
protected boolean isDefined(Object propertyValue)
Check if a property was defined.- Parameters:
propertyValue-- Returns:
- {boolean}
-
isDefinition
protected boolean isDefinition(Node node)
Check if the given node is a definition- Parameters:
node-
-
getMappedNodeName
protected String getMappedNodeName(Node node)
Gets the name of a mapped node. This uses the traversal context to determine the name of the property (typically from a parent map) that points to this node.- Parameters:
node-
-
getDefinitionName
protected String getDefinitionName(Node node)
Returns the name of the given definition. This should only be called *after* calling isDefinition() and only if it returns true. Otherwise the behavior of this method is undefined.- Parameters:
node-
-
getEncodingName
protected String getEncodingName(OpenApiEncoding encoding)
Returns the name of an encoding. This can only be determined using the traversal context because the encoding name is the key for this encoding in the Map of encodings for a media type.
-
getPathTemplate
protected String getPathTemplate(OpenApiPathItem pathItem)
Returns the path template for the given path item.- Parameters:
pathItem-
-
getStatusCode
protected String getStatusCode(OpenApiResponse response)
Returns the status code of the given response.
-
getOperationMethod
protected String getOperationMethod(Operation operation)
Returns the operation method (get, put, post, etc) for the given operation.
-
hasValue
protected boolean hasValue(Object propertyValue)
Check if the property value exists (is not undefined and is not null).- Parameters:
propertyValue-- Returns:
- {boolean}
-
isPathWellFormed
protected boolean isPathWellFormed(String pathTemplate)
Checks the path template against the regular expression and returns match result.- Parameters:
pathTemplate-- Returns:
- {boolean}
-
getPathSegments
protected List<ValidationRule.PathSegment> getPathSegments(String pathTemplate)
Finds all occurences of path segment patterns in a path template.- Parameters:
pathTemplate-- Returns:
- {PathSegment[]}
-
isNullOrUndefined
protected boolean isNullOrUndefined(Object value)
Check if a value is either null or undefined.- Parameters:
value-- Returns:
- {boolean}
-
isValidUrl
protected boolean isValidUrl(String propertyValue)
Returns true only if the given value is a valid URL.- Parameters:
propertyValue-- Returns:
- {boolean}
-
isValidUrlTemplate
protected boolean isValidUrlTemplate(String propertyValue)
Returns true only if the given value is a valid URL template.- Parameters:
propertyValue-
-
isValidGFM
protected boolean isValidGFM(String propertyValue)
Returns true only if the given value is valid GFM style markup.- Parameters:
propertyValue-
-
isValidCommonMark
protected boolean isValidCommonMark(String propertyValue)
Returns true only if the given value is valid CommonMark style markup.- Parameters:
propertyValue-
-
isValidEmailAddress
protected boolean isValidEmailAddress(String propertyValue)
Returns true only if the given value is a valid email address.- Parameters:
propertyValue-
-
isValidMimeType
protected boolean isValidMimeType(List<String> propertyValue)
Returns true only if the given value is a valid mime-type.- Parameters:
propertyValue-
-
isValidEnumItem
protected boolean isValidEnumItem(String value, String[] items)
Returns true if the given value is an item in the enum list.- Parameters:
value-items-
-
isValidForType
protected boolean isValidForType(Object value, Node node)
Returns true if the given value is valid according to the schema provided.- Parameters:
value-node-
-
isValidHttpCode
protected boolean isValidHttpCode(String statusCode)
Returns true if the given status code is a valid HTTP response code.- Parameters:
statusCode-
-
map
protected Map<String,String> map(String... args)
Turns a list of args into a map suitable for use as template arguments. The args must come in pairs of "key, value". For example: map("key1", "value1", "key2", Boolean.TRUE); That would return aMaptwo mappings.
-
-