AgStack Foundation · API Governance Rules

AgStack Foundation API Rules

Spectral linting rules defining API design standards and conventions for AgStack Foundation.

16 Rules error 6 warn 10
View Rules File View on GitHub

Rule Categories

agstack

Rules

warn
agstack-operation-summary-title-case
Operation summaries should use Title Case
$.paths[*][*].summary
error
agstack-operationid-defined
All operations must define an operationId
$.paths[*][get,post,put,delete,patch]
error
agstack-response-200-defined
All operations must define a successful response
$.paths[*][*].responses
warn
agstack-response-422-validation-error
FastAPI operations should document 422 validation errors
$.paths[*][get,post].responses
warn
agstack-security-bearer-defined
Protected operations must declare Bearer security
$.paths[*][post,put,delete,patch]
error
agstack-info-version
API must define a version
$.info
warn
agstack-info-description
API must include a description
$.info
error
agstack-server-url-defined
API must define at least one server URL
$.servers
warn
agstack-schema-type-defined
Schema components must define a type
$.components.schemas[*]
warn
agstack-request-body-content-type
POST/PUT request bodies should specify application/json content type
$.paths[*][post,put].requestBody.content
warn
agstack-tags-on-operations
All operations should have tags for grouping
$.paths[*][*]
warn
agstack-geo-id-format
Geo ID fields should follow AgStack's 16-character alphanumeric format
$.components.schemas[*].properties.geo_id
error
agstack-openapi-version-3
API must use OpenAPI 3.x
$.openapi
warn
agstack-description-field-length
Operation descriptions should be meaningful (min 10 chars)
$.paths[*][*].description
error
agstack-geojson-type-field
GeoJSON schemas must include a type field
$.components.schemas.GeoJSONOut.properties
warn
agstack-paths-lowercase
API paths should use lowercase and hyphens
$.paths

Spectral Ruleset

Raw ↑
rules:
  agstack-operation-summary-title-case:
    description: Operation summaries should use Title Case
    severity: warn
    given: "$.paths[*][*].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

  agstack-operationid-defined:
    description: All operations must define an operationId
    severity: error
    given: "$.paths[*][get,post,put,delete,patch]"
    then:
      field: operationId
      function: defined

  agstack-response-200-defined:
    description: All operations must define a successful response
    severity: error
    given: "$.paths[*][*].responses"
    then:
      function: truthy

  agstack-response-422-validation-error:
    description: FastAPI operations should document 422 validation errors
    severity: warn
    given: "$.paths[*][get,post].responses"
    then:
      function: truthy

  agstack-security-bearer-defined:
    description: Protected operations must declare Bearer security
    severity: warn
    given: "$.paths[*][post,put,delete,patch]"
    then:
      field: security
      function: defined

  agstack-info-version:
    description: API must define a version
    severity: error
    given: "$.info"
    then:
      field: version
      function: defined

  agstack-info-description:
    description: API must include a description
    severity: warn
    given: "$.info"
    then:
      field: description
      function: defined

  agstack-server-url-defined:
    description: API must define at least one server URL
    severity: error
    given: "$.servers"
    then:
      function: length
      functionOptions:
        min: 1

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

  agstack-request-body-content-type:
    description: POST/PUT request bodies should specify application/json content type
    severity: warn
    given: "$.paths[*][post,put].requestBody.content"
    then:
      function: truthy

  agstack-tags-on-operations:
    description: All operations should have tags for grouping
    severity: warn
    given: "$.paths[*][*]"
    then:
      field: tags
      function: defined

  agstack-geo-id-format:
    description: Geo ID fields should follow AgStack's 16-character alphanumeric format
    severity: warn
    given: "$.components.schemas[*].properties.geo_id"
    then:
      function: truthy

  agstack-openapi-version-3:
    description: API must use OpenAPI 3.x
    severity: error
    given: "$.openapi"
    then:
      function: pattern
      functionOptions:
        match: "^3\\."

  agstack-description-field-length:
    description: Operation descriptions should be meaningful (min 10 chars)
    severity: warn
    given: "$.paths[*][*].description"
    then:
      function: minLength
      functionOptions:
        value: 10

  agstack-geojson-type-field:
    description: GeoJSON schemas must include a type field
    severity: error
    given: "$.components.schemas.GeoJSONOut.properties"
    then:
      field: type
      function: defined

  agstack-paths-lowercase:
    description: API paths should use lowercase and hyphens
    severity: warn
    given: "$.paths"
    then:
      function: pattern
      functionOptions:
        match: "^/[a-z0-9/{}_-]+$"