swagger-api / swagger-api/swagger-ui

Execute button non-responsive when using form data input if read only field exists in schema

Open
#7,242 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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: macOS 11.3.1
  • Browser: Tested with Brave 1.24.82 and Firefox 88.0
  • Swagger-UI version: 3.44.0 (and whatever runs on editor.swagger.io)
  • Swagger/OpenAPI version: OpenAPI 3.0.3
Content & configuration

Steps to re-produce:

  1. Visit https://editor.swagger.io.
  2. Paste the schema provided below.
  3. Expand POST /sample/ endpoint
  4. Set Request body: multipart/form-data
  5. Enter any text in description
  6. Click Execute

You should see that nothing happens.

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: 'Sample issue'
  version: 0.0.0
paths:
  /sample/:
    post:
      operationId: sample_create
      description: Sample viewset.
      tags:
      - sample
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Sample'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Sample'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Sample'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sample'
          description: ''
components:
  schemas:
    PatchedSample:
      type: object
      description: Sample serializer to demonstrate issue.
      properties:
        id:
          type: integer
          readOnly: true
        description:
          type: string
    Sample:
      type: object
      description: Sample serializer to demonstrate issue.
      properties:
        id:
          type: integer
          readOnly: true
        description:
          type: string
      required:
      - description
      - id

If you remove the readOnly: true line from the id field on the Sample schema, the problem goes away.

Describe the bug you're encountering

The execute button is non-responsive when trying to make a POST request to an API with a schema that contains a read only field.

Additional context or thoughts

I suspect that the validation done when hitting Execute is including the id read only field in the backround?

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 3.0.3 schema, using multipart/form-data and a readOnly id field. Start by tracing what happens when Execute is clicked and compare it with the schema after removing readOnly; done means the request executes normally while preserving read-only field behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.