# 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