United States Census Bureau · API Governance Rules

United States Census Bureau API Rules

Spectral linting rules defining API design standards and conventions for United States Census Bureau.

8 Rules error 2 warn 4 info 2
View Rules File View on GitHub

Rule Categories

census

Rules

warn
census-year-parameter-documented
Year path parameters should document available year ranges
$.paths..parameters[?(@.name == "year")].description
error
census-get-parameter-required
The get query parameter is the primary Census API parameter and should be marked required
$.paths..parameters[?(@.name == "get")]
warn
census-for-geography-documented
The for geography parameter should document FIPS code syntax
$.paths..parameters[?(@.name == "for")].description
info
census-key-parameter-documented
API key parameters should explain usage limits
$.paths..parameters[?(@.name == "key")].description
error
census-operation-ids-present
All operations must have operationIds
$.paths[*][*]
warn
census-tags-present
All operations should have tags for dataset grouping
$.paths[*][*]
warn
census-response-schema-defined
All 200 responses should define response schema
$.paths..responses.200.content.application/json
info
census-2d-array-response-described
The 2D array response format should be documented
$.paths..[?(@.tags && @.tags.includes('American Community Survey'))].description

Spectral Ruleset

Raw ↑
extends:
  - spectral:oas

rules:
  census-year-parameter-documented:
    description: Year path parameters should document available year ranges
    message: "Year path parameters should document the range of available data years"
    severity: warn
    given: $.paths..parameters[?(@.name == "year")].description
    then:
      function: truthy

  census-get-parameter-required:
    description: The get query parameter is the primary Census API parameter and should be marked required
    message: "The 'get' query parameter should be required for Census Data API endpoints"
    severity: error
    given: $.paths..parameters[?(@.name == "get")]
    then:
      field: required
      function: truthy

  census-for-geography-documented:
    description: The for geography parameter should document FIPS code syntax
    message: "The 'for' parameter should document geography FIPS filter syntax"
    severity: warn
    given: $.paths..parameters[?(@.name == "for")].description
    then:
      function: truthy

  census-key-parameter-documented:
    description: API key parameters should explain usage limits
    message: "The 'key' parameter should describe the usage limits benefit (500+ requests/day)"
    severity: info
    given: $.paths..parameters[?(@.name == "key")].description
    then:
      function: pattern
      functionOptions:
        match: "(requests|limit|key)"

  census-operation-ids-present:
    description: All operations must have operationIds
    message: "Operation must have an operationId"
    severity: error
    given: $.paths[*][*]
    then:
      field: operationId
      function: truthy

  census-tags-present:
    description: All operations should have tags for dataset grouping
    message: "Operation should be tagged with its dataset category"
    severity: warn
    given: $.paths[*][*]
    then:
      field: tags
      function: truthy

  census-response-schema-defined:
    description: All 200 responses should define response schema
    message: "200 response should define the DataAPIResponse or GeocodeResponse schema"
    severity: warn
    given: $.paths..responses.200.content.application/json
    then:
      field: schema
      function: truthy

  census-2d-array-response-described:
    description: The 2D array response format should be documented
    message: "Census 2D array response format should be described in the operation description"
    severity: info
    given: $.paths..[?(@.tags && @.tags.includes('American Community Survey'))].description
    then:
      function: truthy