Square · API Governance Rules

Square API Rules

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

28 Rules error 7 warn 12 info 9
View Rules File View on GitHub

Rule Categories

info no openapi operation parameter paths response schema security tag

Rules

error
info-title-required
Info title must be present.
$.info
info
info-title-square
Info title should reference Square.
$.info.title
error
info-description-required
Info description must be present.
$.info
warn
info-version-required
Info version must be present.
$.info
info
info-contact-required
A contact object should be provided.
$.info
info
info-license-required
A license object should be provided.
$.info
warn
openapi-version-3
Specification should be OpenAPI 3.x.
$.openapi
warn
paths-versioned
Square Connect resource paths should be versioned under /v2/ (or legacy /v1/).
$.paths[*]~
warn
paths-no-trailing-slash
Paths should not end with a trailing slash.
$.paths[*]~
warn
paths-lowercase
Path segments should be lowercase (snake_case path params allowed).
$.paths[*]~
error
operation-operationid-required
Every operation must have an operationId.
$.paths[*][get,post,put,patch,delete]
warn
operation-operationid-pascalcase
Square operationIds use PascalCase (e.g. CreatePayment, ListLocations).
$.paths[*][get,post,put,patch,delete].operationId
error
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete]
warn
operation-summary-square-prefix
Operation summaries should begin with the provider name "Square".
$.paths[*][get,post,put,patch,delete].summary
info
operation-description-present
Operations should have a description.
$.paths[*][get,post,put,patch,delete]
error
operation-tags-required
Every operation must have tags.
$.paths[*][get,post,put,patch,delete]
warn
parameter-description-required
Parameters should have a description.
$.paths[*][get,post,put,patch,delete].parameters[*]
warn
parameter-name-snakecase
Query and path parameters should use snake_case.
$.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query' || @.in=='path')].name
error
response-description-required
Every response must have a description.
$.paths[*][get,post,put,patch,delete].responses[*]
warn
response-2xx-required
Operations should define at least one 2xx success response.
$.paths[*][get,post,put,patch,delete].responses
info
response-json-content
Responses should serve application/json.
$.paths[*][get,post,put,patch,delete].responses[*].content
warn
schema-property-snakecase
Square schema properties use snake_case.
$.components.schemas[*].properties[*]~
info
schema-type-defined
Schema properties should declare a type or reference.
$.components.schemas[*].properties[*]
warn
security-schemes-defined
Security schemes must be defined under components.
$.components
info
security-oauth2-present
Square uses OAuth 2.0; an oauth2 security scheme should be present.
$.components.securitySchemes
info
tag-name-titlecase
Tag names should be PascalCase / Title Case (e.g. Payments, GiftCards).
$.tags[*].name
error
no-empty-descriptions
Descriptions must not be empty.
$..description
info
operation-examples-encouraged
Operations are encouraged to provide examples for mock servers (Microcks).
$.paths[*][get,post,put,patch,delete]

Spectral Ruleset

Raw ↑
# Square Connect API — Spectral Ruleset
# Generated by the API Evangelist profiling pipeline.
# Enforces the conventions observed across the Square Connect v2 OpenAPI specification:
# - /v2/ versioned, kebab-case-ish resource paths
# - PascalCase operationIds (e.g. CreatePayment, ListLocations)
# - "Square ..." Title Case operation summaries
# - snake_case schema property and parameter names
# - OAuth 2.0 + Square-Version header versioning
rules:

  # ----------------------------------------------------------------------------
  # INFO / METADATA
  # ----------------------------------------------------------------------------
  info-title-required:
    description: Info title must be present.
    severity: error
    given: $.info
    then: {field: title, function: truthy}
  info-title-square:
    description: Info title should reference Square.
    severity: info
    given: $.info.title
    then:
      function: pattern
      functionOptions:
        match: "(?i)square"
  info-description-required:
    description: Info description must be present.
    severity: error
    given: $.info
    then: {field: description, function: truthy}
  info-version-required:
    description: Info version must be present.
    severity: warn
    given: $.info
    then: {field: version, function: truthy}
  info-contact-required:
    description: A contact object should be provided.
    severity: info
    given: $.info
    then: {field: contact, function: truthy}
  info-license-required:
    description: A license object should be provided.
    severity: info
    given: $.info
    then: {field: license, function: truthy}

  # ----------------------------------------------------------------------------
  # OPENAPI VERSION
  # ----------------------------------------------------------------------------
  openapi-version-3:
    description: Specification should be OpenAPI 3.x.
    severity: warn
    given: $.openapi
    then:
      function: pattern
      functionOptions:
        match: "^3\\."

  # ----------------------------------------------------------------------------
  # PATHS — NAMING CONVENTIONS
  # ----------------------------------------------------------------------------
  paths-versioned:
    description: Square Connect resource paths should be versioned under /v2/ (or legacy /v1/).
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        match: "^/v[12]/"
  paths-no-trailing-slash:
    description: Paths should not end with a trailing slash.
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        notMatch: ".+/$"
  paths-lowercase:
    description: Path segments should be lowercase (snake_case path params allowed).
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        match: "^[a-z0-9/_{}.-]+$"

  # ----------------------------------------------------------------------------
  # OPERATIONS
  # ----------------------------------------------------------------------------
  operation-operationid-required:
    description: Every operation must have an operationId.
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then: {field: operationId, function: truthy}
  operation-operationid-pascalcase:
    description: Square operationIds use PascalCase (e.g. CreatePayment, ListLocations).
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].operationId
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][A-Za-z0-9]+$"
  operation-summary-required:
    description: Every operation must have a summary.
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then: {field: summary, function: truthy}
  operation-summary-square-prefix:
    description: Operation summaries should begin with the provider name "Square".
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].summary
    then:
      function: pattern
      functionOptions:
        match: "^Square "
  operation-description-present:
    description: Operations should have a description.
    severity: info
    given: $.paths[*][get,post,put,patch,delete]
    then: {field: description, function: truthy}
  operation-tags-required:
    description: Every operation must have tags.
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then: {field: tags, function: truthy}

  # ----------------------------------------------------------------------------
  # PARAMETERS
  # ----------------------------------------------------------------------------
  parameter-description-required:
    description: Parameters should have a description.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].parameters[*]
    then: {field: description, function: truthy}
  parameter-name-snakecase:
    description: Query and path parameters should use snake_case.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].parameters[?(@.in=='query' || @.in=='path')].name
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"

  # ----------------------------------------------------------------------------
  # RESPONSES
  # ----------------------------------------------------------------------------
  response-description-required:
    description: Every response must have a description.
    severity: error
    given: $.paths[*][get,post,put,patch,delete].responses[*]
    then: {field: description, function: truthy}
  response-2xx-required:
    description: Operations should define at least one 2xx success response.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      field: "200"
      function: truthy
  response-json-content:
    description: Responses should serve application/json.
    severity: info
    given: $.paths[*][get,post,put,patch,delete].responses[*].content
    then:
      field: application/json
      function: truthy

  # ----------------------------------------------------------------------------
  # SCHEMAS — PROPERTY NAMING
  # ----------------------------------------------------------------------------
  schema-property-snakecase:
    description: Square schema properties use snake_case.
    severity: warn
    given: $.components.schemas[*].properties[*]~
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-z0-9_]*$"
  schema-type-defined:
    description: Schema properties should declare a type or reference.
    severity: info
    given: $.components.schemas[*].properties[*]
    then:
      function: xor
      functionOptions:
        properties: [type, $ref, allOf, oneOf, anyOf]

  # ----------------------------------------------------------------------------
  # SECURITY
  # ----------------------------------------------------------------------------
  security-schemes-defined:
    description: Security schemes must be defined under components.
    severity: warn
    given: $.components
    then: {field: securitySchemes, function: truthy}
  security-oauth2-present:
    description: Square uses OAuth 2.0; an oauth2 security scheme should be present.
    severity: info
    given: $.components.securitySchemes
    then: {field: oauth2, function: truthy}

  # ----------------------------------------------------------------------------
  # TAGS
  # ----------------------------------------------------------------------------
  tag-name-titlecase:
    description: Tag names should be PascalCase / Title Case (e.g. Payments, GiftCards).
    severity: info
    given: $.tags[*].name
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z]"

  # ----------------------------------------------------------------------------
  # GENERAL QUALITY
  # ----------------------------------------------------------------------------
  no-empty-descriptions:
    description: Descriptions must not be empty.
    severity: error
    given: $..description
    then: {function: truthy}
  operation-examples-encouraged:
    description: Operations are encouraged to provide examples for mock servers (Microcks).
    severity: info
    given: $.paths[*][get,post,put,patch,delete]
    then: {field: x-microcks-operation, function: truthy}