Amnic · API Governance Rules

Amnic API Rules

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

31 Rules error 15 warn 15 info 1
View Rules File View on GitHub

Rule Categories

examples get info no openapi operation parameter paths request response schema security servers tags

Rules

warn
info-title-prefix
API title should start with "Amnic".
$.info.title
error
info-description-required
API info must have a description of at least 20 characters.
$.info
error
info-version-required
API info must define a version.
$.info
warn
info-contact-required
API info should include contact information.
$.info
error
openapi-version-3
OpenAPI version must be 3.0.x.
$.openapi
error
servers-defined
At least one server must be defined.
$
error
servers-https
Server URLs must use HTTPS.
$.servers[*].url
warn
servers-description
Each server should have a description.
$.servers[*]
warn
paths-kebab-case
Path segments should use kebab-case (lowercase with hyphens).
$.paths[*]~
error
paths-no-trailing-slash
Paths must not have trailing slashes.
$.paths[*]~
error
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete,head,options]
warn
operation-summary-prefix
Operation summaries should start with "Amnic".
$.paths[*][get,post,put,patch,delete,head,options].summary
warn
operation-description-required
Every operation should have a description.
$.paths[*][get,post,put,patch,delete,head,options]
error
operation-id-required
Every operation 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,head,options].operationId
error
operation-tags-required
Every operation must have at least one tag.
$.paths[*][get,post,put,patch,delete,head,options]
warn
tags-global-defined
Global tags array should be defined.
$
warn
tags-description
Global tags should have descriptions.
$.tags[*]
error
parameter-description-required
Every parameter must have a description.
$.paths[*][*].parameters[*]
warn
parameter-snake-case
Query and path parameter names should use snake_case or kebab-case.
$.paths[*][*].parameters[?(@.in == 'query')].name
warn
request-body-content-type
Request bodies should use application/json content type.
$.paths[*][post,put,patch].requestBody.content
error
response-success-required
Every operation must have at least one 2xx response.
$.paths[*][get,post,put,patch,delete]
warn
response-401-required
Operations with security should document a 401 response.
$.paths[*][get,post,put,patch,delete].responses
error
response-description-required
Every response must have a description.
$.paths[*][*].responses[*]
warn
schema-description-required
Top-level schemas should have a description.
$.components.schemas[*]
warn
schema-property-snake-case
Schema property names should use snake_case.
$.components.schemas[*].properties[*]~
error
security-scheme-defined
Security schemes must be defined in components.
$.components
warn
security-global-defined
Global security should be defined.
$
error
get-no-request-body
GET operations must not have a request body.
$.paths[*].get
error
no-empty-descriptions
Descriptions must not be empty strings.
$..description
info
examples-encouraged
Operations should include examples for better documentation.
$.paths[*][*].responses[*].content[*]

Spectral Ruleset

Raw ↑
rules:
  # INFO / METADATA
  info-title-prefix:
    description: API title should start with "Amnic".
    severity: warn
    given: $.info.title
    then:
      function: pattern
      functionOptions:
        match: '^Amnic'

  info-description-required:
    description: API info must have a description of at least 20 characters.
    severity: error
    given: $.info
    then:
      field: description
      function: truthy

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

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

  # OPENAPI VERSION
  openapi-version-3:
    description: OpenAPI version must be 3.0.x.
    severity: error
    given: $.openapi
    then:
      function: pattern
      functionOptions:
        match: '^3\.0\.'

  # SERVERS
  servers-defined:
    description: At least one server must be defined.
    severity: error
    given: $
    then:
      field: servers
      function: truthy

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

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

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

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

  # OPERATIONS
  operation-summary-required:
    description: Every operation 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 "Amnic".
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,head,options].summary
    then:
      function: pattern
      functionOptions:
        match: '^Amnic'

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

  operation-id-required:
    description: Every operation 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,head,options].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: error
    given: $.paths[*][get,post,put,patch,delete,head,options]
    then:
      field: tags
      function: truthy

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

  tags-description:
    description: Global tags should have descriptions.
    severity: warn
    given: $.tags[*]
    then:
      field: description
      function: truthy

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

  parameter-snake-case:
    description: Query and path parameter names should use snake_case or kebab-case.
    severity: warn
    given: $.paths[*][*].parameters[?(@.in == 'query')].name
    then:
      function: pattern
      functionOptions:
        match: '^[a-z][a-z0-9_]*$'

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

  # RESPONSES
  response-success-required:
    description: Every operation must have at least one 2xx response.
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: responses
      function: truthy

  response-401-required:
    description: Operations with security should document a 401 response.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      field: '401'
      function: truthy

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

  # SCHEMAS - PROPERTY NAMING
  schema-description-required:
    description: Top-level schemas should have a description.
    severity: warn
    given: $.components.schemas[*]
    then:
      field: description
      function: truthy

  schema-property-snake-case:
    description: Schema property names should use snake_case.
    severity: warn
    given: $.components.schemas[*].properties[*]~
    then:
      function: pattern
      functionOptions:
        match: '^[a-z][a-z0-9_]*$'

  # SECURITY
  security-scheme-defined:
    description: Security schemes must be defined in components.
    severity: error
    given: $.components
    then:
      field: securitySchemes
      function: truthy

  security-global-defined:
    description: Global security should be defined.
    severity: warn
    given: $
    then:
      field: security
      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: error
    given: $..description
    then:
      function: pattern
      functionOptions:
        match: '.+'

  examples-encouraged:
    description: Operations should include examples for better documentation.
    severity: info
    given: $.paths[*][*].responses[*].content[*]
    then:
      field: examples
      function: truthy