Cumulocity · API Governance Rules

Cumulocity API Rules

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

12 Rules error 4 warn 4 info 4
View Rules File View on GitHub

Rule Categories

cumulocity

Rules

warn
cumulocity-operation-summary-title-case
Every operation summary should use Title Case.
$.paths[*][get,post,put,delete,patch]
warn
cumulocity-operation-id-camel-case
operationId should be lowerCamelCase.
$.paths[*][get,post,put,delete,patch]
warn
cumulocity-tag-singular-noun
Tags should be human-readable, Title Case nouns describing a resource collection.
$.tags[*]
info
cumulocity-collection-paths-end-with-resource
Collection paths should reference the resource collection in plural form (managedObjects, measurements, events, alarms, operations, externalIds, users, groups, applications, options).
$.paths
info
cumulocity-content-type-vendor-json
Resource responses should use the application/vnd.com.nsn.cumulocity.* content type.
$.paths[*][get,post,put].responses[200,201].content
info
cumulocity-pagination-parameters
List operations should accept pageSize, currentPage, and withTotalPages query parameters.
$.paths[*].get.parameters
info
cumulocity-resource-self-link
Resource schemas should expose a `self` URI for HATEOAS navigation.
$.components.schemas[*].properties
warn
cumulocity-time-fields-iso8601
Time fields (time, creationTime, lastUpdated, firstOccurrenceTime, dateFrom, dateTo) should be RFC 3339 date-time strings.
$.components.schemas[*].properties[time,creationTime,lastUpdated,firstOccurrenceTime,dateFrom,dateTo]
error
cumulocity-alarm-severity-enum
Alarm severity must use the four canonical values.
$.components.schemas.Alarm.properties.severity
error
cumulocity-alarm-status-enum
Alarm status must use the three canonical values.
$.components.schemas.Alarm.properties.status
error
cumulocity-operation-status-enum
Operation status must use the four canonical values.
$.components.schemas.Operation.properties.status
error
cumulocity-security-defined
Every operation must declare security (basicAuth or bearerAuth).
$.paths[*][get,post,put,delete,patch]

Spectral Ruleset

Raw ↑
extends:
- spectral:oas
rules:
  cumulocity-operation-summary-title-case:
    description: Every operation summary should use Title Case.
    severity: warn
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: summary
      function: pattern
      functionOptions:
        match: '^[A-Z][A-Za-z0-9]*(\s[A-Z][A-Za-z0-9]*)*$'
  cumulocity-operation-id-camel-case:
    description: operationId should be lowerCamelCase.
    severity: warn
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: operationId
      function: pattern
      functionOptions:
        match: '^[a-z][a-zA-Z0-9]*$'
  cumulocity-tag-singular-noun:
    description: Tags should be human-readable, Title Case nouns describing a resource collection.
    severity: warn
    given: $.tags[*]
    then:
      field: name
      function: pattern
      functionOptions:
        match: '^[A-Z][A-Za-z0-9 .]+$'
  cumulocity-collection-paths-end-with-resource:
    description: Collection paths should reference the resource collection in plural form (managedObjects, measurements, events, alarms, operations, externalIds, users, groups, applications, options).
    severity: info
    given: $.paths
    then:
      function: truthy
  cumulocity-content-type-vendor-json:
    description: Resource responses should use the application/vnd.com.nsn.cumulocity.* content type.
    severity: info
    given: $.paths[*][get,post,put].responses[200,201].content
    then:
      function: truthy
  cumulocity-pagination-parameters:
    description: List operations should accept pageSize, currentPage, and withTotalPages query parameters.
    severity: info
    given: $.paths[*].get.parameters
    then:
      function: truthy
  cumulocity-resource-self-link:
    description: Resource schemas should expose a `self` URI for HATEOAS navigation.
    severity: info
    given: $.components.schemas[*].properties
    then:
      field: self
      function: truthy
  cumulocity-time-fields-iso8601:
    description: Time fields (time, creationTime, lastUpdated, firstOccurrenceTime, dateFrom, dateTo) should be RFC 3339 date-time strings.
    severity: warn
    given: $.components.schemas[*].properties[time,creationTime,lastUpdated,firstOccurrenceTime,dateFrom,dateTo]
    then:
      field: format
      function: pattern
      functionOptions:
        match: '^date-time$|^date$'
  cumulocity-alarm-severity-enum:
    description: Alarm severity must use the four canonical values.
    severity: error
    given: $.components.schemas.Alarm.properties.severity
    then:
      field: enum
      function: schema
      functionOptions:
        schema:
          type: array
          items:
            type: string
            enum: [CRITICAL, MAJOR, MINOR, WARNING]
  cumulocity-alarm-status-enum:
    description: Alarm status must use the three canonical values.
    severity: error
    given: $.components.schemas.Alarm.properties.status
    then:
      field: enum
      function: schema
      functionOptions:
        schema:
          type: array
          items:
            type: string
            enum: [ACTIVE, ACKNOWLEDGED, CLEARED]
  cumulocity-operation-status-enum:
    description: Operation status must use the four canonical values.
    severity: error
    given: $.components.schemas.Operation.properties.status
    then:
      field: enum
      function: schema
      functionOptions:
        schema:
          type: array
          items:
            type: string
            enum: [PENDING, EXECUTING, SUCCESSFUL, FAILED]
  cumulocity-security-defined:
    description: Every operation must declare security (basicAuth or bearerAuth).
    severity: error
    given: $.paths[*][get,post,put,delete,patch]
    then:
      field: security
      function: defined