|
| 1 | +extends: |
| 2 | + - spectral:oas |
| 3 | + |
| 4 | +rules: |
| 5 | + # Disable built-in rules already covered by Redocly |
| 6 | + info-contact: off |
| 7 | + info-description: off |
| 8 | + operation-tag-defined: off |
| 9 | + oas3-api-servers: off |
| 10 | + |
| 11 | + # ============================================================ |
| 12 | + # Naming Conventions (README: Naming Conventions) |
| 13 | + # ============================================================ |
| 14 | + |
| 15 | + # Fields must be camelCase (excludes TestWebhookResponse which mirrors external format) |
| 16 | + field-names-camelCase: |
| 17 | + description: Schema property names must be camelCase |
| 18 | + message: "Property '{{property}}' must be camelCase. See openapi/README.md#field-naming" |
| 19 | + severity: error |
| 20 | + given: "$.components.schemas[?(@property != 'TestWebhookResponse')].properties" |
| 21 | + then: |
| 22 | + field: "@key" |
| 23 | + function: casing |
| 24 | + functionOptions: |
| 25 | + type: camel |
| 26 | + |
| 27 | + # Enum values must be UPPER_SNAKE_CASE (dots allowed for webhook namespacing) |
| 28 | + enum-values-upper-snake-case: |
| 29 | + description: Enum values must be UPPER_SNAKE_CASE |
| 30 | + message: "Enum value '{{value}}' must be UPPER_SNAKE_CASE. See openapi/README.md#field-naming" |
| 31 | + severity: error |
| 32 | + given: "$.components.schemas.*.enum[*]" |
| 33 | + then: |
| 34 | + function: pattern |
| 35 | + functionOptions: |
| 36 | + match: "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*(\\.[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)*$" |
| 37 | + |
| 38 | + # Query parameters must be camelCase |
| 39 | + query-params-camelCase: |
| 40 | + description: Query parameter names must be camelCase |
| 41 | + message: "Query parameter '{{value}}' must be camelCase. See openapi/README.md#field-naming" |
| 42 | + severity: error |
| 43 | + given: "$.paths.*.*.parameters[?(@.in=='query')].name" |
| 44 | + then: |
| 45 | + function: casing |
| 46 | + functionOptions: |
| 47 | + type: camel |
| 48 | + |
| 49 | + # Path parameters must be camelCase |
| 50 | + path-params-camelCase: |
| 51 | + description: Path parameter names must be camelCase |
| 52 | + message: "Path parameter '{{value}}' must be camelCase. See openapi/README.md#field-naming" |
| 53 | + severity: error |
| 54 | + given: "$.paths.*.*.parameters[?(@.in=='path')].name" |
| 55 | + then: |
| 56 | + function: casing |
| 57 | + functionOptions: |
| 58 | + type: camel |
| 59 | + |
| 60 | + # ============================================================ |
| 61 | + # Discriminators and Polymorphism (README: OpenAPI Best Practices) |
| 62 | + # ============================================================ |
| 63 | + |
| 64 | + # oneOf must include a discriminator |
| 65 | + oneOf-must-have-discriminator: |
| 66 | + description: oneOf schemas must include a discriminator |
| 67 | + message: "oneOf without a discriminator. See openapi/README.md#discriminators-and-polymorphism" |
| 68 | + severity: warn |
| 69 | + given: "$.components.schemas[?(@.oneOf)]" |
| 70 | + then: |
| 71 | + field: discriminator |
| 72 | + function: truthy |
| 73 | + |
| 74 | + # ============================================================ |
| 75 | + # No Inline Schemas (README: Avoid Inline Schemas) |
| 76 | + # ============================================================ |
| 77 | + |
| 78 | + # Request bodies must use $ref, not inline schemas. |
| 79 | + # Note: Spectral resolves $refs in the bundled spec, so some component-level |
| 80 | + # false positives appear — the real violations are on paths.* entries. |
| 81 | + no-inline-request-schema: |
| 82 | + description: Request body schemas must use $ref, not inline definitions |
| 83 | + message: "Use $ref for request body schema instead of inline definition. See openapi/README.md#avoid-inline-schemas-in-request-and-response-definitions" |
| 84 | + severity: error |
| 85 | + given: "$.paths[*][get,post,put,patch,delete].requestBody.content[application/json].schema" |
| 86 | + then: |
| 87 | + field: "$ref" |
| 88 | + function: truthy |
| 89 | + |
| 90 | + # Response bodies must use $ref, not inline schemas |
| 91 | + no-inline-response-schema: |
| 92 | + description: Response body schemas must use $ref, not inline definitions |
| 93 | + message: "Use $ref for response schema instead of inline definition. See openapi/README.md#avoid-inline-schemas-in-request-and-response-definitions" |
| 94 | + severity: error |
| 95 | + given: "$.paths[*][get,post,put,patch,delete].responses[*].content[application/json].schema" |
| 96 | + then: |
| 97 | + field: "$ref" |
| 98 | + function: truthy |
| 99 | + |
| 100 | + # ============================================================ |
| 101 | + # Pagination (README: Pagination) |
| 102 | + # ============================================================ |
| 103 | + |
| 104 | + # GET list endpoints returning arrays should use pagination envelope |
| 105 | + pagination-envelope-has-data: |
| 106 | + description: Paginated responses must include a 'data' array field |
| 107 | + message: "List response missing 'data' field. See openapi/README.md#pagination" |
| 108 | + severity: warn |
| 109 | + given: "$.paths.*.get.responses.200.content.application/json.schema.properties" |
| 110 | + then: |
| 111 | + field: data |
| 112 | + function: truthy |
| 113 | + |
| 114 | + pagination-envelope-has-hasMore: |
| 115 | + description: Paginated responses must include a 'hasMore' boolean field |
| 116 | + message: "List response missing 'hasMore' field. See openapi/README.md#pagination" |
| 117 | + severity: warn |
| 118 | + given: "$.paths.*.get.responses.200.content.application/json.schema.properties[?(@.data)]" |
| 119 | + then: |
| 120 | + field: hasMore |
| 121 | + function: truthy |
| 122 | + |
| 123 | + # ============================================================ |
| 124 | + # HTTP Methods and Status Codes (README: HTTP Methods) |
| 125 | + # ============================================================ |
| 126 | + |
| 127 | + # DELETE operations should return 204 |
| 128 | + delete-returns-204: |
| 129 | + description: DELETE operations should return 204 No Content |
| 130 | + message: "DELETE should return 204. See openapi/README.md#http-methods" |
| 131 | + severity: warn |
| 132 | + given: "$.paths.*.delete.responses" |
| 133 | + then: |
| 134 | + field: "204" |
| 135 | + function: truthy |
| 136 | + |
| 137 | + # ============================================================ |
| 138 | + # Documentation (README: Documentation in OpenAPI) |
| 139 | + # ============================================================ |
| 140 | + |
| 141 | + # Schema properties should have descriptions |
| 142 | + schema-properties-have-descriptions: |
| 143 | + description: Schema properties should have descriptions |
| 144 | + message: "Property '{{property}}' is missing a description. See openapi/README.md#documentation-in-openapi" |
| 145 | + severity: warn |
| 146 | + given: "$.components.schemas.*.properties.*" |
| 147 | + then: |
| 148 | + field: description |
| 149 | + function: truthy |
| 150 | + |
| 151 | + # Schemas should have examples where appropriate |
| 152 | + schema-properties-have-examples: |
| 153 | + description: String and number schema properties should have examples |
| 154 | + message: "Property is missing an example. See openapi/README.md#documentation-in-openapi" |
| 155 | + severity: info |
| 156 | + given: "$.components.schemas.*.properties[?(@.type=='string' || @.type=='integer' || @.type=='number')]" |
| 157 | + then: |
| 158 | + field: example |
| 159 | + function: truthy |
| 160 | + |
| 161 | + # ============================================================ |
| 162 | + # Paths (README: Resources) |
| 163 | + # ============================================================ |
| 164 | + |
| 165 | + # Paths should use kebab-case (path params in {camelCase} are allowed) |
| 166 | + paths-kebab-case: |
| 167 | + description: Path segments should use kebab-case |
| 168 | + message: "Path should use kebab-case (e.g., /external-accounts not /externalAccounts). See openapi/README.md#resources" |
| 169 | + severity: error |
| 170 | + given: "$.paths" |
| 171 | + then: |
| 172 | + field: "@key" |
| 173 | + function: pattern |
| 174 | + functionOptions: |
| 175 | + match: "^(\\/([a-z0-9]+(-[a-z0-9]+)*|\\{[a-zA-Z0-9]+\\}))+$" |
0 commit comments