Merge · API Governance Rules

Merge API Rules

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

37 Rules error 15 warn 15 info 7
View Rules File View on GitHub

Rule Categories

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

Rules

error
info-title-required
Info object must have a title.
$.info
warn
info-title-merge-prefix
Info title should start with "Merge".
$.info.title
error
info-description-required
Info object must have a description.
$.info
warn
info-description-min-length
Info description should be at least 50 characters.
$.info.description
error
info-version-required
Info object must have a version.
$.info
warn
info-contact-required
Info object should have contact information.
$.info
warn
openapi-version-3
OpenAPI version should be 3.x.
$
error
servers-defined
At least one server must be defined.
$
error
servers-https
Server URLs should use HTTPS.
$.servers[*].url
info
servers-merge-api-domain
Server URL should be on api.merge.dev.
$.servers[*].url
warn
paths-kebab-case
Path segments should use kebab-case.
$.paths
error
paths-no-trailing-slash
Paths must not have trailing slashes.
$.paths
info
paths-plural-resources
Resource paths should use plural nouns.
$.paths
error
operation-operationid-required
Every operation must have an operationId.
$.paths[*][get,post,put,patch,delete]
warn
operation-operationid-camel-case
operationId should use camelCase.
$.paths[*][get,post,put,patch,delete].operationId
error
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete]
warn
operation-summary-merge-prefix
Operation summaries should start with "Merge".
$.paths[*][get,post,put,patch,delete].summary
error
operation-description-required
Every operation must have a description.
$.paths[*][get,post,put,patch,delete]
error
operation-tags-required
Every operation must have at least one tag.
$.paths[*][get,post,put,patch,delete]
warn
parameter-description-required
Every parameter must have a description.
$.paths[*][*].parameters[*]
warn
parameter-snake-case
Parameter names should use snake_case.
$.paths[*][*].parameters[*].name
info
parameter-pagination-cursor
Merge APIs use cursor-based pagination with cursor parameter.
$.paths[*].get.parameters
warn
request-body-json
Request bodies should use application/json.
$.paths[*][post,put,patch].requestBody.content
error
response-success-required
Every operation must have a success response.
$.paths[*][get,post,put,patch,delete].responses
error
response-description-required
Every response must have a description.
$.paths[*][*].responses[*]
warn
schema-property-snake-case
Schema properties should use snake_case naming.
$.components.schemas[*].properties
warn
schema-type-defined
Schemas must define a type.
$.components.schemas[*]
info
schema-description
Top-level schemas should have descriptions.
$.components.schemas[*]
error
security-defined
Global security must be defined.
$
warn
security-bearer-auth
Merge APIs should use Bearer token authentication.
$.components.securitySchemes
warn
security-account-token-header
Merge APIs require X-Account-Token header.
$.components.securitySchemes
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
info
pagination-response-format
List endpoints should return paginated responses with next/previous/results.
$.paths[*].get.responses.200.content.application/json.schema
info
remote-was-deleted-field
Merge schemas should include remote_was_deleted field for soft delete tracking.
$.components.schemas[?(@.type=='object' && [email protected](/Paginated|Request|Error/))]
error
no-empty-descriptions
Descriptions must 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 object must have a title.
    given: $.info
    severity: error
    then:
      field: title
      function: truthy

  info-title-merge-prefix:
    description: Info title should start with "Merge".
    given: $.info.title
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^Merge"

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

  info-description-min-length:
    description: Info description should be at least 50 characters.
    given: $.info.description
    severity: warn
    then:
      function: length
      functionOptions:
        min: 50

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

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

  # ============================================================
  # OPENAPI VERSION
  # ============================================================
  openapi-version-3:
    description: OpenAPI version should be 3.x.
    given: $
    severity: warn
    then:
      field: openapi
      function: pattern
      functionOptions:
        match: "^3\\."

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

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

  servers-merge-api-domain:
    description: Server URL should be on api.merge.dev.
    given: $.servers[*].url
    severity: info
    then:
      function: pattern
      functionOptions:
        match: "api\\.merge\\.dev"

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

  paths-no-trailing-slash:
    description: Paths must not have trailing slashes.
    given: $.paths
    severity: error
    then:
      field: "@key"
      function: pattern
      functionOptions:
        notMatch: "\\/$"

  paths-plural-resources:
    description: Resource paths should use plural nouns.
    given: $.paths
    severity: info
    then:
      field: "@key"
      function: pattern
      functionOptions:
        notMatch: "\\/[a-z]+[^s{}]\\/\\{"

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

  operation-operationid-camel-case:
    description: operationId should use camelCase.
    given: $.paths[*][get,post,put,patch,delete].operationId
    severity: warn
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"

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

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

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

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

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

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

  parameter-pagination-cursor:
    description: Merge APIs use cursor-based pagination with cursor parameter.
    given: $.paths[*].get.parameters
    severity: info
    then:
      function: schema
      functionOptions:
        schema:
          type: array
          contains:
            type: object
            properties:
              name:
                const: cursor

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

  # ============================================================
  # RESPONSES
  # ============================================================
  response-success-required:
    description: Every operation must have a success response.
    given: $.paths[*][get,post,put,patch,delete].responses
    severity: error
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ["200"]
            - required: ["201"]
            - required: ["204"]

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

  # ============================================================
  # SCHEMAS - PROPERTY NAMING
  # ============================================================
  schema-property-snake-case:
    description: Schema properties should use snake_case naming.
    given: $.components.schemas[*].properties
    severity: warn
    then:
      field: "@key"
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"

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

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

  # ============================================================
  # SECURITY
  # ============================================================
  security-defined:
    description: Global security must be defined.
    given: $
    severity: error
    then:
      field: security
      function: truthy

  security-bearer-auth:
    description: Merge APIs should use Bearer token authentication.
    given: $.components.securitySchemes
    severity: warn
    then:
      field: bearerAuth
      function: truthy

  security-account-token-header:
    description: Merge APIs require X-Account-Token header.
    given: $.components.securitySchemes
    severity: warn
    then:
      field: accountToken
      function: truthy

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

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

  # ============================================================
  # MERGE-SPECIFIC PATTERNS
  # ============================================================
  pagination-response-format:
    description: List endpoints should return paginated responses with next/previous/results.
    given: $.paths[*].get.responses.200.content.application/json.schema
    severity: info
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          properties:
            "$ref":
              type: string
              pattern: "Paginated"

  remote-was-deleted-field:
    description: Merge schemas should include remote_was_deleted field for soft delete tracking.
    given: $.components.schemas[?(@.type=='object' && [email protected](/Paginated|Request|Error/))]
    severity: info
    then:
      field: properties.remote_was_deleted
      function: truthy

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

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