Indian Institute of Technology Kanpur · API Governance Rules

Indian Institute of Technology Kanpur API Rules

Spectral linting rules defining API design standards and conventions for Indian Institute of Technology Kanpur.

6 Rules error 1 warn 3 info 2
View Rules File View on GitHub

Rule Categories

iitk

Rules

error
iitk-operation-operationId
Operations must define an operationId.
$.paths[*][get,post,put,delete,patch]
warn
iitk-operation-tags
Operations should be grouped under at least one tag.
$.paths[*][get,post,put,delete,patch]
warn
iitk-path-snake-case
Path segments should be lower snake_case (Koha convention).
$.paths[*]~
info
iitk-public-prefix-known
Document that user-facing discovery endpoints are namespaced under /public.
$.paths[*]~
info
iitk-pagination-params
List operations should expose _page / _per_page pagination parameters.
$.paths[*].get.parameters[?(@.in=='query')].name
warn
iitk-error-response-documented
Non-2xx responses should be documented with a description.
$.paths[*][*].responses[?(@property >= '400')]

Spectral Ruleset

Raw ↑
# Spectral ruleset for the PKK Library (IIT Kanpur) Koha REST API.
# Encodes patterns observed in the live OpenAPI description served at
# https://libserv.iitk.ac.in/api/v1/ (Koha 23.11 REST API).
formats:
  - oas3
extends:
  - spectral:oas
rules:
  # Every operation should declare an operationId (the Koha spec does).
  iitk-operation-operationId:
    description: Operations must define an operationId.
    severity: error
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: operationId
      function: truthy

  # Operations should be tagged by resource (acquisitions, biblios, items, libraries, patrons...).
  iitk-operation-tags:
    description: Operations should be grouped under at least one tag.
    severity: warn
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: tags
      function: truthy

  # Collection paths use lower_snake_case plural nouns (e.g. /biblios, /acquisitions/orders).
  iitk-path-snake-case:
    description: Path segments should be lower snake_case (Koha convention).
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        match: "^(/[a-z0-9_.-]+(\\{[a-zA-Z0-9_]+\\})?)+$|^/$"

  # Public discovery endpoints live under the /public path prefix.
  iitk-public-prefix-known:
    description: Document that user-facing discovery endpoints are namespaced under /public.
    severity: info
    given: $.paths[*]~
    then:
      function: defined

  # Pagination query params follow the underscore-prefixed Koha convention (_page, _per_page).
  iitk-pagination-params:
    description: List operations should expose _page / _per_page pagination parameters.
    severity: info
    given: $.paths[*].get.parameters[?(@.in=='query')].name
    then:
      function: defined

  # Errors should follow the documented { error, error_code } shape.
  iitk-error-response-documented:
    description: Non-2xx responses should be documented with a description.
    severity: warn
    given: $.paths[*][*].responses[?(@property >= '400')]
    then:
      field: description
      function: truthy