swagger-api / swagger-api/swagger-ui

Render fields for additional properties when using ` application/x-www-form-urlencoded`

Open
#8,576 0 comments 4 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

Content & configuration

Swagger/OpenAPI definition:

openapi: 3.0.3
info:
 title: additionalProperties Demo
 version: '1.0'
servers:
 - url: /
paths:
 /example:
   put:
     summary: Put endpoint
     requestBody:
       $ref: '#/components/requestBodies/PutRequestBody'
     responses:
       default:
         description: success
components:
 schemas:
   PutRequest:
     type: object
     properties:
       required:
         type: string
       not_required:
         type: string
     required:
       - required
     additionalProperties:
       type: string
 requestBodies:
   PutRequestBody:
     required: true
     content:
       application/x-www-form-urlencoded:
         schema:
           $ref: "#/components/schemas/PutRequest"

Swagger-UI configuration options:

 SwaggerUI({
   '/spec.json',
   dom_id: '#spec'
 })

SwaggerUI version: 3.52.0

Is your feature request related to a problem?

When the request body schema contains additionalProperties and the content type is application/x-www-form-urlencoded, the custom (additional) properties are not rendered on the form (see screenshot), thus making it impossible for the user to enter custom properties to the API call.
Screenshot from 2023-04-19 14-50-20

The fact that the schema is not referenced in the request body section at all also makes it difficult for the user to even realize that they may add extra properties (and if they do - they would need to add them manually in their curl)

Describe the solution you'd like

If additionalProperties is configured in the schema of the request parameters, and the content type is application/x-www-form-urlencoded, then I would expect some interface to actually add custom fields: maybe a button to add an element, and have both the field key and value empty. See screenshot:
Screenshot from 2023-04-19 14-57-59

Describe alternatives you've considered

The workaround for this would be to just specify this in text in the request body description.

Additional context

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 Swagger UI with the provided OpenAPI 3.0.3 definition and an application/x-www-form-urlencoded request body containing additionalProperties. Trace the form rendering and request serialization entry points; done means users can add custom key/value fields and those fields appear in the generated API call.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.