|
| 1 | +extends: [ "spectral:oas" ] |
| 2 | +rules: |
| 3 | + strings-need-bounds: |
| 4 | + description: Strings must be bounded unless they already use format/enum/pattern |
| 5 | + given: |
| 6 | + - "$.components.schemas.*" |
| 7 | + - "$.paths.*.*.parameters[*].schema" |
| 8 | + - "$.paths.*.*.requestBody.content.*.schema" |
| 9 | + - "$.paths.*.*.responses.*.content.*.schema" |
| 10 | + then: |
| 11 | + function: schema |
| 12 | + functionOptions: |
| 13 | + schema: |
| 14 | + if: |
| 15 | + properties: { type: { const: string } } |
| 16 | + required: [ type ] |
| 17 | + then: |
| 18 | + anyOf: |
| 19 | + - required: [ maxLength ] |
| 20 | + - required: [ enum ] |
| 21 | + - required: [ pattern ] |
| 22 | + - required: [ format ] |
| 23 | + severity: warn |
| 24 | + |
| 25 | + arrays-need-maxitems: |
| 26 | + given: |
| 27 | + - "$.components.schemas.*" |
| 28 | + - "$.paths.*.*.parameters[*].schema" |
| 29 | + - "$.paths.*.*.requestBody.content.*.schema" |
| 30 | + - "$.paths.*.*.responses.*.content.*.schema" |
| 31 | + then: |
| 32 | + function: schema |
| 33 | + functionOptions: |
| 34 | + schema: |
| 35 | + if: |
| 36 | + properties: { type: { const: array } } |
| 37 | + required: [ type ] |
| 38 | + then: |
| 39 | + required: [ maxItems ] |
| 40 | + severity: warn |
| 41 | + |
| 42 | + objects-should-forbid-unknown: |
| 43 | + description: |
| 44 | + Request objects should set additionalProperties: false |
| 45 | + given: |
| 46 | + - "$.paths.*.*.requestBody.content.*.schema" |
| 47 | + then: |
| 48 | + function: schema |
| 49 | + functionOptions: |
| 50 | + schema: |
| 51 | + if: |
| 52 | + properties: { type: { const: object } } |
| 53 | + required: [ type ] |
| 54 | + then: |
| 55 | + required: [ additionalProperties ] |
| 56 | + properties: { additionalProperties: { const: false } } |
| 57 | + severity: warn |
| 58 | + |
| 59 | + path-string-params-need-format-or-pattern: |
| 60 | + given: |
| 61 | + - "$.paths.*.*.parameters[?(@.in=='path')].schema" |
| 62 | + then: |
| 63 | + function: schema |
| 64 | + functionOptions: |
| 65 | + schema: |
| 66 | + if: |
| 67 | + properties: { type: { const: string } } |
| 68 | + required: [ type ] |
| 69 | + then: |
| 70 | + anyOf: |
| 71 | + - required: [ format ] |
| 72 | + - required: [ pattern ] |
| 73 | + severity: warn |
| 74 | + |
| 75 | + param-id-needs-format-or-pattern: |
| 76 | + given: |
| 77 | + - "$.paths.*.*.parameters[?(@.name=='id')].schema" |
| 78 | + then: |
| 79 | + function: schema |
| 80 | + functionOptions: |
| 81 | + schema: |
| 82 | + anyOf: |
| 83 | + - required: [ format ] |
| 84 | + - required: [ pattern ] |
| 85 | + severity: warn |
| 86 | + |
| 87 | + schema-id-prop-needs-format-or-pattern: |
| 88 | + given: |
| 89 | + - "$.components.schemas.*.properties.id" |
| 90 | + - "$.paths.*.*.requestBody.content.*.schema.properties.id" |
| 91 | + then: |
| 92 | + function: schema |
| 93 | + functionOptions: |
| 94 | + schema: |
| 95 | + anyOf: |
| 96 | + - required: [ format ] |
| 97 | + - required: [ pattern ] |
| 98 | + severity: warn |
0 commit comments