swagger-api / swagger-api/swagger-ui

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

Open
#7,784 5 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: try-it-out type: bug
Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in editor.swagger.io with the provided OpenAPI 2.0 definition and invalid request bodies. Trace the Execute flow and request-body validation handling, including whether errors reach the page or browser console. Done means invalid input produces a visible error or the documented request behavior is restored, with the valid-body case still executing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.