ETH Zurich – Swiss Federal Institute of Technology API Rules

Spectral linting rules defining API design standards and conventions for ETH Zurich – Swiss Federal Institute of Technology.

5 Rules error 1 warn 3 info 1
View Rules File View on GitHub

Rule Categories

eth

Rules

error
eth-info-title-required
API must declare an info.title.
$.info
warn
eth-server-on-library-host
Production server URL should be on the api.library.ethz.ch host.
$.servers[*].url
warn
eth-apikey-query-security-scheme
The platform authenticates with an apiKey security scheme passed in the query string as "apikey". Specs should define this scheme.
$.components.securitySchemes[*]
warn
eth-operations-have-200-response
GET operations should document a 200 response.
$.paths[*].get.responses
info
eth-operation-has-summary-or-description
Each operation should have a summary or description.
$.paths[*][get,post,put,delete]

Spectral Ruleset

Raw ↑
---
# Spectral ruleset for the ETH Library API Platform.
# Encodes patterns observed across the six published OpenAPI 3.0 specs
# (discovery, ethorama, geo, persons, research-collection, vector).
formats:
  - oas3
rules:
  eth-info-title-required:
    description: API must declare an info.title.
    severity: error
    given: $.info
    then:
      field: title
      function: truthy

  eth-server-on-library-host:
    description: Production server URL should be on the api.library.ethz.ch host.
    severity: warn
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: "^https://api\\.library\\.ethz\\.ch/"

  eth-apikey-query-security-scheme:
    description: >-
      The platform authenticates with an apiKey security scheme passed in the
      query string as "apikey". Specs should define this scheme.
    severity: warn
    given: $.components.securitySchemes[*]
    then:
      - field: type
        function: pattern
        functionOptions:
          match: "^apiKey$"
      - field: in
        function: pattern
        functionOptions:
          match: "^query$"
      - field: name
        function: pattern
        functionOptions:
          match: "^apikey$"

  eth-operations-have-200-response:
    description: GET operations should document a 200 response.
    severity: warn
    given: $.paths[*].get.responses
    then:
      field: "200"
      function: truthy

  eth-operation-has-summary-or-description:
    description: Each operation should have a summary or description.
    severity: info
    given: $.paths[*][get,post,put,delete]
    then:
      function: schema
      functionOptions:
        schema:
          type: object
          anyOf:
            - required: [summary]
            - required: [description]