Skip to content

OAS2: Execute button doesn't work if the request body fails schema validation, and no errors are seen anywhere #7784

Open
@hkosova

Description

@hkosova

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: Chrome, Firefox latest
  • Method of installation: petstore.swagger.io, editor.swagger.io
  • Swagger-UI version: 4.2.1
  • Swagger/OpenAPI version: OpenAPI 2.0

Content & configuration

Example Swagger/OpenAPI definition:

swagger: '2.0'
info:
  title: test
  version: 1.0.0
host: httpbin.org
schemes:
  - https
paths:
  /post:
    post:
      consumes:
        - application/json
      parameters:
        - in: body
          name: body
          required: true
          schema:
            $ref: '#/definitions/MyModel'
      responses:
        '200':
          description: ok

definitions:
  MyModel:
    type: object
    required:
      - prop1
    properties:
      prop1:
        type: string
        example: foo
        minLength: 10
      prop2:
        type: string
        pattern: ^\d+$

Describe the bug you're encountering

If a JSON request body does not validate against its schema (e.g. a required property is missing, or some property value does not match minLength or pattern), the "Execute" button does not work, it does nothing. Also, there are no errors at all on the page or in the browser console, which makes it very hard to troubleshoot the issue.

Given an equivalent OpenAPI 3 spec, "Execute" button works fine. (It looks like OAS3 request bodies are not validated.)

To reproduce...

  1. Paste the spec above into https://editor.swagger.io
  2. Expand the operation, click "Try it out" and then "Execute".

Expected result: the request is sent.
Actual result: Nothing happens.

  1. Replace the body with the following, and click "Execute" again.
{
  "prop1": "testtesttest",
  "prop2": "1"
}

This time "Execute" works and the request is sent.

  1. Now replace the body with the following and click "Execute" again:
{
  "prop2: "1"
}

Expected result: the request is sent.
Actual result: Nothing happens.

Additional context or thoughts

Possibly related to #6295, #7451

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions