tRPC · API Governance Rules

tRPC API Rules

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

8 Rules error 3 warn 2
View Rules File View on GitHub

Rule Categories

trpc

Rules

warn
trpc-operation-summary-title-case
Operation summaries must use Title Case
$.paths[*][*].summary
error
trpc-operation-tags-required
All operations must have at least one tag
$.paths[*][*]
warn
trpc-trpc-error-schema
Error responses must use the TRPCErrorResult schema
$.paths[*][*].responses[4*,5*].content.application/json.schema
error
trpc-success-response-defined
All operations should define a 200 success response
$.paths[*][get,post]
hint
trpc-procedure-path-format
tRPC procedure paths should use dot notation for nested routers (e.g., router.procedure) or flat names for root procedures
$.paths[*]~
error
trpc-batch-endpoint-post
Batch endpoints must use POST method
$.paths[/batch]
hint
trpc-query-uses-get
Query procedures should use GET method
$.paths[*]~
hint
trpc-input-query-param
GET operations should define an input query parameter
$.paths[*][get]

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  trpc-operation-summary-title-case:
    description: Operation summaries must use Title Case
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: "^([A-Z][a-z]* ?)+$"

  trpc-operation-tags-required:
    description: All operations must have at least one tag
    severity: error
    given: "$.paths[*][*]"
    then:
      field: tags
      function: truthy

  trpc-trpc-error-schema:
    description: Error responses must use the TRPCErrorResult schema
    severity: warn
    given: "$.paths[*][*].responses[4*,5*].content.application/json.schema"
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          minProperties: 1

  trpc-success-response-defined:
    description: All operations should define a 200 success response
    severity: error
    given: "$.paths[*][get,post]"
    then:
      field: responses
      function: schema
      functionOptions:
        schema:
          type: object
          minProperties: 1

  trpc-procedure-path-format:
    description: >-
      tRPC procedure paths should use dot notation for nested routers
      (e.g., router.procedure) or flat names for root procedures
    severity: hint
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^(/[a-zA-Z0-9._-]+|/\\{procedure\\})$"

  trpc-batch-endpoint-post:
    description: Batch endpoints must use POST method
    severity: error
    given: "$.paths[/batch]"
    then:
      field: post
      function: truthy

  trpc-query-uses-get:
    description: Query procedures should use GET method
    severity: hint
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        notMatch: "^/batch$"

  trpc-input-query-param:
    description: GET operations should define an input query parameter
    severity: hint
    given: "$.paths[*][get]"
    then:
      field: parameters
      function: truthy