chucknorris.io · API Governance Rules

chucknorris.io API Rules

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

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

Rule Categories

chucknorris

Rules

warn
chucknorris-info-contact
Spec must include the chucknorris.io maintainer contact.
$.info.contact
warn
chucknorris-info-license-gpl
Top-level spec license must be GPL-3.0 (matches chuck-api).
$.info.license
error
chucknorris-server-base-url
The only documented production server is https://api.chucknorris.io.
$.servers[*].url
error
chucknorris-paths-under-jokes
All operation paths must live under /jokes.
$.paths
warn
chucknorris-operation-summary-title-case
Operation summaries should be in Title Case.
$.paths[*][get,post,put,patch,delete,options,head].summary
error
chucknorris-operation-id-required
Every operation must declare an operationId.
$.paths[*][get,post,put,patch,delete,options,head]
warn
chucknorris-operation-id-camelcase
operationId should be camelCase (e.g. getRandomJoke).
$.paths[*][get,post,put,patch,delete,options,head].operationId
warn
chucknorris-success-must-have-json
2xx responses must include an application/json content type.
$.paths[*][get,post,put,patch,delete,options,head].responses[?(@property.match(/2\d\d/))].content
error
chucknorris-joke-schema-required-fields
The Joke schema must require the canonical chucknorris.io fields.
$.components.schemas.Joke
warn
chucknorris-search-query-min-length
The /jokes/search `query` parameter should declare a minLength.
$.paths['/jokes/search'].get.parameters[?(@.name=='query')].schema

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas
formats:
  - oas3
rules:
  # Provider conventions enforced from the chucknorris.io OpenAPI spec.
  chucknorris-info-contact:
    description: Spec must include the chucknorris.io maintainer contact.
    severity: warn
    given: $.info.contact
    then:
      - field: name
        function: truthy
      - field: email
        function: truthy

  chucknorris-info-license-gpl:
    description: Top-level spec license must be GPL-3.0 (matches chuck-api).
    severity: warn
    given: $.info.license
    then:
      - field: name
        function: pattern
        functionOptions:
          match: "^GPL-3\\.0$"

  chucknorris-server-base-url:
    description: The only documented production server is https://api.chucknorris.io.
    severity: error
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: "^https://api\\.chucknorris\\.io$"

  chucknorris-paths-under-jokes:
    description: All operation paths must live under /jokes.
    severity: error
    given: $.paths
    then:
      function: pattern
      functionOptions:
        match: "^/jokes(/.*)?$"
      field: "@key"

  chucknorris-operation-summary-title-case:
    description: Operation summaries should be in Title Case.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,options,head].summary
    then:
      function: pattern
      functionOptions:
        match: "^([A-Z][A-Za-z0-9]*)(\\s[A-Z][A-Za-z0-9]*)*$"

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

  chucknorris-operation-id-camelcase:
    description: operationId should be camelCase (e.g. getRandomJoke).
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,options,head].operationId
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]+$"

  chucknorris-success-must-have-json:
    description: 2xx responses must include an application/json content type.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,options,head].responses[?(@property.match(/2\d\d/))].content
    then:
      field: application/json
      function: truthy

  chucknorris-joke-schema-required-fields:
    description: The Joke schema must require the canonical chucknorris.io fields.
    severity: error
    given: $.components.schemas.Joke
    then:
      field: required
      function: schema
      functionOptions:
        schema:
          type: array
          contains:
            enum:
              - id
              - value
              - categories
              - icon_url
              - url
              - created_at
              - updated_at

  chucknorris-search-query-min-length:
    description: The /jokes/search `query` parameter should declare a minLength.
    severity: warn
    given: $.paths['/jokes/search'].get.parameters[?(@.name=='query')].schema
    then:
      field: minLength
      function: truthy