Created
January 17, 2026 13:41
-
-
Save kinlane/78976266f1720ed92a737507b16ae046 to your computer and use it in GitHub Desktop.
mininum-viable-consumer-rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extends: [[spectral:oas, off]] | |
| functions: | |
| - pattern | |
| functionsDir: ./functions | |
| rules: | |
| # ============================================================================ | |
| # INFO RULES | |
| # ============================================================================ | |
| info-object-must-exist: | |
| description: Info Object MUST exist | |
| message: "OpenAPI specification must have an info object" | |
| severity: error | |
| given: "$" | |
| then: | |
| field: info | |
| function: truthy | |
| info-must-have-title: | |
| description: Info MUST have title | |
| message: "Info object must have a title property" | |
| severity: error | |
| given: "$.info" | |
| then: | |
| field: title | |
| function: truthy | |
| info-must-have-description: | |
| description: Info MUST have description | |
| message: "Info object must have a description property" | |
| severity: error | |
| given: "$.info" | |
| then: | |
| field: description | |
| function: truthy | |
| # ============================================================================ | |
| # SERVERS RULES | |
| # ============================================================================ | |
| servers-object-must-exist: | |
| description: Servers Object MUST exist | |
| message: "OpenAPI specification must have a servers array" | |
| severity: error | |
| given: "$" | |
| then: | |
| field: servers | |
| function: truthy | |
| servers-must-have-url: | |
| description: Servers MUST have URL | |
| message: "Server object must have a url property" | |
| severity: error | |
| given: "$.servers[*]" | |
| then: | |
| field: url | |
| function: truthy | |
| servers-must-have-description: | |
| description: Servers MUST have description | |
| message: "Server object must have a description property" | |
| severity: error | |
| given: "$.servers[*]" | |
| then: | |
| field: description | |
| function: truthy | |
| # ============================================================================ | |
| # TAGS RULES | |
| # ============================================================================ | |
| tags-must-exist: | |
| description: Tags array MUST exist with at least one tag | |
| message: "OpenAPI specification must have a tags array with at least one tag" | |
| severity: error | |
| given: "$" | |
| then: | |
| field: tags | |
| function: schema | |
| functionOptions: | |
| schema: | |
| type: array | |
| minItems: 1 | |
| tags-must-be-object: | |
| description: Tags MUST be tag objects | |
| message: "Each tag must be a valid tag object" | |
| severity: error | |
| given: "$.tags[*]" | |
| then: | |
| function: schema | |
| functionOptions: | |
| schema: | |
| type: object | |
| tags-must-have-name: | |
| description: Tags MUST have a name | |
| message: "Tag object must have a name property" | |
| severity: error | |
| given: "$.tags[*]" | |
| then: | |
| field: name | |
| function: truthy | |
| tags-name-must-be-title-case: | |
| description: Tag names MUST have first letter in each word capitalized | |
| message: "Tag name '{{value}}' must have the first letter of each word capitalized (Title Case)" | |
| severity: error | |
| given: "$.tags[*].name" | |
| then: | |
| function: pattern | |
| functionOptions: | |
| match: "^([A-Z][a-z]*)(\\s[A-Z][a-z]*)*$" | |
| tags-must-have-description: | |
| description: Tags MUST have a description | |
| message: "Tag object must have a description property" | |
| severity: error | |
| given: "$.tags[*]" | |
| then: | |
| field: description | |
| function: truthy | |
| # ============================================================================ | |
| # OPERATIONS RULES | |
| # ============================================================================ | |
| operation-must-have-summary: | |
| description: Operation MUST have a summary | |
| message: "Operation must have a summary property" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace]" | |
| then: | |
| field: summary | |
| function: truthy | |
| operation-must-have-description: | |
| description: Operation MUST have description | |
| message: "Operation must have a description property" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace]" | |
| then: | |
| field: description | |
| function: truthy | |
| operation-must-have-operationid: | |
| description: Operation MUST have identifier (operationId) | |
| message: "Operation must have an operationId property" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace]" | |
| then: | |
| field: operationId | |
| function: truthy | |
| operation-id-must-be-camel-case: | |
| description: Operation identifier MUST be camelCase | |
| message: "operationId '{{value}}' must be camelCase" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace].operationId" | |
| then: | |
| function: pattern | |
| functionOptions: | |
| match: "^[a-z][a-zA-Z0-9]*$" | |
| operation-must-have-tags: | |
| description: Operations MUST have tags with at least one tag | |
| message: "Operation must have a tags array with at least one tag" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace]" | |
| then: | |
| field: tags | |
| function: schema | |
| functionOptions: | |
| schema: | |
| type: array | |
| minItems: 1 | |
| operation-tags-must-be-title-case: | |
| description: Operation tag names MUST have first letter in each word capitalized | |
| message: "Operation tag '{{value}}' must have the first letter of each word capitalized (Title Case)" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace].tags[*]" | |
| then: | |
| function: pattern | |
| functionOptions: | |
| match: "^([A-Z][a-z]*)(\\s[A-Z][a-z]*)*$" | |
| operation-must-have-security: | |
| description: Operations MUST have a security definition | |
| message: "Operation must have a security property defined" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace]" | |
| then: | |
| field: security | |
| function: truthy | |
| # ============================================================================ | |
| # PARAMETERS RULES | |
| # ============================================================================ | |
| parameters-must-use-references: | |
| description: Parameters MUST use references | |
| message: "Parameters should use $ref references to components/parameters" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace].parameters[*]" | |
| then: | |
| field: "$ref" | |
| function: truthy | |
| parameters-must-have-description: | |
| description: Parameters MUST have descriptions | |
| message: "Parameter must have a description property" | |
| severity: error | |
| given: "$.components.parameters[*]" | |
| then: | |
| field: description | |
| function: truthy | |
| parameters-must-have-schema: | |
| description: Parameters MUST have schema | |
| message: "Parameter must have a schema property" | |
| severity: error | |
| given: "$.components.parameters[*]" | |
| then: | |
| field: schema | |
| function: truthy | |
| # ============================================================================ | |
| # REQUEST BODIES RULES | |
| # ============================================================================ | |
| request-body-must-have-schema: | |
| description: Request bodies MUST have schema | |
| message: "Request body content must have a schema" | |
| severity: error | |
| given: "$.paths[*][post,put,patch].requestBody.content[*]" | |
| then: | |
| field: schema | |
| function: truthy | |
| request-body-must-use-schema-reference: | |
| description: Request bodies MUST use schema references | |
| message: "Request body schema must use a $ref reference" | |
| severity: error | |
| given: "$.paths[*][post,put,patch].requestBody.content[*].schema" | |
| then: | |
| field: "$ref" | |
| function: truthy | |
| request-body-must-have-examples: | |
| description: Request bodies MUST have examples | |
| message: "Request body content must have examples" | |
| severity: error | |
| given: "$.paths[*][post,put,patch].requestBody.content[*]" | |
| then: | |
| field: examples | |
| function: truthy | |
| request-body-examples-must-use-reference: | |
| description: Request bodies MUST use examples references | |
| message: "Request body examples must use $ref references" | |
| severity: error | |
| given: "$.paths[*][post,put,patch].requestBody.content[*].examples[*]" | |
| then: | |
| field: "$ref" | |
| function: truthy | |
| # ============================================================================ | |
| # RESPONSES RULES | |
| # ============================================================================ | |
| responses-must-have-schema: | |
| description: Responses MUST have schema | |
| message: "Response content must have a schema" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace].responses[*].content[*]" | |
| then: | |
| field: schema | |
| function: truthy | |
| responses-must-use-schema-reference: | |
| description: Responses MUST use schema references | |
| message: "Response schema must use a $ref reference" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace].responses[*].content[*].schema" | |
| then: | |
| field: "$ref" | |
| function: truthy | |
| responses-must-have-examples: | |
| description: Responses MUST have examples | |
| message: "Response content must have examples" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace].responses[*].content[*]" | |
| then: | |
| field: examples | |
| function: truthy | |
| responses-examples-must-use-reference: | |
| description: Responses MUST use examples references | |
| message: "Response examples must use $ref references" | |
| severity: error | |
| given: "$.paths[*][get,post,put,patch,delete,options,head,trace].responses[*].content[*].examples[*]" | |
| then: | |
| field: "$ref" | |
| function: truthy | |
| # ============================================================================ | |
| # SCHEMA RULES | |
| # ============================================================================ | |
| schema-must-have-description: | |
| description: Schema MUST have description | |
| message: "Schema must have a description property" | |
| severity: error | |
| given: "$.components.schemas[*]" | |
| then: | |
| field: description | |
| function: truthy | |
| schema-must-have-type: | |
| description: Schema MUST have type | |
| message: "Schema must have a type property" | |
| severity: error | |
| given: "$.components.schemas[*]" | |
| then: | |
| field: type | |
| function: truthy | |
| schema-properties-must-have-description: | |
| description: Schema properties MUST have description | |
| message: "Schema property must have a description" | |
| severity: error | |
| given: "$.components.schemas[*].properties[*]" | |
| then: | |
| field: description | |
| function: truthy | |
| schema-properties-must-have-type: | |
| description: Schema properties MUST have type | |
| message: "Schema property must have a type" | |
| severity: error | |
| given: "$.components.schemas[*].properties[*]" | |
| then: | |
| field: type | |
| function: truthy | |
| # ============================================================================ | |
| # COMPONENTS RULES | |
| # ============================================================================ | |
| components-must-have-security-schemes: | |
| description: Components MUST have a securitySchemes property | |
| message: "Components must have a securitySchemes property defined" | |
| severity: error | |
| given: "$.components" | |
| then: | |
| field: securitySchemes | |
| function: truthy | |
| components-must-have-parameters: | |
| description: Components MUST have a parameters property | |
| message: "Components must have a parameters property defined" | |
| severity: error | |
| given: "$.components" | |
| then: | |
| field: parameters | |
| function: truthy | |
| components-must-have-examples: | |
| description: Components MUST have an examples property | |
| message: "Components must have an examples property defined" | |
| severity: error | |
| given: "$.components" | |
| then: | |
| field: examples | |
| function: truthy | |
| components-must-have-schemas: | |
| description: Components MUST have a schemas property | |
| message: "Components must have a schemas property defined" | |
| severity: error | |
| given: "$.components" | |
| then: | |
| field: schemas | |
| function: truthy | |
| components-must-have-headers: | |
| description: Components MUST have a headers property | |
| message: "Components must have a headers property defined" | |
| severity: error | |
| given: "$.components" | |
| then: | |
| field: headers | |
| function: truthy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment