|
| 1 | +extends: ["spectral:oas"] |
| 2 | +rules: |
| 3 | +# Built-in rules |
| 4 | + # Descriptions |
| 5 | + oas3-parameter-description: warn |
| 6 | + oas2-parameter-description: warn |
| 7 | + tag-description: info |
| 8 | + # Document info |
| 9 | + info-contact: info |
| 10 | + info-description: warn |
| 11 | + info-license: warn |
| 12 | + # Examples |
| 13 | + oas3-valid-media-example: false |
| 14 | + oas3-valid-schema-example: false |
| 15 | + oas2-valid-media-example: false |
| 16 | + # Operations |
| 17 | + operation-operationId: false |
| 18 | + operation-operationId-unique: false |
| 19 | + operation-operationId-valid-in-url: false |
| 20 | + operation-tag-defined: warn |
| 21 | + operation-tags: warn |
| 22 | + # Responses |
| 23 | + operation-success-response: warn |
| 24 | + # Schema |
| 25 | + oas3-schema: error |
| 26 | + oas2-schema: error |
| 27 | + array-items: false |
| 28 | + # Tags |
| 29 | + openapi-tags: warn |
| 30 | + openapi-tags-alphabetical: info |
| 31 | + # Turn off some built-in rules |
| 32 | + operation-description: false |
| 33 | + operation-singular-tag: false |
| 34 | +# Custom rules |
| 35 | + # Descriptions |
| 36 | + avoid-problematic-words: |
| 37 | + description: Ban certain words from descriptions |
| 38 | + message: "Use appropriate replacements for problematic terms" |
| 39 | + severity: warn |
| 40 | + given: "$..*.description" |
| 41 | + then: |
| 42 | + function: pattern |
| 43 | + functionOptions: |
| 44 | + notMatch: /(blacklist|whitelist|execute|kill)/i |
| 45 | + # Examples |
| 46 | + operation-success-examples: |
| 47 | + formats: ["oas3_1"] |
| 48 | + description: Response code 200 should have at least one example. |
| 49 | + message: "Each response body should have a realistic example. It must not contain any sensitive or confidential data." |
| 50 | + severity: info |
| 51 | + given: $.paths[*].[*].responses.[200].content.[application/json] |
| 52 | + then: |
| 53 | + field: examples |
| 54 | + function: defined |
| 55 | + # Extensions |
| 56 | + internal-extension: |
| 57 | + description: Operations should not have x-internal extension. |
| 58 | + message: "Do not publish x-internal operations" |
| 59 | + severity: error |
| 60 | + given: $.paths[*].[get,put,post,delete,options,head,patch,trace] |
| 61 | + then: |
| 62 | + field: x-internal |
| 63 | + function: undefined |
| 64 | + # Operations |
| 65 | + operation-summary: |
| 66 | + description: Operations should have summaries. |
| 67 | + message: "Each operation should have a summary" |
| 68 | + severity: error |
| 69 | + recommended: true |
| 70 | + given: $.paths[*].[get,put,post,delete,options,head,patch,trace] |
| 71 | + then: |
| 72 | + field: summary |
| 73 | + function: defined |
| 74 | + operation-summary-length: |
| 75 | + description: Operation summary should be between 5 and 45 characters |
| 76 | + given: "$.paths[*].[get,put,post,delete,options,head,patch,trace]" |
| 77 | + then: |
| 78 | + field: summary |
| 79 | + function: length |
| 80 | + functionOptions: |
| 81 | + max: 45 |
| 82 | + min: 5 |
| 83 | + severity: warn |
| 84 | + simple-verbs-in-summary: |
| 85 | + given: |
| 86 | + - "$.paths[*][*].summary" |
| 87 | + then: |
| 88 | + function: pattern |
| 89 | + functionOptions: |
| 90 | + notMatch: "Retrieve|Return|List *" |
| 91 | + severity: warn |
| 92 | + description: Summaries should use common verbs. |
| 93 | + message: "Summaries should use common verbs like Get, Update, Delete whenever possible" |
| 94 | + # NOTE: This one hiccups on acronyms so perhaps too noisy |
| 95 | + # docs-operation-summary-sentence-case: |
| 96 | + # description: Operation summary should be sentence cased |
| 97 | + # given: "$.paths[*].[get,put,post,delete,options,head,patch,trace]" |
| 98 | + # then: |
| 99 | + # field: summary |
| 100 | + # function: pattern |
| 101 | + # functionOptions: |
| 102 | + # match: /^[A-Z]+[^A-Z]+$/ |
| 103 | + # severity: warn |
| 104 | + |
0 commit comments