Swagger · API Governance Rules

Swagger API Rules

Spectral linting rules defining API design standards and conventions for Swagger.

10 Rules error 4 warn 6
View Rules File View on GitHub

Rule Categories

swagger

Rules

warn
swagger-oas-operations-have-tags
All OpenAPI operations must have at least one tag for organization
$.paths[*][get,put,post,delete,patch,options,head,trace]
error
swagger-oas-operations-have-summaries
All OpenAPI operations must have a summary in Title Case
$.paths[*][get,put,post,delete,patch,options,head,trace]
warn
swagger-oas-summaries-title-case
OpenAPI operation summaries should use Title Case
$.paths[*][get,put,post,delete,patch,options,head,trace].summary
error
swagger-oas-operations-have-operation-ids
All OpenAPI operations must have an operationId for code generation
$.paths[*][get,put,post,delete,patch,options,head,trace]
warn
swagger-oas-operations-have-descriptions
All OpenAPI operations should have a description
$.paths[*][get,put,post,delete,patch,options,head,trace]
error
swagger-oas-path-params-required
All path parameters must be marked as required
$.paths[*][*].parameters[?(@.in == 'path')]
warn
swagger-oas-schemas-have-descriptions
All component schemas must have a description
$.components.schemas[*]
error
swagger-oas-info-required-fields
API info object must have title, description, and version
$.info
warn
swagger-oas-responses-have-descriptions
All response objects must have a description
$.paths[*][*].responses[*]
warn
swagger-oas-paths-kebab-case
API paths should use kebab-case (lowercase with hyphens, no underscores)
$.paths[*]~

Spectral Ruleset

swagger-rules.yml Raw ↑
extends: spectral:oas
rules:

  swagger-oas-operations-have-tags:
    description: All OpenAPI operations must have at least one tag for organization
    severity: warn
    given: "$.paths[*][get,put,post,delete,patch,options,head,trace]"
    then:
      field: tags
      function: truthy

  swagger-oas-operations-have-summaries:
    description: All OpenAPI operations must have a summary in Title Case
    severity: error
    given: "$.paths[*][get,put,post,delete,patch,options,head,trace]"
    then:
      field: summary
      function: truthy

  swagger-oas-summaries-title-case:
    description: OpenAPI operation summaries should use Title Case
    severity: warn
    given: "$.paths[*][get,put,post,delete,patch,options,head,trace].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][a-zA-Z0-9]*([ ][A-Z][a-zA-Z0-9]*)*$"

  swagger-oas-operations-have-operation-ids:
    description: All OpenAPI operations must have an operationId for code generation
    severity: error
    given: "$.paths[*][get,put,post,delete,patch,options,head,trace]"
    then:
      field: operationId
      function: truthy

  swagger-oas-operations-have-descriptions:
    description: All OpenAPI operations should have a description
    severity: warn
    given: "$.paths[*][get,put,post,delete,patch,options,head,trace]"
    then:
      field: description
      function: truthy

  swagger-oas-path-params-required:
    description: All path parameters must be marked as required
    severity: error
    given: "$.paths[*][*].parameters[?(@.in == 'path')]"
    then:
      field: required
      function: truthy

  swagger-oas-schemas-have-descriptions:
    description: All component schemas must have a description
    severity: warn
    given: "$.components.schemas[*]"
    then:
      field: description
      function: truthy

  swagger-oas-info-required-fields:
    description: API info object must have title, description, and version
    severity: error
    given: "$.info"
    then:
      - field: title
        function: truthy
      - field: version
        function: truthy

  swagger-oas-responses-have-descriptions:
    description: All response objects must have a description
    severity: warn
    given: "$.paths[*][*].responses[*]"
    then:
      field: description
      function: truthy

  swagger-oas-paths-kebab-case:
    description: API paths should use kebab-case (lowercase with hyphens, no underscores)
    severity: warn
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^(/[a-z0-9-{}]*)*$"