1

Trying to setup a cloud endpoint. with the following config.

# openapi2-functions.yaml
swagger: '2.0'
info:
  title: Redacted
  description: Redacted
  version: 1.0.0
schemes: [http, https]
produces:
  - application/json
paths:
  /service/{route}/{id_}:
    get:
      summary: <summary> 
      operationId: service
      parameters: 
        - in: path
          name: route
          type: string
          required: true
        - in: path
          name: id_
          type: string
          default: ""
          required: false
      x-google-backend:
        address: http://<URL_HERE>/{route}/{id_}
        path_translation: APPEND_PATH_TO_ADDRESS
        deadline: 60.0
      responses:
        '200':
          description: A successful response
          schema:
            type: string

I'm setting required to false for id_. When I try to deploy this YAML file, i get the following error:

"domain": "validation",
"keyword": "additionalProperties",
"message": "object instance has properties which are not allowed by the schema: [\"default\",\"type\"]",
"unwanted": ["default", "type"]

Also:

"domain": "validation",
"keyword": "required",
"message": "object has missing required properties ([\"schema\"])",
"required": ["in", "name", "schema"],
"missing": ["schema"]

When I set it to True, it deploys just fine but that is not the behaviour I want.

When i actually add the schema to the parameters as follows, i get another error.

parameters:
  - required: false
    schema:
      title: id_
    name: id_
    in: path

Error:

"domain": "validation",
"keyword": "additionalProperties",
"message": "object instance has properties which are not allowed by the schema: [\"schema\"]",
"unwanted": ["schema"]
Nissan
  • 466
  • 1
  • 4
  • 12
  • 1
    Path parameters are required so they _must_ always have `required: true`. If you need an optional path parameter, you need to define two paths - with and without that parameter. See the [linked Q&A](https://stackoverflow.com/q/35011192/113116). – Helen Sep 21 '21 at 07:37

0 Answers0