swagger-api / swagger-api/swagger-ui

Swagger-UI does not render Request Body fields

Open
#9,357 2 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

Using the OpenAPI definition and installation (JS and React) from swagger-ui and swagger-ui-react does not lead to the expected outcome. Only Swagger Editor renders the parameter of the request body in it's ui. The other two implementations do not render anything (see screenshots).

What needs to be changed to get the same functionality across implementations? Currently the default configuration and installation guide does not lead to the expected outcome. Neither does updating swagger-ui to the latest version solve it.

Thank you in advance!

The complete request body section within the Swagger Editor at editor.swagger.io

The empty request body section in the custom implementation using the default configuration

Context
  • OS: macOS 14.0
  • Browser: Firefox 119
  • Method of installation: npm
  • Swagger-UI version: 5.9.1
  • Swagger/OpenAPI version: 3.0.3
Content & configuration

Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: Example
  version: '1.0'
servers:
  - url: https://example.com
paths:
  /v1:
    get:
      security: []
      description: Retrieve version of API.
      responses:
        '200':
          description: ''
          content:
            application/json:
              example:
                message: success
                version: v1
  /v1/foo/new:
    post:
      operationId: https://example.com/api/v1/foo/new
      security: []
      description: Create new foo.
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                amount:
                  type: string
                  default: '2'
                description:
                  type: string
                  default: Example foo
              required:
                - amount
                - description
      responses:
        '200':
          description: ''
          content:
            application/json:
              example:
                success:
                  code: 200
                  message: success
                  data:
                    foo: bar
      parameters:
        - name: Secret
          in: header
          required: true
          schema:
            type: string
          example: xx-xx-xx

Swagger-UI-React configuration options:

import React from 'react';
import ReactDOM from 'react-dom';
import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';

ReactDOM.render(
    (
        <SwaggerUI url="/example.json" />
    ),
    document.querySelector('foo')
);

Swagger-UI configuration options:

import SwaggerUI from 'swagger-ui';
import 'swagger-ui/dist/swagger-ui.css';

SwaggerUI({
    domNode: document.querySelector('foo'),
    url: '/example.json'
});

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 with the supplied OpenAPI 3.0.3 definition in both the JavaScript and React installations, using the documented default configuration. Compare their request-body rendering with editor.swagger.io, and confirm that the amount and description fields appear for the application/x-www-form-urlencoded body in both implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.