Google Places · API Governance Rules

Google Places API Rules

Spectral linting rules defining API design standards and conventions for Google Places.

39 Rules error 6 warn 20 info 13
View Rules File View on GitHub

Rule Categories

get info no openapi operation parameter paths post request response schema security servers tags

Rules

warn
info-title-google-places
The info.title must begin with "Google Places".
$.info.title
warn
info-description-required
A non-trivial info.description is required.
$.info
info
info-contact-required
Provider contact information should be present.
$.info
info
info-license-required
A license (Google APIs Terms of Service) should be declared.
$.info
warn
openapi-version-3-1
Specs must target OpenAPI 3.1.0.
$.openapi
error
servers-defined
At least one server must be defined.
$.servers
error
servers-https-only
Server URLs must use HTTPS.
$.servers[*].url
info
servers-places-host
The production server should be the Places API (New) host.
$.servers[*].url
warn
paths-no-trailing-slash
Paths must not end with a trailing slash.
$.paths[*]~
error
paths-no-query-string
Paths must not contain query strings.
$.paths[*]~
info
paths-places-prefix
All resource paths live under the /places collection.
$.paths[*]~
warn
operation-summary-required
Every operation must have a summary.
$.paths[*][get,post,put,patch,delete]
warn
operation-summary-google-places-prefix
Operation summaries must begin with "Google Places".
$.paths[*][get,post,put,patch,delete].summary
warn
operation-description-required
Every operation must have a description.
$.paths[*][get,post,put,patch,delete]
error
operation-operationId-required
Every operation must declare an operationId.
$.paths[*][get,post,put,patch,delete]
warn
operation-operationId-camelcase
operationId must be camelCase.
$.paths[*][get,post,put,patch,delete].operationId
info
operation-operationId-verb-prefix
operationId should start with a recognized verb (get, list, search, autocomplete, create, update, delete).
$.paths[*][get,post,put,patch,delete].operationId
warn
operation-tags-required
Every operation must have at least one tag.
$.paths[*][get,post,put,patch,delete]
info
operation-microcks-extension
Each operation should carry an x-microcks-operation extension for mock-server compatibility.
$.paths[*][get,post,put,patch,delete]
warn
tags-global-defined
A global tags array must be defined.
$
warn
tags-title-case
Global tag names must use Title Case (e.g. "Places", "Search").
$.tags[*].name
info
tags-have-description
Global tags should include a description.
$.tags[*]
warn
parameter-description-required
Every parameter must have a description.
$.paths[*][get,post,put,patch,delete].parameters[*]
warn
parameter-schema-required
Every parameter must define a schema with a type.
$.paths[*][get,post,put,patch,delete].parameters[?(@.in)]
info
parameter-field-mask-required
Places API (New) requests require the X-Goog-FieldMask header; a reusable FieldMask parameter should be defined.
$.components.parameters
warn
request-body-json
Request bodies must offer an application/json media type.
$.paths[*][post,put,patch].requestBody.content
warn
post-has-request-body
POST operations (search, autocomplete) must declare a request body.
$.paths[*].post
error
response-2xx-required
Every operation must define a 2xx success response.
$.paths[*][get,post,put,patch,delete].responses
info
response-json-content
200 responses should return application/json.
$.paths[*][get,post,put,patch,delete].responses.200.content
info
response-error-schema-message
The Error schema should expose an error object carrying a message.
$.components.schemas.Error.properties.error.properties
warn
schema-property-camelcase
Schema property names must be camelCase, matching the Places API (New) convention.
$.components.schemas[*].properties[*]~
info
schema-top-level-description
Top-level component schemas should have a description.
$.components.schemas[*]
warn
schema-types-defined
Component schemas must declare a type.
$.components.schemas[*]
warn
security-global-defined
A global security requirement must be declared.
$
warn
security-schemes-defined
Security schemes must be defined in components.
$.components
info
security-api-key-header
The primary API key scheme should be the X-Goog-Api-Key header.
$.components.securitySchemes.ApiKeyAuth
error
get-no-request-body
GET operations must not declare a request body.
$.paths[*].get
warn
no-empty-descriptions
Descriptions must not be empty strings.
$..description
info
schema-examples-encouraged
Schema properties are encouraged to provide example values.
$.components.schemas[*].properties[?(@.type && @.type != 'object' && @.type != 'array')]

Spectral Ruleset

Raw ↑
# Spectral ruleset for the Google Places API (New)
# Generated by the API Evangelist profiling pipeline.
# Enforces the conventions observed across the google-places OpenAPI specifications:
#   - info.title and operation summaries prefixed with "Google Places"
#   - OpenAPI 3.1.0
#   - HTTPS server at https://places.googleapis.com/v1
#   - search/autocomplete operations use POST with a request body; details/photos use GET
#   - camelCase operationIds with verb prefixes; camelCase schema properties
#   - X-Goog-Api-Key header authentication (with key query fallback) and OAuth2
#   - the X-Goog-FieldMask header is required on requests
#   - Title Case global tags
extends: []
rules:

  # ---------------------------------------------------------------------------
  # INFO / METADATA
  # ---------------------------------------------------------------------------
  info-title-google-places:
    description: The info.title must begin with "Google Places".
    severity: warn
    given: $.info.title
    then:
      function: pattern
      functionOptions:
        match: "^Google Places"
  info-description-required:
    description: A non-trivial info.description is required.
    severity: warn
    given: $.info
    then:
      field: description
      function: truthy
  info-contact-required:
    description: Provider contact information should be present.
    severity: info
    given: $.info
    then:
      field: contact
      function: truthy
  info-license-required:
    description: A license (Google APIs Terms of Service) should be declared.
    severity: info
    given: $.info
    then:
      field: license
      function: truthy

  # ---------------------------------------------------------------------------
  # OPENAPI VERSION
  # ---------------------------------------------------------------------------
  openapi-version-3-1:
    description: Specs must target OpenAPI 3.1.0.
    severity: warn
    given: $.openapi
    then:
      function: pattern
      functionOptions:
        match: "^3\\.1\\."

  # ---------------------------------------------------------------------------
  # SERVERS
  # ---------------------------------------------------------------------------
  servers-defined:
    description: At least one server must be defined.
    severity: error
    given: $.servers
    then:
      function: truthy
  servers-https-only:
    description: Server URLs must use HTTPS.
    severity: error
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: "^https://"
  servers-places-host:
    description: The production server should be the Places API (New) host.
    severity: info
    given: $.servers[*].url
    then:
      function: pattern
      functionOptions:
        match: "places\\.googleapis\\.com"

  # ---------------------------------------------------------------------------
  # PATHS — NAMING CONVENTIONS
  # ---------------------------------------------------------------------------
  paths-no-trailing-slash:
    description: Paths must not end with a trailing slash.
    severity: warn
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        notMatch: ".+/$"
  paths-no-query-string:
    description: Paths must not contain query strings.
    severity: error
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        notMatch: "\\?"
  paths-places-prefix:
    description: All resource paths live under the /places collection.
    severity: info
    given: $.paths[*]~
    then:
      function: pattern
      functionOptions:
        match: "^/places"

  # ---------------------------------------------------------------------------
  # OPERATIONS
  # ---------------------------------------------------------------------------
  operation-summary-required:
    description: Every operation must have a summary.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: summary
      function: truthy
  operation-summary-google-places-prefix:
    description: Operation summaries must begin with "Google Places".
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].summary
    then:
      function: pattern
      functionOptions:
        match: "^Google Places"
  operation-description-required:
    description: Every operation must have a description.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: description
      function: truthy
  operation-operationId-required:
    description: Every operation must declare an operationId.
    severity: error
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: operationId
      function: truthy
  operation-operationId-camelcase:
    description: operationId must be camelCase.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].operationId
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]+$"
  operation-operationId-verb-prefix:
    description: operationId should start with a recognized verb (get, list, search, autocomplete, create, update, delete).
    severity: info
    given: $.paths[*][get,post,put,patch,delete].operationId
    then:
      function: pattern
      functionOptions:
        match: "^(get|list|search|autocomplete|create|update|delete)"
  operation-tags-required:
    description: Every operation must have at least one tag.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: tags
      function: truthy
  operation-microcks-extension:
    description: Each operation should carry an x-microcks-operation extension for mock-server compatibility.
    severity: info
    given: $.paths[*][get,post,put,patch,delete]
    then:
      field: x-microcks-operation
      function: truthy

  # ---------------------------------------------------------------------------
  # TAGS
  # ---------------------------------------------------------------------------
  tags-global-defined:
    description: A global tags array must be defined.
    severity: warn
    given: $
    then:
      field: tags
      function: truthy
  tags-title-case:
    description: Global tag names must use Title Case (e.g. "Places", "Search").
    severity: warn
    given: $.tags[*].name
    then:
      function: pattern
      functionOptions:
        match: "^[A-Z][A-Za-z]+( [A-Z][A-Za-z]+)*$"
  tags-have-description:
    description: Global tags should include a description.
    severity: info
    given: $.tags[*]
    then:
      field: description
      function: truthy

  # ---------------------------------------------------------------------------
  # PARAMETERS
  # ---------------------------------------------------------------------------
  parameter-description-required:
    description: Every parameter must have a description.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].parameters[*]
    then:
      field: description
      function: truthy
  parameter-schema-required:
    description: Every parameter must define a schema with a type.
    severity: warn
    given: $.paths[*][get,post,put,patch,delete].parameters[?(@.in)]
    then:
      field: schema
      function: truthy
  parameter-field-mask-required:
    description: Places API (New) requests require the X-Goog-FieldMask header; a reusable FieldMask parameter should be defined.
    severity: info
    given: $.components.parameters
    then:
      field: FieldMask
      function: truthy

  # ---------------------------------------------------------------------------
  # REQUEST BODIES
  # ---------------------------------------------------------------------------
  request-body-json:
    description: Request bodies must offer an application/json media type.
    severity: warn
    given: $.paths[*][post,put,patch].requestBody.content
    then:
      field: application/json
      function: truthy
  post-has-request-body:
    description: POST operations (search, autocomplete) must declare a request body.
    severity: warn
    given: $.paths[*].post
    then:
      field: requestBody
      function: truthy

  # ---------------------------------------------------------------------------
  # RESPONSES
  # ---------------------------------------------------------------------------
  response-2xx-required:
    description: Every operation must define a 2xx success response.
    severity: error
    given: $.paths[*][get,post,put,patch,delete].responses
    then:
      field: "200"
      function: truthy
  response-json-content:
    description: 200 responses should return application/json.
    severity: info
    given: $.paths[*][get,post,put,patch,delete].responses.200.content
    then:
      field: application/json
      function: truthy
  response-error-schema-message:
    description: The Error schema should expose an error object carrying a message.
    severity: info
    given: $.components.schemas.Error.properties.error.properties
    then:
      field: message
      function: truthy

  # ---------------------------------------------------------------------------
  # SCHEMAS — PROPERTY NAMING
  # ---------------------------------------------------------------------------
  schema-property-camelcase:
    description: Schema property names must be camelCase, matching the Places API (New) convention.
    severity: warn
    given: $.components.schemas[*].properties[*]~
    then:
      function: pattern
      functionOptions:
        match: "^[a-z][a-zA-Z0-9]*$"
  schema-top-level-description:
    description: Top-level component schemas should have a description.
    severity: info
    given: $.components.schemas[*]
    then:
      field: description
      function: truthy
  schema-types-defined:
    description: Component schemas must declare a type.
    severity: warn
    given: $.components.schemas[*]
    then:
      field: type
      function: truthy

  # ---------------------------------------------------------------------------
  # SECURITY
  # ---------------------------------------------------------------------------
  security-global-defined:
    description: A global security requirement must be declared.
    severity: warn
    given: $
    then:
      field: security
      function: truthy
  security-schemes-defined:
    description: Security schemes must be defined in components.
    severity: warn
    given: $.components
    then:
      field: securitySchemes
      function: truthy
  security-api-key-header:
    description: The primary API key scheme should be the X-Goog-Api-Key header.
    severity: info
    given: $.components.securitySchemes.ApiKeyAuth
    then:
      - field: in
        function: pattern
        functionOptions:
          match: "^header$"
      - field: name
        function: pattern
        functionOptions:
          match: "^X-Goog-Api-Key$"

  # ---------------------------------------------------------------------------
  # HTTP METHOD CONVENTIONS
  # ---------------------------------------------------------------------------
  get-no-request-body:
    description: GET operations must not declare a request body.
    severity: error
    given: $.paths[*].get
    then:
      field: requestBody
      function: falsy

  # ---------------------------------------------------------------------------
  # GENERAL QUALITY
  # ---------------------------------------------------------------------------
  no-empty-descriptions:
    description: Descriptions must not be empty strings.
    severity: warn
    given: $..description
    then:
      function: truthy
  schema-examples-encouraged:
    description: Schema properties are encouraged to provide example values.
    severity: info
    given: $.components.schemas[*].properties[?(@.type && @.type != 'object' && @.type != 'array')]
    then:
      field: example
      function: truthy