Linters
Linters are also called Linter Fuzzers.
Usually a good OpenAPI contract must follow several good practices in order to make it easy digestible by the service clients and act as much as possible as self-sufficient documentation:
- follow good and consistent practices for naming the contract elements like paths, query params, headers, requests, responses
- always use plural for the resources
- provide tags for all operations in order to avoid breaking code generation on some languages and have a logical grouping of the API operations
- provide good description for all paths, methods and request/response elements
- provide meaningful responses for
POST,PATCHandPUTrequests - provide examples for all requests/response elements
- provide structural constraints for (ideally) all request/response properties (min, max, regex)
- have some sort of
CorrelationIds/TraceIdsheaders for traceability - have at least a security schema in place
- avoid having the API version part of the paths
- document response codes for both "happy" and "unhappy" flows
- avoid using
xmlpayload unless there is a really good reason (like documenting an old API for example) - json types and properties do not use the same naming (like having a
Petwith a property namedpet)
CATS has currently 41 registered Linter Fuzzers or Linters. The names below
match the current output of cats list --linters:
ArrayWithoutItemsLinter- detects array schemas that do not define anitemspropertyCollectionPaginationLinter- verifies that collection GET operations support paginationDeleteHasBodyLinter- checks if DELETE methods have a bodyEmptyPathsLinter- verifies that each path contains at least one operationEmptyRequestSchemaLinter- detects request schemas without properties, references, or compositionEmptyResponseSchemaLinter- detects response schemas without properties, references, or compositionEnumCaseGlobalLinter- verifies consistent casing for string enum values across the contractEnumCasePathLevelLinter- verifies enum casing for inline path-level schemasGetHasBodyLinter- checks if GET methods have a bodyHeadHasBodyLinter- checks if HEAD methods have a bodyHeadersCaseLinter- verifies that HTTP headers follow naming conventionsHttpMethodConsistencyErrorLinter- flags missing critical REST methodsHttpMethodConsistencyWarnLinter- flags missing optional REST methodsHttpStatusCodeInRangeLinter- verifies that response codes are between 100 and 599JsonObjectsCaseLinter- verifies that JSON elements follow naming conventionsMultipleSuccessCodesLinter- flags operations with multiple 2xx response codesOperationIdVerbPrefixLinter- verifies operationId prefixes for HTTP methodsPatchWithoutBodyLinter- verifies that PATCH operations define a request bodyPathCaseLinter- verifies that path elements follow naming conventionsPathNounsLinter- verifies that path elements use nounsPathPluralsLinter- verifies plural resource namesPathTagsLinter- verifies path tags and top-level tag consistencyPostWithoutBodyLinter- verifies that POST operations define a request bodyPutWithoutBodyLinter- verifies that PUT operations define a request bodyQueryParamsCaseLinter- verifies that query parameters follow naming conventionsRecommendedHttpCodesLinter- verifies recommended response codesResponsesWithBodiesLinter- verifies response bodies are present except for 204 and 304SecuritySchemesLinter- verifies valid security schemes are configuredStringSchemaLimitGlobalLinter- verifies string schemas havemaxLengthorenumStringSchemaPathLevelLinter- verifies limits for inline path-level string schemasTopLevelElementsLinter- verifies meaningful contract-level metadataTracingHeadersLinter- verifies recommended tracing headersUniqueOperationIdsLinter- verifies that operationIds are uniqueUnusedExamplesLinter- flags unreferenced component examplesUnusedHeadersLinter- flags unreferenced component headersUnusedParametersLinter- flags unreferenced component parametersUnusedRequestBodiesLinter- flags unreferenced component request bodiesUnusedResponsesLinter- flags unreferenced component responsesUnusedSchemasLinter- flags unreferenced component schemasVersionsLinter- verifies that paths do not contain versioning informationXmlContentTypeLinter- verifies that requests and responses do not offerapplication/xml
You can run only these Fuzzers using cats lint --contract=CONTRACT.
Naming conventions can be configured using the following arguments:
--headersNaming=<headersNaming>Naming strategy for json object properties. Possible valuesSNAKE, KEBAB, PASCAL, CAMEL, HTTP_HEADER. Default:HTTP_HEADER--jsonObjectsNaming=<jsonObjectsNaming>Naming strategy for json objects. Possible valuesSNAKE, KEBAB, PASCAL, CAMEL, HTTP_HEADER. Default:PASCAL--jsonPropertiesNaming=<jsonPropertiesNaming>Naming strategy for json object properties. Possible valuesSNAKE, KEBAB, PASCAL, CAMEL, HTTP_HEADER. Default:CAMEL--pathNaming=<pathNaming>Naming strategy for paths (excluding path variables). Possible valuesSNAKE, KEBAB, PASCAL, CAMEL, HTTP_HEADER. Default:KEBAB--pathVariablesNaming=<pathVariablesNaming>Naming strategy for paths variables. Possible valuesSNAKE, KEBAB, PASCAL, CAMEL, HTTP_HEADER. Default:CAMEL--queryParamsNaming=<queryParamsNaming>Naming strategy for query parameters. Possible valuesSNAKE, KEBAB, PASCAL, CAMEL, HTTP_HEADER. Default:SNAKE
Linter Fuzzers are disabled by default. You must either use the cats lint ... command to run only the linters or
the --includeLinters argument to run them along other Fuzzers.
📄️ Empty Paths
| Item | Description |
📄️ Headers Case
| Item | Description |
📄️ Json Objects Case
| Item | Description |
📄️ Path Case
| Item | Description |
📄️ Path Nouns
| Item | Description |
📄️ Path Plural
| Item | Description |
📄️ Path Tags
| Item | Description |
📄️ Query Params Case
| Item | Description |
📄️ Recommended HTTP Codes
| Item | Description |
📄️ Tracing Headers
| Item | Description |
📄️ Security Schemes
| Item | Description |
📄️ HTTP Status Code In Valid Range
| Item | Description |
📄️ Top Level Elements
| Item | Description |
📄️ Tracing Headers
| Item | Description |
📄️ Unique Operations
| Item | Description |
📄️ Versions
| Item | Description |
📄️ XML Content Type
| Item | Description |