stoplightio / prism

Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
https://stoplight.io/open-source/prism
Apache License 2.0
4.27k stars 343 forks source link

Validation error on object as Header Parameter #2559

Open felixwoestmann opened 3 months ago

felixwoestmann commented 3 months ago

For an endpoint which has an object as a header parameter I receive an validation error, even though my spec is consistent with the OpenAPI 3 standard.

Current Behavior

The server errors saying:

Request did not pass the validation rules
[12:27:04 PM] ›     [VALIDATOR] ✖  error     Request header parameter exclude must have required property 'name'

Expected Behavior

The server answers with a mock response.

Steps to Reproduce

Here is the OpenAPI definition used and the corresponding cURL with the object serialization as described in https://swagger.io/docs/specification/serialization/#header

curl -X GET 'http://localhost:4010/pets/header' -H 'Prefer: code=200' -H 'exclude: id, 10, name, Fido, tag, tag1'

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets/header:
    get:
      summary: List all pets with header params
      operationId: listPetsHeader
      tags:
        - pets
      parameters:
        - name: exclude
          in:  header
          description: tags to exclude
          required: true
          schema:
            $ref: "#/components/schemas/Pet"
      responses:
        '200':
          description: A paged array of pets
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pets"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      maxItems: 100
      items:
        $ref: "#/components/schemas/Pet"

Environment

tesanchez commented 3 months ago

Hello, it doesnt seem like prism support this. Can you help me understand how often you are seeing objects in headers and how it will benefit you?

felixwoestmann commented 3 months ago

Hello, I have never encountered it in the wild. I am developing an OpenAPI Code generator and am using prism to validate my implementation. I was implementing header parameters when I encountered the issue.