TensorFlow · API Governance Rules

TensorFlow API Rules

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

13 Rules error 5 warn 7
View Rules File View on GitHub

Rule Categories

tensorflow

Rules

warn
tensorflow-operation-id-kebab-case
Operation IDs should use camelCase following TensorFlow Serving conventions
$.paths[*][get,post,put,patch,delete].operationId
false
tensorflow-model-name-in-path
Model endpoints must include model_name path parameter
$.paths['/v1/models/{model_name}*']
error
tensorflow-path-versioned
All TensorFlow Serving API paths must be versioned with /v1/
$.paths[*]~
error
tensorflow-inference-methods
Inference endpoints (classify, regress, predict) must use POST
$.paths[*classify,*regress,*predict]
error
tensorflow-status-get-method
Model status and metadata endpoints must use GET
$.paths['/v1/models/{model_name}','/v1/models/{model_name}/metadata']
error
tensorflow-response-200-defined
All operations must define a 200 success response
$.paths[*][get,post,put,patch,delete].responses
warn
tensorflow-error-response-defined
Operations should define error responses
$.paths[*][get,post,put,patch,delete].responses
error
tensorflow-request-body-inference
Inference operations must define a request body
$.paths[*classify,*regress,*predict].post
warn
tensorflow-json-content-type
TensorFlow Serving uses JSON for all request/response bodies
$.paths[*][post].requestBody.content
warn
tensorflow-tags-defined
All operations should be tagged
$.paths[*][get,post,put,patch,delete]
warn
tensorflow-summary-title-case
All operation summaries should use Title Case
$.paths[*][get,post,put,patch,delete].summary
warn
tensorflow-description-present
All operations should have a description
$.paths[*][get,post,put,patch,delete]
warn
tensorflow-schema-descriptions
Schema components should have descriptions
$.components.schemas[*]

Spectral Ruleset

Raw ↑
extends: spectral:oas
rules:
  # Naming Conventions
  tensorflow-operation-id-kebab-case:
    description: Operation IDs should use camelCase following TensorFlow Serving conventions
    message: "Operation ID '{{value}}' should use camelCase"
    given: "$.paths[*][get,post,put,patch,delete].operationId"
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"
    severity: warn

  tensorflow-model-name-in-path:
    description: Model endpoints must include model_name path parameter
    message: "Model inference paths should include {model_name} path parameter"
    given: "$.paths['/v1/models/{model_name}*']"
    then:
      field: get
      function: truthy
    severity: off

  tensorflow-path-versioned:
    description: All TensorFlow Serving API paths must be versioned with /v1/
    message: "Path '{{property}}' must start with /v1/"
    given: "$.paths[*]~"
    then:
      function: pattern
      functionOptions:
        match: "^/v1/"
    severity: error

  tensorflow-inference-methods:
    description: Inference endpoints (classify, regress, predict) must use POST
    message: "TensorFlow Serving inference endpoints must use POST method"
    given: "$.paths[*classify,*regress,*predict]"
    then:
      field: post
      function: truthy
    severity: error

  tensorflow-status-get-method:
    description: Model status and metadata endpoints must use GET
    message: "Model status and metadata endpoints must use GET method"
    given: "$.paths['/v1/models/{model_name}','/v1/models/{model_name}/metadata']"
    then:
      field: get
      function: truthy
    severity: error

  tensorflow-response-200-defined:
    description: All operations must define a 200 success response
    message: "Operation '{{path}}' must define a 200 success response"
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      field: "200"
      function: truthy
    severity: error

  tensorflow-error-response-defined:
    description: Operations should define error responses
    message: "Operation should define at least one error response (4xx)"
    given: "$.paths[*][get,post,put,patch,delete].responses"
    then:
      function: schema
      functionOptions:
        schema:
          anyOf:
            - required: ['400']
            - required: ['401']
            - required: ['404']
    severity: warn

  tensorflow-request-body-inference:
    description: Inference operations must define a request body
    message: "Inference operation '{{path}}' must define a request body"
    given: "$.paths[*classify,*regress,*predict].post"
    then:
      field: requestBody
      function: truthy
    severity: error

  tensorflow-json-content-type:
    description: TensorFlow Serving uses JSON for all request/response bodies
    message: "TensorFlow Serving endpoints should use application/json content type"
    given: "$.paths[*][post].requestBody.content"
    then:
      field: "application/json"
      function: truthy
    severity: warn

  tensorflow-tags-defined:
    description: All operations should be tagged
    message: "Operation is missing tags"
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: tags
      function: truthy
    severity: warn

  tensorflow-summary-title-case:
    description: All operation summaries should use Title Case
    message: "Summary '{{value}}' should use Title Case"
    given: "$.paths[*][get,post,put,patch,delete].summary"
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"
    severity: warn

  tensorflow-description-present:
    description: All operations should have a description
    message: "Operation is missing a description"
    given: "$.paths[*][get,post,put,patch,delete]"
    then:
      field: description
      function: truthy
    severity: warn

  tensorflow-schema-descriptions:
    description: Schema components should have descriptions
    message: "Schema '{{path}}' is missing a description"
    given: "$.components.schemas[*]"
    then:
      field: description
      function: truthy
    severity: warn