1Factory · API Governance Rules

1Factory API Rules

Spectral linting rules defining API design standards and conventions for 1Factory.

32 Rules error 13 warn 15 info 4
View Rules File View on GitHub

Rule Categories

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

Rules

error
info-title-required
Info title must be present and follow "1Factory ..." pattern.
$.info
warn
info-description-required
Info description must be present and at least 50 characters.
$.info
error
info-version-required
API version must be defined.
$.info
warn
info-contact-required
Contact information must be provided.
$.info
info
info-terms-of-service
Terms of service URL should be provided.
$.info
error
openapi-version-3
Must use OpenAPI 3.0.x.
$
error
servers-must-be-defined
Servers array must be defined and non-empty.
$
error
servers-https-required
Production server URLs must use HTTPS.
$.servers[*]
warn
servers-description-required
Each server must have a description.
$.servers[*]
warn
paths-no-trailing-slash
Paths must not end with a trailing slash.
$.paths
error
paths-no-query-string
Paths must not contain query strings.
$.paths
error
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete,options,head]
warn
operation-description-required
Every operation should have a description.
$.paths[*][get,post,put,patch,delete,options,head]
warn
operation-summary-prefix
Every operation summary should start with "1Factory".
$.paths[*][get,post,put,patch,delete,options,head].summary
error
operation-tags-required
Every operation must have at least one tag.
$.paths[*][get,post,put,patch,delete,options,head]
warn
tag-descriptions-required
Global tags must have descriptions.
$.tags[*]
warn
parameter-description-required
Every parameter must have a description.
$.paths[*][get,post,put,patch,delete,options,head].parameters[*]
error
parameter-schema-required
Every parameter must have a schema.
$.paths[*][get,post,put,patch,delete,options,head].parameters[*]
info
request-body-description
Request bodies should have a description.
$.paths[*][post,put,patch].requestBody
warn
request-body-json-content
Request bodies should use application/json content type.
$.paths[*][post,put,patch].requestBody.content
error
response-success-required
Every operation must define at least one 2xx response.
$.paths[*][get,post,put,patch,delete,options,head].responses
error
response-description-required
Every response must have a description.
$.paths[*][get,post,put,patch,delete,options,head].responses[*]
warn
response-401-required
APIs using API key auth should define a 401 response.
$.paths[*][get,post,put,patch,delete].responses
info
response-429-rate-limit
Rate-limited APIs should define a 429 response.
$.paths[*][get,post,put,patch,delete].responses
warn
schema-description-required
Top-level component schemas should have descriptions.
$.components.schemas[*]
warn
schema-type-required
Schemas should define a type.
$.components.schemas[*]
error
security-schemes-defined
Security schemes must be defined in components.
$.components
warn
security-api-key-in-header
API keys should be passed in headers, not query parameters.
$.components.securitySchemes[*][?(@.type == 'apiKey')]
error
get-no-request-body
GET operations must not have a request body.
$.paths[*].get
warn
delete-no-request-body
DELETE operations should not have a request body.
$.paths[*].delete
warn
no-empty-descriptions
Descriptions should not be empty strings.
$..description
info
examples-encouraged
Schema properties should include example values.
$.components.schemas[*].properties[*]

Spectral Ruleset

Raw ↑
rules:

  # INFO / METADATA
  info-title-required:
    description: Info title must be present and follow "1Factory ..." pattern.
    severity: error
    given: $.info
    then:
      field: title
      function: truthy

  info-description-required:
    description: Info description must be present and at least 50 characters.
    severity: warn
    given: $.info
    then:
      field: description
      function: minLength
      functionOptions:
        value: 50

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

  info-contact-required:
    description: Contact information must be provided.
    severity: warn
    given: $.info
    then:
      field: contact
      function: truthy

  info-terms-of-service:
    description: Terms of service URL should be provided.
    severity: info
    given: $.info
    then:
      field: termsOfService
      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 and non-empty.
    severity: error
    given: $
    then:
      field: servers
      function: truthy

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

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

  # PATHS — NAMING CONVENTIONS
  paths-no-trailing-slash:
    description: Paths must not end with a trailing slash.
    severity: warn
    given: $.paths
    then:
      function: pattern
      functionOptions:
        notMatch: "/$"

  paths-no-query-string:
    description: Paths must not contain query strings.
    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,options,head]
    then:
      field: summary
      function: truthy

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

  operation-summary-prefix:
    description: Every operation summary should start with "1Factory".
    severity: warn
    given: $.paths[*][get,post,put,patch,delete,options,head].summary
    then:
      function: pattern
      functionOptions:
        match: "^1Factory "

  operation-tags-required:
    description: Every operation must have at least one tag.
    severity: error
    given: $.paths[*][get,post,put,patch,delete,options,head]
    then:
      field: tags
      function: truthy

  # TAGS
  tag-descriptions-required:
    description: Global tags must have descriptions.
    severity: warn
    given: $.tags[*]
    then:
      field: description
      function: truthy

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

  parameter-schema-required:
    description: Every parameter must have a schema.
    severity: error
    given: $.paths[*][get,post,put,patch,delete,options,head].parameters[*]
    then:
      field: schema
      function: truthy

  # REQUEST BODIES
  request-body-description:
    description: Request bodies should have a description.
    severity: info
    given: $.paths[*][post,put,patch].requestBody
    then:
      field: description
      function: truthy

  request-body-json-content:
    description: Request bodies should use application/json content type.
    severity: warn
    given: $.paths[*][post,put,patch].requestBody.content
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          required:
            - application/json

  # RESPONSES
  response-success-required:
    description: Every operation must define at least one 2xx response.
    severity: error
    given: $.paths[*][get,post,put,patch,delete,options,head].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,options,head].responses[*]
    then:
      field: description
      function: truthy

  response-401-required:
    description: APIs using API key auth should define a 401 response.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            '401':
              type: object

  response-429-rate-limit:
    description: Rate-limited APIs should define a 429 response.
    severity: info
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            '429':
              type: object

  # SCHEMAS — PROPERTY NAMING
  schema-description-required:
    description: Top-level 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

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

  security-api-key-in-header:
    description: API keys should be passed in headers, not query parameters.
    severity: warn
    given: $.components.securitySchemes[*][?(@.type == 'apiKey')]
    then:
      field: in
      function: enumeration
      functionOptions:
        values:
          - header

  # 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

  delete-no-request-body:
    description: DELETE operations should not have a request body.
    severity: warn
    given: $.paths[*].delete
    then:
      field: requestBody
      function: falsy

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

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