vacuum-rules.yaml 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. description: Recommended rules for a high quality specification.
  2. documentationUrl: https://quobix.com/vacuum/rulesets/recommended
  3. rules:
  4. component-description:
  5. category:
  6. description: Documentation is really important, in OpenAPI, just about everything can and should have a description. This set of rules checks for absent descriptions, poor quality descriptions (copy/paste), or short descriptions.
  7. id: descriptions
  8. name: Descriptions
  9. description: Component description check
  10. formats:
  11. - oas3
  12. - oas3_1
  13. - oas3_2
  14. given: $
  15. howToFix: Components are the inputs and outputs of a specification. A user needs to be able to understand each component and what id does. Descriptions are critical to understanding components. Add a description!
  16. id: component-description
  17. recommended: true
  18. resolved: true
  19. severity: warn
  20. then:
  21. function: oasComponentDescriptions
  22. type: validation
  23. duplicate-paths:
  24. category:
  25. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  26. id: operations
  27. name: Operations
  28. description: Paths cannot be duplicated; only the last definition will be kept.
  29. formats:
  30. - oas3
  31. - oas3_1
  32. - oas3_2
  33. given: $
  34. howToFix: Duplicate path definitions found in your OpenAPI specification. In YAML, duplicate keys are allowed, but only the last occurrence is used. This means earlier path definitions are silently ignored, which can lead to missing API endpoints in your specification.
  35. id: duplicate-paths
  36. recommended: true
  37. severity: error
  38. then:
  39. function: duplicatePaths
  40. type: validation
  41. duplicated-entry-in-enum:
  42. category:
  43. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  44. id: schemas
  45. name: Schemas
  46. description: Enum values must not have duplicate entry
  47. formats:
  48. - oas3
  49. - oas3_1
  50. - oas3_2
  51. - oas2
  52. given: $
  53. howToFix: Enums need to be unique, you can't duplicate them in the same definition. Please remove the duplicate value.
  54. id: duplicated-entry-in-enum
  55. recommended: true
  56. severity: error
  57. then:
  58. function: duplicatedEnum
  59. type: validation
  60. info-description:
  61. category:
  62. description: The info object contains licencing, contact, authorship details and more. Checks to confirm required details have been completed.
  63. id: information
  64. name: Contract Information
  65. description: Info section is missing a description
  66. formats:
  67. - oas3
  68. - oas3_1
  69. - oas3_2
  70. - oas2
  71. given: $
  72. howToFix: The 'info' section is missing a description, surely you want people to know what this spec is all about, right?
  73. id: info-description
  74. recommended: true
  75. resolved: true
  76. severity: error
  77. then:
  78. function: infoDescription
  79. type: validation
  80. info-license-spdx:
  81. category:
  82. description: The info object contains licencing, contact, authorship details and more. Checks to confirm required details have been completed.
  83. id: information
  84. name: Contract Information
  85. description: License section cannot contain both an identifier and a URL, they are mutually exclusive.
  86. formats:
  87. - oas3
  88. - oas3_1
  89. - oas3_2
  90. - oas2
  91. given: $
  92. howToFix: A license can contain either a URL or an SPDX identifier, but not both, They are mutually exclusive and cannot both be present. Choose one or the other
  93. id: info-license-spdx
  94. recommended: true
  95. resolved: true
  96. severity: error
  97. then:
  98. function: infoLicenseURLSPDX
  99. type: validation
  100. migrate-zally-ignore:
  101. category:
  102. description: Validation rules make sure that certain characters or patterns have not been used that may cause issues when rendering in different types of applications.
  103. id: validation
  104. name: Validation
  105. description: x-zally-ignore keys should be migrated to x-lint-ignore for compatibility with vacuum
  106. formats:
  107. - oas3
  108. - oas3_1
  109. - oas3_2
  110. - oas2
  111. given: $
  112. howToFix: Migrate x-zally-ignore directives to vacuum's x-lint-ignore. Rename the key to x-lint-ignore and update the ignored rule id to the vacuum equivalent rule.
  113. id: migrate-zally-ignore
  114. recommended: true
  115. resolved: true
  116. severity: warn
  117. then:
  118. function: migrateZallyIgnore
  119. type: validation
  120. no-$ref-siblings:
  121. category:
  122. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  123. id: schemas
  124. name: Schemas
  125. description: $ref values cannot be placed next to other properties (like a description)
  126. formats:
  127. - oas2
  128. - oas3
  129. given: $
  130. howToFix: $ref values must not be placed next to sibling nodes, There should only be a single node when using $ref. A common mistake is adding 'description' next to a $ref. This is wrong. remove all siblings!
  131. id: no-$ref-siblings
  132. recommended: true
  133. severity: error
  134. then:
  135. function: refSiblings
  136. type: validation
  137. no-ambiguous-paths:
  138. category:
  139. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  140. id: operations
  141. name: Operations
  142. description: Paths need to resolve unambiguously from one another
  143. formats:
  144. - oas3
  145. - oas3_1
  146. - oas3_2
  147. - oas2
  148. given: $
  149. howToFix: Paths must all resolve unambiguously, they can't be confused with one another (/{id}/ambiguous and /ambiguous/{id} are the same thing. Make sure every path and the variables used are unique and do conflict with one another. Check the ordering of variables and the naming of path segments.
  150. id: no-ambiguous-paths
  151. recommended: true
  152. resolved: true
  153. severity: error
  154. then:
  155. function: noAmbiguousPaths
  156. type: validation
  157. no-eval-in-markdown:
  158. category:
  159. description: Validation rules make sure that certain characters or patterns have not been used that may cause issues when rendering in different types of applications.
  160. id: validation
  161. name: Validation
  162. description: Markdown descriptions must not have `eval()` statements'
  163. formats:
  164. - oas3
  165. - oas3_1
  166. - oas3_2
  167. - oas2
  168. given: $
  169. howToFix: Remove all references to 'eval()' in the description. These can be used by malicious actors to embed code in contracts that is then executed when read by a browser.
  170. id: no-eval-in-markdown
  171. recommended: true
  172. resolved: true
  173. severity: error
  174. then:
  175. function: noEvalDescription
  176. functionOptions:
  177. pattern: eval\(
  178. type: validation
  179. no-http-verbs-in-path:
  180. category:
  181. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  182. id: operations
  183. name: Operations
  184. description: Path segments must not contain an HTTP verb
  185. formats:
  186. - oas3
  187. - oas3_1
  188. - oas3_2
  189. - oas2
  190. given: $
  191. howToFix: When HTTP verbs (get/post/put etc) are used in path segments, it muddies the semantics of REST and creates a confusing and inconsistent experience. It's highly recommended that verbs are not used in path segments. Replace those HTTP verbs with more meaningful nouns.
  192. id: no-http-verbs-in-path
  193. recommended: true
  194. severity: warn
  195. then:
  196. function: noVerbsInPath
  197. type: style
  198. no-request-body:
  199. category:
  200. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  201. id: operations
  202. name: Operations
  203. description: HTTP GET and DELETE should not accept request bodies
  204. formats:
  205. - oas3
  206. - oas3_1
  207. - oas3_2
  208. given: $
  209. howToFix: Remove 'requestBody' from HTTP GET and DELETE methods
  210. id: no-request-body
  211. recommended: true
  212. severity: warn
  213. then:
  214. function: noRequestBody
  215. type: style
  216. no-script-tags-in-markdown:
  217. category:
  218. description: Validation rules make sure that certain characters or patterns have not been used that may cause issues when rendering in different types of applications.
  219. id: validation
  220. name: Validation
  221. description: Markdown descriptions must not have `<script>` tags'
  222. formats:
  223. - oas3
  224. - oas3_1
  225. - oas3_2
  226. - oas2
  227. given: $
  228. howToFix: Remove all references to '<script>' tags from the description. These can be used by malicious actors to load remote code if the spec is being parsed by a browser.
  229. id: no-script-tags-in-markdown
  230. recommended: true
  231. resolved: true
  232. severity: error
  233. then:
  234. function: noEvalDescription
  235. functionOptions:
  236. pattern: <script
  237. type: validation
  238. no-unnecessary-combinator:
  239. category:
  240. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  241. id: schemas
  242. name: Schemas
  243. description: Schema combinators (allOf, anyOf, oneOf) with only one item should be replaced with the item directly.
  244. formats:
  245. - oas3
  246. - oas3_1
  247. - oas3_2
  248. given: $
  249. howToFix: Schema combinators (allOf, anyOf, oneOf) with only a single item are unnecessary and should be replaced with the item directly for cleaner, more readable schemas.
  250. id: no-unnecessary-combinator
  251. recommended: true
  252. resolved: true
  253. severity: warn
  254. then:
  255. function: oasUnnecessaryCombinator
  256. type: style
  257. oas-missing-type:
  258. category:
  259. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  260. id: schemas
  261. name: Schemas
  262. description: All schemas and their properties should have a type field (unless using enum, const, or a composition)
  263. formats:
  264. - oas3
  265. - oas3_1
  266. - oas3_2
  267. given: $
  268. howToFix: 'Add a `type` field to all schemas and properties. Valid types are: string, number, integer, boolean, array, object, or null.'
  269. id: oas-missing-type
  270. recommended: true
  271. severity: info
  272. then:
  273. function: missingType
  274. type: validation
  275. oas-schema-check:
  276. category:
  277. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  278. id: schemas
  279. name: Schemas
  280. description: All document schemas must have a valid type defined
  281. formats:
  282. - oas3
  283. - oas3_1
  284. - oas3_2
  285. given: $
  286. howToFix: Make sure each schema has a value type defined. Without a type, the schema is useless
  287. id: oas-schema-check
  288. recommended: true
  289. severity: error
  290. then:
  291. function: schemaTypeCheck
  292. type: validation
  293. oas2-anyOf:
  294. category:
  295. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  296. id: schemas
  297. name: Schemas
  298. description: '`anyOf` was introduced in OpenAPI 3.0, cannot be used un OpenAPI 2 specs'
  299. formats:
  300. - oas2
  301. given: $
  302. howToFix: You can't use 'anyOf' in Swagger/OpenAPI 2 specs. It was added in version 3. You have to remove it
  303. id: oas2-anyOf
  304. recommended: true
  305. severity: error
  306. then:
  307. function: oasPolymorphicAnyOf
  308. type: validation
  309. oas2-api-host:
  310. category:
  311. description: The info object contains licencing, contact, authorship details and more. Checks to confirm required details have been completed.
  312. id: information
  313. name: Contract Information
  314. description: OpenAPI `host` must be present and a non-empty string
  315. formats:
  316. - oas2
  317. given: $
  318. howToFix: The 'host' value is missing. How is a user supposed to know where the API actually lives? The host is critical in order for consumers to be able to call the API. Add an API host!
  319. id: oas2-api-host
  320. recommended: true
  321. severity: info
  322. then:
  323. field: host
  324. function: truthy
  325. type: style
  326. oas2-api-schemes:
  327. category:
  328. description: The info object contains licencing, contact, authorship details and more. Checks to confirm required details have been completed.
  329. id: information
  330. name: Contract Information
  331. description: OpenAPI host `schemes` must be present and non-empty array
  332. formats:
  333. - oas2
  334. given: $
  335. howToFix: Add an array of supported host 'schemes' to the root of the specification. These are the available API schemes (like https/http).
  336. id: oas2-api-schemes
  337. recommended: true
  338. severity: warn
  339. then:
  340. field: schemes
  341. function: schema
  342. functionOptions:
  343. forceValidation: true
  344. schema:
  345. items:
  346. minItems: 1
  347. type: string
  348. type: array
  349. uniqueItems: true
  350. type: validation
  351. oas2-discriminator:
  352. category:
  353. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  354. id: schemas
  355. name: Schemas
  356. description: discriminators are used correctly in schemas
  357. formats:
  358. - oas2
  359. given: $
  360. howToFix: When using polymorphism, a discriminator should also be provided to allow tools to understand how to compose your models when generating code. Add a correct discriminator.
  361. id: oas2-discriminator
  362. recommended: true
  363. resolved: true
  364. severity: error
  365. then:
  366. function: oasDiscriminator
  367. type: validation
  368. oas2-host-not-example:
  369. category:
  370. description: The info object contains licencing, contact, authorship details and more. Checks to confirm required details have been completed.
  371. id: information
  372. name: Contract Information
  373. description: Host URL should not point at example.com
  374. formats:
  375. - oas2
  376. given: $.host
  377. howToFix: Remove 'example.com' from the host URL, it's not going to work.
  378. id: oas2-host-not-example
  379. recommended: true
  380. severity: warn
  381. then:
  382. function: pattern
  383. functionOptions:
  384. notMatch: example\.com
  385. type: style
  386. oas2-host-trailing-slash:
  387. category:
  388. description: The info object contains licencing, contact, authorship details and more. Checks to confirm required details have been completed.
  389. id: information
  390. name: Contract Information
  391. description: Host URL should not contain a trailing slash
  392. formats:
  393. - oas2
  394. given: $.host
  395. howToFix: Remove the trailing slash from the host URL. This may cause some tools to incorrectly add a double slash to paths.
  396. id: oas2-host-trailing-slash
  397. recommended: true
  398. severity: warn
  399. then:
  400. function: pattern
  401. functionOptions:
  402. notMatch: /$
  403. type: style
  404. oas2-oneOf:
  405. category:
  406. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  407. id: schemas
  408. name: Schemas
  409. description: '`oneOf` was introduced in OpenAPI 3.0, cannot be used un OpenAPI 2 specs'
  410. formats:
  411. - oas2
  412. given: $
  413. howToFix: You can't use 'oneOf' in Swagger/OpenAPI 2 specs. It was added in version 3. You have to remove it
  414. id: oas2-oneOf
  415. recommended: true
  416. severity: error
  417. then:
  418. function: oasPolymorphicOneOf
  419. type: validation
  420. oas2-operation-formData-consume-check:
  421. category:
  422. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  423. id: operations
  424. name: Operations
  425. description: 'Operations with `in: formData` parameter must include `application/x-www-form-urlencoded` or `multipart/form-data` in their `consumes` property.'
  426. formats:
  427. - oas2
  428. given: $
  429. howToFix: When using 'formData', the parameter must include the correct mime-types. Make sure you use 'application/x-www-form-urlencoded' or 'multipart/form-data' as the 'consumes' value in your parameter.
  430. id: oas2-operation-formData-consume-check
  431. recommended: true
  432. resolved: true
  433. severity: warn
  434. then:
  435. function: oasOpFormDataConsumeCheck
  436. type: validation
  437. oas2-operation-security-defined:
  438. category:
  439. description: Security plays a central role in RESTful APIs. These rules make sure that the correct definitions have been used and put in the right places.
  440. id: security
  441. name: Security
  442. description: '`security` values must match a scheme defined in securityDefinitions'
  443. formats:
  444. - oas2
  445. given: $
  446. howToFix: When defining security definitions for operations, you need to ensure they match the globally defined security schemes. Check $.securityDefinitions to make sure your values align.
  447. id: oas2-operation-security-defined
  448. recommended: true
  449. resolved: true
  450. severity: error
  451. then:
  452. function: oas2OpSecurityDefined
  453. type: validation
  454. oas2-parameter-description:
  455. category:
  456. description: Documentation is really important, in OpenAPI, just about everything can and should have a description. This set of rules checks for absent descriptions, poor quality descriptions (copy/paste), or short descriptions.
  457. id: descriptions
  458. name: Descriptions
  459. description: Parameter description checks
  460. formats:
  461. - oas2
  462. given: $
  463. howToFix: All parameters should have a description. Descriptions are critical to understanding how an API works correctly. Please add a description to all parameters.
  464. id: oas2-parameter-description
  465. recommended: true
  466. resolved: true
  467. severity: warn
  468. then:
  469. function: oasParamDescriptions
  470. type: style
  471. oas2-schema:
  472. category:
  473. description: Validation rules make sure that certain characters or patterns have not been used that may cause issues when rendering in different types of applications.
  474. id: validation
  475. name: Validation
  476. description: OpenAPI 2 specification is invalid
  477. formats:
  478. - oas2
  479. given: $
  480. howToFix: The schema isn't valid Swagger/OpenAPI 2. Check the errors for more details
  481. id: oas2-schema
  482. recommended: true
  483. severity: error
  484. then:
  485. function: oasDocumentSchema
  486. type: validation
  487. oas2-unused-definition:
  488. category:
  489. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  490. id: schemas
  491. name: Schemas
  492. description: Check for unused definitions and bad references
  493. formats:
  494. - oas2
  495. given: $
  496. howToFix: Orphaned components are not used by anything. You might have plans to use them later, or they could be older schemas that never got cleaned up. A clean spec is a happy spec. Prune your orphaned components.
  497. id: oas2-unused-definition
  498. recommended: true
  499. severity: warn
  500. then:
  501. function: oasUnusedComponent
  502. type: validation
  503. oas3-api-servers:
  504. category:
  505. description: Validation rules make sure that certain characters or patterns have not been used that may cause issues when rendering in different types of applications.
  506. id: validation
  507. name: Validation
  508. description: Check for valid API servers definition
  509. formats:
  510. - oas3
  511. given: $
  512. howToFix: Ensure server URIs are correct and valid, check the schemes, ensure descriptions are complete.
  513. id: oas3-api-servers
  514. recommended: true
  515. severity: warn
  516. then:
  517. function: oasAPIServers
  518. type: validation
  519. oas3-example-external-check:
  520. category:
  521. description: Examples help consumers understand how API calls should look. They are really important for automated tooling for mocking and testing. These rules check examples have been added to component schemas, parameters and operations. These rules also check that examples match the schema and types provided.
  522. id: examples
  523. name: Examples
  524. description: Examples cannot use both `value` and `externalValue` together.
  525. formats:
  526. - oas3
  527. - oas3_1
  528. - oas3_2
  529. given: $
  530. howToFix: Examples are critical for consumers to be able to understand schemas and models defined by the spec. Without examples, developers can't understand the type of data the API will return in real life. Examples are turned into mocks and can provide a rich testing capability for APIs. Add detailed examples everywhere!
  531. id: oas3-example-external-check
  532. recommended: true
  533. severity: warn
  534. then:
  535. function: oasExampleExternal
  536. type: validation
  537. oas3-missing-example:
  538. category:
  539. description: Examples help consumers understand how API calls should look. They are really important for automated tooling for mocking and testing. These rules check examples have been added to component schemas, parameters and operations. These rules also check that examples match the schema and types provided.
  540. id: examples
  541. name: Examples
  542. description: Ensure everything that can have an example, contains one
  543. formats:
  544. - oas3
  545. - oas3_1
  546. - oas3_2
  547. given: $
  548. howToFix: Examples are critical for consumers to be able to understand schemas and models defined by the spec. Without examples, developers can't understand the type of data the API will return in real life. Examples are turned into mocks and can provide a rich testing capability for APIs. Add detailed examples everywhere!
  549. id: oas3-missing-example
  550. recommended: true
  551. severity: warn
  552. then:
  553. function: oasExampleMissing
  554. type: validation
  555. oas3-no-$ref-siblings:
  556. category:
  557. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  558. id: schemas
  559. name: Schemas
  560. description: '`$ref` values cannot be placed next to other properties, except `description` and `summary`'
  561. formats:
  562. - oas3_1
  563. given: $
  564. howToFix: $ref values must not be placed next to sibling nodes, except `description` and `summary` nodes. This is wrong. remove all additional siblings!
  565. id: oas3-no-$ref-siblings
  566. recommended: true
  567. severity: error
  568. then:
  569. function: oasRefSiblings
  570. type: validation
  571. oas3-operation-security-defined:
  572. category:
  573. description: Security plays a central role in RESTful APIs. These rules make sure that the correct definitions have been used and put in the right places.
  574. id: security
  575. name: Security
  576. description: '`security` values must match a scheme defined in components.securitySchemes'
  577. formats:
  578. - oas3
  579. - oas3_1
  580. - oas3_2
  581. given: $
  582. howToFix: When defining security values for operations, you need to ensure they match the globally defined security schemes. Check $.components.securitySchemes to make sure your values align.
  583. id: oas3-operation-security-defined
  584. recommended: true
  585. resolved: true
  586. severity: error
  587. then:
  588. function: oasOpSecurityDefined
  589. functionOptions:
  590. schemesPath: $.components.securitySchemes
  591. type: validation
  592. oas3-parameter-description:
  593. category:
  594. description: Documentation is really important, in OpenAPI, just about everything can and should have a description. This set of rules checks for absent descriptions, poor quality descriptions (copy/paste), or short descriptions.
  595. id: descriptions
  596. name: Descriptions
  597. description: Parameter description checks
  598. formats:
  599. - oas3
  600. - oas3_1
  601. - oas3_2
  602. given: $
  603. howToFix: All parameters should have a description. Descriptions are critical to understanding how an API works correctly. Please add a description to all parameters.
  604. id: oas3-parameter-description
  605. recommended: true
  606. resolved: true
  607. severity: warn
  608. then:
  609. function: oasParamDescriptions
  610. type: style
  611. oas3-schema:
  612. category:
  613. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  614. id: schemas
  615. name: Schemas
  616. description: OpenAPI 3+ specification is invalid
  617. formats:
  618. - oas3
  619. - oas3_1
  620. - oas3_2
  621. given: $
  622. howToFix: The schema isn't valid OpenAPI 3. Check the errors for more details
  623. id: oas3-schema
  624. recommended: true
  625. severity: error
  626. then:
  627. function: oasDocumentSchema
  628. type: validation
  629. oas3-unused-component:
  630. category:
  631. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  632. id: schemas
  633. name: Schemas
  634. description: Check for unused components and bad references
  635. formats:
  636. - oas3
  637. - oas3_1
  638. - oas3_2
  639. given: $
  640. howToFix: Unused components / definitions are generally the result of the OpenAPI contract being updated without considering references. Another reference could have been updated, or an operation changed that no longer references this component. Remove this component from the spec, or re-link to it from another component or operation to fix the problem.
  641. id: oas3-unused-component
  642. recommended: true
  643. severity: warn
  644. then:
  645. function: oasUnusedComponent
  646. type: validation
  647. oas3-valid-schema-example:
  648. category:
  649. description: Examples help consumers understand how API calls should look. They are really important for automated tooling for mocking and testing. These rules check examples have been added to component schemas, parameters and operations. These rules also check that examples match the schema and types provided.
  650. id: examples
  651. name: Examples
  652. description: If an example has been used, check the schema is valid
  653. formats:
  654. - oas3
  655. - oas3_1
  656. - oas3_2
  657. given: $
  658. howToFix: Examples are critical for consumers to be able to understand schemas and models defined by the spec. Without examples, developers can't understand the type of data the API will return in real life. Examples are turned into mocks and can provide a rich testing capability for APIs. Add detailed examples everywhere!
  659. id: oas3-valid-schema-example
  660. recommended: true
  661. severity: warn
  662. then:
  663. function: oasExampleSchema
  664. type: validation
  665. operation-description:
  666. category:
  667. description: Documentation is really important, in OpenAPI, just about everything can and should have a description. This set of rules checks for absent descriptions, poor quality descriptions (copy/paste), or short descriptions.
  668. id: descriptions
  669. name: Descriptions
  670. description: Operation description checks
  671. formats:
  672. - oas3
  673. - oas3_1
  674. - oas3_2
  675. - oas2
  676. given: $
  677. howToFix: All operations must have a description. Descriptions explain how the operation works, and how users should use it and what to expect. Operation descriptions make up the bulk of API documentation. so please, add a description!
  678. id: operation-description
  679. recommended: true
  680. resolved: true
  681. severity: warn
  682. then:
  683. function: oasDescriptions
  684. functionOptions:
  685. minWords: "1"
  686. type: validation
  687. operation-operationId:
  688. category:
  689. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  690. id: operations
  691. name: Operations
  692. description: Every operation must contain an `operationId`.
  693. formats:
  694. - oas3
  695. - oas3_1
  696. - oas3_2
  697. - oas2
  698. given: $
  699. howToFix: Every single operation needs an operationId. It's a critical requirement to be able to identify each individual operation uniquely. Please add an operationId to the operation.
  700. id: operation-operationId
  701. recommended: true
  702. severity: error
  703. then:
  704. function: oasOpId
  705. type: validation
  706. operation-operationId-unique:
  707. category:
  708. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  709. id: operations
  710. name: Operations
  711. description: Every operation must have unique `operationId`.
  712. formats:
  713. - oas3
  714. - oas3_1
  715. - oas3_2
  716. - oas2
  717. given: $.paths
  718. howToFix: An operationId needs to be unique, there can't be any duplicates in the document, you can't re-use them. Make sure the ID used for this operation is unique.
  719. id: operation-operationId-unique
  720. recommended: true
  721. resolved: true
  722. severity: error
  723. then:
  724. function: oasOpIdUnique
  725. type: validation
  726. operation-operationId-valid-in-url:
  727. category:
  728. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  729. id: operations
  730. name: Operations
  731. description: OperationId must use URL friendly characters
  732. formats:
  733. - oas3
  734. - oas3_1
  735. - oas3_2
  736. - oas2
  737. given: $.paths[*][*]
  738. howToFix: An operationId is critical to correct code generation and operation identification. The operationId should really be designed in a way to make it friendly when used as part of a URL. Remove non-standard URL characters.
  739. id: operation-operationId-valid-in-url
  740. recommended: true
  741. resolved: true
  742. severity: error
  743. then:
  744. field: operationId
  745. function: pattern
  746. functionOptions:
  747. match: ^[A-Za-z0-9-._~:/?#\[\]@!\$&'()*+,;=]*$
  748. type: validation
  749. operation-parameters:
  750. category:
  751. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  752. id: operations
  753. name: Operations
  754. description: Operation parameters are unique and non-repeating.
  755. formats:
  756. - oas3
  757. - oas3_1
  758. - oas3_2
  759. - oas2
  760. given: $.paths
  761. howToFix: Make sure that all the operation parameters are unique and non-repeating, don't duplicate names, don'tre-use parameter names in the same operation.
  762. id: operation-parameters
  763. recommended: true
  764. resolved: true
  765. severity: error
  766. then:
  767. function: oasOpParams
  768. type: validation
  769. operation-success-response:
  770. category:
  771. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  772. id: operations
  773. name: Operations
  774. description: Operation must have at least one `2xx` or a `3xx` response.
  775. formats:
  776. - oas3
  777. - oas3_1
  778. - oas3_2
  779. - oas2
  780. given: $
  781. howToFix: Make sure that your operation returns a 'success' response via 2xx or 3xx response code. An API consumer will always expect a success response
  782. id: operation-success-response
  783. recommended: true
  784. resolved: true
  785. severity: warn
  786. then:
  787. field: responses
  788. function: oasOpSuccessResponse
  789. type: style
  790. operation-tag-defined:
  791. category:
  792. description: Tags are used as meta-data for operations. They are mainly used by tooling as a taxonomy mechanism to build navigation, search and more. Tags are important as they help consumers navigate the contract when using documentation, testing, code generation or analysis tools.
  793. id: tags
  794. name: Tags
  795. description: Operation tags must be defined in global tags.
  796. formats:
  797. - oas3
  798. - oas3_1
  799. - oas3_2
  800. - oas2
  801. given: $
  802. howToFix: This tag has not been defined in the global scope, you should always ensure that any tags used in operations, are defined globally in the root 'tags' definition.
  803. id: operation-tag-defined
  804. recommended: true
  805. resolved: true
  806. severity: warn
  807. then:
  808. function: oasTagDefined
  809. type: validation
  810. operation-tags:
  811. category:
  812. description: Tags are used as meta-data for operations. They are mainly used by tooling as a taxonomy mechanism to build navigation, search and more. Tags are important as they help consumers navigate the contract when using documentation, testing, code generation or analysis tools.
  813. id: tags
  814. name: Tags
  815. description: Operation `tags` are missing/empty
  816. formats:
  817. - oas3
  818. - oas3_1
  819. - oas3_2
  820. - oas2
  821. given: $
  822. howToFix: Operations use tags to define the domain(s) they are apart of. Generally a single tag per operation is used, however some tools use multiple tags. The point is that you need tags! Add some tags to the operation that match the globally available ones.
  823. id: operation-tags
  824. recommended: true
  825. resolved: true
  826. severity: warn
  827. then:
  828. function: oasOperationTags
  829. type: validation
  830. path-declarations-must-exist:
  831. category:
  832. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  833. id: operations
  834. name: Operations
  835. description: Path parameter declarations must not be empty ex. `/api/{}` is invalid
  836. formats:
  837. - oas3
  838. - oas3_1
  839. - oas3_2
  840. - oas2
  841. given: $.paths
  842. howToFix: Paths define the endpoint for operations. Without paths, there is no API. You need to add 'paths' to the root of the specification.
  843. id: path-declarations-must-exist
  844. recommended: true
  845. resolved: true
  846. severity: error
  847. then:
  848. function: pattern
  849. functionOptions:
  850. notMatch: '{}'
  851. type: validation
  852. path-item-refs:
  853. category:
  854. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  855. id: operations
  856. name: Operations
  857. description: Path items should not use references ($ref) values. They are technically not allowed.
  858. formats:
  859. - oas3
  860. - oas3_1
  861. - oas3_2
  862. given: $
  863. howToFix: Path items should not use references for defining operations. It's technically allowed, but not great style
  864. id: path-item-refs
  865. recommended: true
  866. severity: info
  867. then:
  868. function: pathItemReferences
  869. type: validation
  870. path-keys-no-trailing-slash:
  871. category:
  872. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  873. id: operations
  874. name: Operations
  875. description: Path must not end with a slash
  876. formats:
  877. - oas3
  878. - oas3_1
  879. - oas3_2
  880. - oas2
  881. given: $.paths
  882. howToFix: Paths should not end with a trailing slash, it can confuse tooling and isn't valid as a path Remove the trailing slash from the path.
  883. id: path-keys-no-trailing-slash
  884. recommended: true
  885. resolved: true
  886. severity: warn
  887. then:
  888. function: pattern
  889. functionOptions:
  890. notMatch: .+\/$
  891. type: validation
  892. path-not-include-query:
  893. category:
  894. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  895. id: operations
  896. name: Operations
  897. description: Path must not include query string
  898. formats:
  899. - oas3
  900. - oas3_1
  901. - oas3_2
  902. - oas2
  903. given: $.paths
  904. howToFix: Query strings are defined as parameters for an operation, they should not be included in the path Please remove it and correctly define as a parameter.
  905. id: path-not-include-query
  906. recommended: true
  907. resolved: true
  908. severity: error
  909. then:
  910. function: pattern
  911. functionOptions:
  912. notMatch: \?
  913. type: validation
  914. path-params:
  915. category:
  916. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  917. id: operations
  918. name: Operations
  919. description: Path parameters must be defined and valid.
  920. formats:
  921. - oas3
  922. - oas3_1
  923. - oas3_2
  924. given: $
  925. howToFix: Path parameters need to match up with the parameters defined for the path, or in an operation that sits under that path. Make sure variable names match up and are defined correctly.
  926. id: path-params
  927. recommended: true
  928. resolved: true
  929. severity: error
  930. then:
  931. function: oasPathParam
  932. type: validation
  933. paths-kebab-case:
  934. category:
  935. description: Operations are the core of the contract, they define paths and HTTP methods. These rules check operations have been well constructed, looks for operationId, parameter, schema and return types in depth.
  936. id: operations
  937. name: Operations
  938. description: Path segments must only use kebab-case (no underscores or uppercase)
  939. formats:
  940. - oas3
  941. - oas3_1
  942. - oas3_2
  943. - oas2
  944. given: $
  945. howToFix: Path segments should not contain any uppercase letters, punctuation or underscores. The only valid way to separate words in a segment, is to use a hyphen '-'. The elements that are violating the rule are highlighted in the violation description. These are the elements that need to change.
  946. id: paths-kebab-case
  947. recommended: true
  948. severity: warn
  949. then:
  950. function: pathsKebabCase
  951. type: validation
  952. typed-enum:
  953. category:
  954. description: Schemas are how request bodies and response payloads are defined. They define the data going in and the data flowing out of an operation. These rules check for structural validity, checking types, checking required fields and validating correct use of structures.
  955. id: schemas
  956. name: Schemas
  957. description: Enum values must respect the specified type
  958. formats:
  959. - oas3
  960. - oas3_1
  961. - oas3_2
  962. - oas2
  963. given: $
  964. howToFix: Enum values lock down the number of variable inputs a parameter or schema can have. The problem here is that the Enum defined, does not match the specified type. Fix the type!
  965. id: typed-enum
  966. recommended: true
  967. resolved: true
  968. severity: warn
  969. then:
  970. function: typedEnum
  971. type: validation