2020 Police Brutality · API Governance Rules

2020 Police Brutality API Rules

Spectral linting rules defining API design standards and conventions for 2020 Police Brutality.

19 Rules error 10 warn 7 info 2
View Rules File View on GitHub

Rule Categories

get info no openapi operation response schema servers tags

Rules

error
info-title-required
API info title must be present.
$.info
warn
info-description-required
API info description must be present and meaningful.
$.info
error
info-version-required
API version must be defined.
$.info
warn
info-license-required
Open data APIs should include a license.
$.info
error
openapi-version-3
Must use OpenAPI 3.0.x.
$
error
servers-must-be-defined
Servers array must be defined.
$
warn
servers-description-required
Each server should have a description.
$.servers[*]
error
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete]
warn
operation-description-required
Every operation should have a description.
$.paths[*][get,post,put,patch,delete]
error
operation-operationid-required
Every operation must have an operationId.
$.paths[*][get,post,put,patch,delete]
error
operation-tags-required
Every operation must have at least one tag.
$.paths[*][get,post,put,patch,delete]
error
response-success-required
Every operation must define at least one 2xx response.
$.paths[*][get,post,put,patch,delete].responses
error
response-description-required
Every response must have a description.
$.paths[*][get,post,put,patch,delete].responses[*]
warn
schema-description-required
Component schemas should have descriptions.
$.components.schemas[*]
warn
schema-type-required
Schemas should define a type.
$.components.schemas[*]
info
schema-properties-described
Schema properties should have descriptions.
$.components.schemas[*].properties[*]
error
get-no-request-body
GET operations must not have a request body.
$.paths[*].get
warn
no-empty-descriptions
Descriptions must not be empty strings.
$..description
info
tags-defined
Global tags array should be defined for documentation.
$

Spectral Ruleset

Raw ↑
rules:

  # INFO / METADATA
  info-title-required:
    description: API info title must be present.
    severity: error
    given: $.info
    then:
      field: title
      function: truthy

  info-description-required:
    description: API info description must be present and meaningful.
    severity: warn
    given: $.info
    then:
      field: description
      function: truthy

  info-version-required:
    description: API version must be defined.
    severity: error
    given: $.info
    then:
      field: version
      function: truthy

  info-license-required:
    description: Open data APIs should include a license.
    severity: warn
    given: $.info
    then:
      field: license
      function: truthy

  # OPENAPI VERSION
  openapi-version-3:
    description: Must use OpenAPI 3.0.x.
    severity: error
    given: $
    then:
      field: openapi
      function: pattern
      functionOptions:
        match: "^3\\.0\\."

  # SERVERS
  servers-must-be-defined:
    description: Servers array must be defined.
    severity: error
    given: $
    then:
      field: servers
      function: truthy

  servers-description-required:
    description: Each server should have a description.
    severity: warn
    given: $.servers[*]
    then:
      field: description
      function: truthy

  # OPERATIONS
  operation-summary-required:
    description: Every operation must have a summary.
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: summary
      function: truthy

  operation-description-required:
    description: Every operation should have a description.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: description
      function: truthy

  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-tags-required:
    description: Every operation must have at least one tag.
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: tags
      function: truthy

  # RESPONSES
  response-success-required:
    description: Every 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
          minProperties: 1

  response-description-required:
    description: Every response must have a description.
    severity: error
    given: $.paths[*][get,post,put,patch,delete].responses[*]
    then:
      field: description
      function: truthy

  # SCHEMAS
  schema-description-required:
    description: Component schemas should have descriptions.
    severity: warn
    given: $.components.schemas[*]
    then:
      field: description
      function: truthy

  schema-type-required:
    description: Schemas should define a type.
    severity: warn
    given: $.components.schemas[*]
    then:
      field: type
      function: truthy

  schema-properties-described:
    description: Schema properties should have descriptions.
    severity: info
    given: $.components.schemas[*].properties[*]
    then:
      field: description
      function: truthy

  # HTTP METHOD CONVENTIONS
  get-no-request-body:
    description: GET operations must not have a request body.
    severity: error
    given: $.paths[*].get
    then:
      field: requestBody
      function: falsy

  # GENERAL QUALITY
  no-empty-descriptions:
    description: Descriptions must not be empty strings.
    severity: warn
    given: $..description
    then:
      function: truthy

  tags-defined:
    description: Global tags array should be defined for documentation.
    severity: info
    given: $
    then:
      field: tags
      function: truthy