# Spectral ruleset for the Lunchbox 2.0 APIs (Core, Management, Loyalty, POS). # Enforces the conventions observed across the Lunchbox OpenAPI specifications: # Title Case "Lunchbox ..." summaries, camelCase operationIds with verb prefixes, # Title Case tags, snake_case parameters and schema properties, token/Api-Key auth. extends: [[spectral:oas, off]] rules: # --------------------------------------------------------------------------- # INFO / METADATA # --------------------------------------------------------------------------- info-title-lunchbox: description: API title should start with "Lunchbox". severity: warn given: $.info.title then: function: pattern functionOptions: match: '^Lunchbox' info-description-required: description: Info description is required and should be meaningful. severity: warn given: $.info then: field: description function: truthy info-version-required: description: Info version is required. severity: error given: $.info then: field: version function: truthy info-contact-required: description: Contact information should be provided. severity: info given: $.info then: field: contact function: truthy # --------------------------------------------------------------------------- # OPENAPI VERSION # --------------------------------------------------------------------------- openapi-version-3: description: Specs must use OpenAPI 3.0.x. severity: error given: $.openapi then: function: pattern functionOptions: match: '^3\.0\.\d+$' # --------------------------------------------------------------------------- # SERVERS # --------------------------------------------------------------------------- servers-defined: description: At least one server must be defined. severity: error given: $.servers then: function: truthy servers-https: description: Server URLs must use HTTPS. severity: warn given: $.servers[*].url then: function: pattern functionOptions: match: '^https://' servers-description: description: Each server should have a description. severity: info given: $.servers[*] then: field: description function: truthy # --------------------------------------------------------------------------- # PATHS — NAMING CONVENTIONS # --------------------------------------------------------------------------- paths-no-trailing-slash: description: Paths should not end with a trailing slash (except root collections). severity: warn given: $.paths[*]~ then: function: pattern functionOptions: notMatch: '.+/$' paths-no-query-string: description: Path keys must not contain query strings. severity: error given: $.paths[*]~ then: function: pattern functionOptions: notMatch: '\?' # --------------------------------------------------------------------------- # OPERATIONS # --------------------------------------------------------------------------- operation-summary-required: description: Every operation must have a summary. severity: warn given: $.paths[*][get,post,put,patch,delete] then: field: summary function: truthy operation-summary-lunchbox-prefix: description: Operation summaries should start with "Lunchbox". severity: warn given: $.paths[*][get,post,put,patch,delete].summary then: function: pattern functionOptions: match: '^Lunchbox ' operation-operationid-required: description: Every operation must have an operationId. severity: error given: $.paths[*][get,post,put,patch,delete] then: field: operationId function: truthy operation-operationid-camelcase: description: operationId should be camelCase. severity: warn given: $.paths[*][get,post,put,patch,delete].operationId then: function: pattern functionOptions: match: '^[a-z][a-zA-Z0-9]*$' operation-tags-required: description: Every operation must have at least one tag. severity: warn given: $.paths[*][get,post,put,patch,delete] then: field: tags function: truthy # --------------------------------------------------------------------------- # TAGS # --------------------------------------------------------------------------- tags-global-defined: description: A global tags array should be defined. severity: info given: $ then: field: tags function: truthy tag-description: description: Each global tag should have a description. severity: info given: $.tags[*] then: field: description function: truthy tag-title-case: description: Tag names should be Title Case (e.g., "User Wallet", "Service Types"). severity: warn given: $.tags[*].name then: function: pattern functionOptions: match: '^[A-Z][A-Za-z]*( [A-Z][A-Za-z]*)*$' # --------------------------------------------------------------------------- # PARAMETERS # --------------------------------------------------------------------------- parameter-snake-case: description: Parameter names should be snake_case (Lunchbox convention). severity: warn given: $.paths[*][*].parameters[*].name then: function: pattern functionOptions: match: '^[a-z][a-z0-9_]*$' parameter-schema-required: description: Each parameter must define a schema. severity: error given: $.paths[*][*].parameters[*] then: field: schema function: truthy # --------------------------------------------------------------------------- # REQUEST BODIES # --------------------------------------------------------------------------- request-body-json: description: Request bodies should offer application/json. severity: warn given: $.paths[*][post,put,patch].requestBody.content then: field: application/json function: truthy # --------------------------------------------------------------------------- # RESPONSES # --------------------------------------------------------------------------- response-success-defined: description: Each operation must define at least one 2xx response. severity: error given: $.paths[*][get,post,put,patch,delete].responses then: function: schema functionOptions: schema: type: object patternProperties: '^2\d\d$': {} minProperties: 1 response-description-required: description: Each response must have a description. severity: warn given: $.paths[*][*].responses[*] then: field: description function: truthy # --------------------------------------------------------------------------- # SCHEMAS — PROPERTY NAMING # --------------------------------------------------------------------------- schema-property-snake-case: description: Schema property names should be snake_case (Core/Management/POS convention). severity: info given: $.components.schemas[*].properties[*]~ then: function: pattern functionOptions: match: '^[a-zA-Z][a-zA-Z0-9_]*$' schema-property-typed: description: Schema properties should declare a type or a $ref. severity: info given: $.components.schemas[*].properties[*] then: function: schema functionOptions: schema: anyOf: - required: [type] - required: ['$ref'] - required: [allOf] - required: [oneOf] - required: [anyOf] # --------------------------------------------------------------------------- # SECURITY # --------------------------------------------------------------------------- security-global-defined: description: A global security requirement should be defined. severity: warn given: $ then: field: security function: truthy security-schemes-defined: description: Security schemes must be declared under components. severity: warn given: $.components then: field: securitySchemes function: truthy security-scheme-described: description: Each security scheme should have a description. severity: info given: $.components.securitySchemes[*] then: field: description function: truthy # --------------------------------------------------------------------------- # HTTP METHOD CONVENTIONS # --------------------------------------------------------------------------- get-no-request-body: description: GET operations must not declare a request body. severity: error given: $.paths[*].get then: field: requestBody function: falsy delete-no-request-body: description: DELETE operations should not declare a request body. severity: warn given: $.paths[*].delete then: field: requestBody function: falsy # --------------------------------------------------------------------------- # GENERAL QUALITY # --------------------------------------------------------------------------- operation-examples-encouraged: description: Operations are encouraged to provide response examples. severity: info given: $.paths[*][*].responses[*].content.application/json then: function: schema functionOptions: schema: anyOf: - required: [example] - required: [examples] - required: [schema]