APIs.io · API Governance Rules

APIs.io API Rules

Spectral linting rules defining API design standards and conventions for APIs.io.

37 Rules error 13 warn 18 info 6
View Rules File View on GitHub

Rule Categories

apis components examples get info no openapi operation parameter paths post request response schema servers tag tags

Rules

warn
info-title-format
Info title should start with "APIs.io"
$.info.title
error
info-description-required
Info must have a description
$.info
error
info-version-required
Info must have a version
$.info
warn
info-contact-required
Info should include contact information
$.info
warn
openapi-version-31
Specs should use OpenAPI 3.1.x as established by the APIs.io API
$.openapi
error
servers-defined
Servers array must be defined
$
error
servers-https-only
Server URLs must use HTTPS
$.servers[*].url
warn
paths-kebab-case
Path segments should use kebab-case
$.paths[*]~
warn
paths-no-trailing-slash
Paths must not have trailing slashes
$.paths[*]~
error
operation-summary-required
All operations must have a summary
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-summary-prefix
Operation summaries should start with "APIs.io"
$.paths[*][get,post,put,patch,delete].summary
info
operation-summary-title-case
Operation summaries should use Title Case
$.paths[*][get,post,put,patch,delete].summary
warn
operation-description-required
All operations should have a description
$.paths[*][get,post,put,patch,delete,head,options]
error
operation-id-required
All operations must have an operationId
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-id-camel-case
OperationId should use camelCase
$.paths[*][get,post,put,patch,delete].operationId
error
operation-tags-required
All operations must have at least one tag
$.paths[*][get,post,put,patch,delete,head,options]
warn
tags-defined
Global tags array should be defined
$
warn
tag-description-required
All global tags should have descriptions
$.tags[*]
error
parameter-description-required
All parameters must have descriptions
$.paths[*][*].parameters[*]
error
parameter-schema-required
All parameters must have a schema
$.paths[*][*].parameters[*]
warn
parameter-names-snake-case
Parameter names should use snake_case
$.paths[*][*].parameters[*].name
warn
request-body-description-required
Request bodies should have descriptions
$.paths[*][*].requestBody
warn
request-body-json-content
Request bodies should support application/json content type
$.paths[*][post,put,patch].requestBody.content
error
response-200-required
GET and POST operations must have a 2xx response
$.paths[*][get,post]
error
response-description-required
All responses must have descriptions
$.paths[*][*].responses[*]
warn
response-400-recommended
Operations should include a 400 Bad Request response
$.paths[*][get,post,put,patch,delete].responses
warn
response-401-recommended
Operations should include a 401 Unauthorized response
$.paths[*][get,post,put,patch,delete].responses
warn
response-500-recommended
Operations should include a 500 Internal Server Error response
$.paths[*][get,post,put,patch,delete].responses
info
schema-properties-snake-case
Schema property names should use snake_case
$.components.schemas[*].properties[*]~
info
schema-description-recommended
Component schemas should have descriptions
$.components.schemas[*]
warn
schema-type-defined
Schema objects should have a type defined
$.components.schemas[*]
info
components-security-schemes-defined
Security schemes should be defined in components
$.components
error
get-no-request-body
GET operations must not have a request body
$.paths[*].get
warn
post-has-request-body
POST operations should have a request body
$.paths[*].post
error
no-empty-descriptions
Descriptions must not be empty strings
$..description
info
examples-on-schemas
Schema properties should include examples
$.components.schemas[*].properties[*]
info
apis-json-format-validation
APIs submitted to APIs.io should follow APIs.json format
$.paths[*][post].requestBody.content.application/json.schema

Spectral Ruleset

Raw ↑
rules:
  # INFO / METADATA
  info-title-format:
    description: Info title should start with "APIs.io"
    severity: warn
    given: "$.info.title"
    then:
      function: pattern
      functionOptions:
        match: "^APIs\\.io"

  info-description-required:
    description: Info must have a description
    severity: error
    given: "$.info"
    then:
      field: description
      function: truthy

  info-version-required:
    description: Info must have a version
    severity: error
    given: "$.info"
    then:
      field: version
      function: truthy

  info-contact-required:
    description: Info should include contact information
    severity: warn
    given: "$.info"
    then:
      field: contact
      function: truthy

  # OPENAPI VERSION
  openapi-version-31:
    description: Specs should use OpenAPI 3.1.x as established by the APIs.io API
    severity: warn
    given: "$.openapi"
    then:
      function: pattern
      functionOptions:
        match: "^3\\.1\\."

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

  servers-https-only:
    description: Server URLs must use HTTPS
    severity: error
    given: "$.servers[*].url"
    then:
      function: pattern
      functionOptions:
        match: "^https://"

  # PATHS — NAMING CONVENTIONS
  paths-kebab-case:
    description: Path segments should use kebab-case
    severity: warn
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^(\\/([a-z0-9-{}._]+))*$"

  paths-no-trailing-slash:
    description: Paths must not have trailing slashes
    severity: warn
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        notMatch: "\\/$"

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

  operation-summary-prefix:
    description: Operation summaries should start with "APIs.io"
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^APIs\\.io"

  operation-summary-title-case:
    description: Operation summaries should use Title Case
    severity: info
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

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

  operation-id-required:
    description: All operations must have an operationId
    severity: error
    given: "$.paths[*][get,post,put,patch,delete,head,options]"
    then:
      field: operationId
      function: truthy

  operation-id-camel-case:
    description: OperationId should use 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: All operations must have at least one tag
    severity: error
    given: "$.paths[*][get,post,put,patch,delete,head,options]"
    then:
      field: tags
      function: truthy

  # TAGS
  tags-defined:
    description: Global tags array should be defined
    severity: warn
    given: "$"
    then:
      field: tags
      function: truthy

  tag-description-required:
    description: All global tags should have descriptions
    severity: warn
    given: "$.tags[*]"
    then:
      field: description
      function: truthy

  # PARAMETERS
  parameter-description-required:
    description: All parameters must have descriptions
    severity: error
    given: "$.paths[*][*].parameters[*]"
    then:
      field: description
      function: truthy

  parameter-schema-required:
    description: All parameters must have a schema
    severity: error
    given: "$.paths[*][*].parameters[*]"
    then:
      field: schema
      function: truthy

  parameter-names-snake-case:
    description: Parameter names should use snake_case
    severity: warn
    given: "$.paths[*][*].parameters[*].name"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"

  # REQUEST BODIES
  request-body-description-required:
    description: Request bodies should have descriptions
    severity: warn
    given: "$.paths[*][*].requestBody"
    then:
      field: description
      function: truthy

  request-body-json-content:
    description: Request bodies should support application/json content type
    severity: warn
    given: "$.paths[*][post,put,patch].requestBody.content"
    then:
      field: application/json
      function: truthy

  # RESPONSES
  response-200-required:
    description: GET and POST operations must have a 2xx response
    severity: error
    given: "$.paths[*][get,post]"
    then:
      field: responses
      function: truthy

  response-description-required:
    description: All responses must have descriptions
    severity: error
    given: "$.paths[*][*].responses[*]"
    then:
      field: description
      function: truthy

  response-400-recommended:
    description: Operations should include a 400 Bad Request response
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: "400"
      function: truthy

  response-401-recommended:
    description: Operations should include a 401 Unauthorized response
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: "401"
      function: truthy

  response-500-recommended:
    description: Operations should include a 500 Internal Server Error response
    severity: warn
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: "500"
      function: truthy

  # SCHEMAS — PROPERTY NAMING
  schema-properties-snake-case:
    description: Schema property names should use snake_case
    severity: info
    given: "$.components.schemas[*].properties[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"

  schema-description-recommended:
    description: Component schemas should have descriptions
    severity: info
    given: "$.components.schemas[*]"
    then:
      field: description
      function: truthy

  schema-type-defined:
    description: Schema objects should have a type defined
    severity: warn
    given: "$.components.schemas[*]"
    then:
      field: type
      function: truthy

  # SECURITY
  components-security-schemes-defined:
    description: Security schemes should be defined in components
    severity: info
    given: "$.components"
    then:
      field: securitySchemes
      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

  post-has-request-body:
    description: POST operations should have a request body
    severity: warn
    given: "$.paths[*].post"
    then:
      field: requestBody
      function: truthy

  # GENERAL QUALITY
  no-empty-descriptions:
    description: Descriptions must not be empty strings
    severity: error
    given: "$..description"
    then:
      function: pattern
      functionOptions:
        match: ".+"

  examples-on-schemas:
    description: Schema properties should include examples
    severity: info
    given: "$.components.schemas[*].properties[*]"
    then:
      field: example
      function: truthy

  apis-json-format-validation:
    description: APIs submitted to APIs.io should follow APIs.json format
    severity: info
    given: "$.paths[*][post].requestBody.content.application/json.schema"
    then:
      field: $ref
      function: truthy