OpenAPI errors

How to fix "path parameter must be required" in OpenAPI

An OpenAPI parameter with in: path must set required: true. It cannot be optional because the URL template cannot match the operation without a value for that segment.

Broken YAML

The parameter exists, but it is marked optional:

openapi: 3.1.0
info:
  title: Users API
  version: 1.0.0
paths:
  /users/{userId}:
    get:
      operationId: getUser
      parameters:
        - name: userId
          in: path
          required: false
          schema:
            type: string
      responses:
        '200':
          description: User returned

Why it fails

The Parameter Object rule requires the required field for every path parameter, and its value must be true. Omitting the field also fails the rule. The normal default of false for other parameter locations does not apply to path parameters.

If the value is optional in the real API, it cannot stay as an optional path segment in one OpenAPI path. Model separate paths, such as /users and /users/{userId}, or move the optional value to a query parameter if that matches the API.

Corrected YAML

Set the path parameter to required:

openapi: 3.1.0
info:
  title: Users API
  version: 1.0.0
paths:
  /users/{userId}:
    get:
      operationId: getUser
      parameters:
        - name: userId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: User returned

OpenAPI 3.0 vs 3.1

There is no version difference. OpenAPI 3.0 and OpenAPI 3.1 both require required: true when in: path.

Validate the fix

Open the Sourced OpenAPI validator, paste the complete document, and select Validate spec. It reports every path parameter that is missing required: true.

If the URL contains a template variable with no Parameter Object at all, use the missing path parameter declaration guide.