Skip to content

validateOuput() does not take into account content type when validating response body #2713

@mtjandra

Description

@mtjandra

Context

validateOutput() does not take into account the content-type header when validating the response body.

openapi: 3.0.0
info:
  description: service description
  version: '0.1'
  title: service title
tags:
- name: tag1
  description: tag1 description
paths:
  "/test":
    get:
      tags:
      - tag1
      summary: ''
      description: ''
      operationId: testCreateOne
      responses:
        '200':
          description: ''
          content:
            application/json: # will incorrectly validate against this schema even if the matched media type is application/custom+json
              schema:
                properties: {}
            application/custom+json:
              schema:
                required: ['required_property']
                properties:
                  required_property:
                    type: boolean

Current Behavior

When a response for a given status code define schemas for multiple content types, it incorrectly attempts to validate the response body against the first found schema rather than for the media type which matches the content type from the response.

Expected Behavior

When a response for a given status code define schemas for multiple content types, it should validate the response body for the matching endpoint, status code and media type.

See expected behaviour at #2714.

Possible Workaround/Solution

Steps to Reproduce

See test at #2714. Please feel free to fix the bug, unsure if I will get to it.

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions