swagger-api / swagger-api/swagger-ui

No inputs being sent with API Request

Open
#5,990 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: support
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: OSX
  • Browser: Chrome, Safari, Firefox (latest)
  • Method of installation: npm
  • Swagger-UI version: 3.25.1
  • Swagger/OpenAPI version: 2.0
Content & configuration

Example Swagger/OpenAPI definition:

swagger: '2.0'
info:
  description: The Grouparoo Staging Application
  version: 0.1.2-alpha.4
  title: '@grouparoo/app-staging-public'
  license:
    name: MPL-2.0
host: 'localhost:3000'
basePath: /v1
schemes:
  - http
paths:
  '/apiKey/{guid}':
    get:
      tags:
        - apiKey
      summary: view an apiKey
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: path
          name: guid
          type: string
          required: true
      responses:
        '200':
          description: successful operation
        '400':
          description: Invalid input
        '404':
          description: Not Fount
        '422':
          description: Missing or invalid params
        '500':
          description: Server error
      security:
        - GrouparooAPIKey: []
securityDefinitions:
  GrouparooAPIKey:
    type: apiKey
    name: apiKey
    in: query
externalDocs:
  description: Learn more about Grouparoo
  url: 'https://www.grouparoo.com'

Swagger-UI configuration options:

import { Component } from "react";

interface Props {
  apiVersion: string;
}

export default class Swagger extends Component<Props> {
  componentDidMount() {
    // we need to wait for didMount as swagger won't render with SSR
    const SwaggerUi = require("swagger-ui");

    const { apiVersion } = this.props;

    const swagger = SwaggerUi({
      dom_id: "#swaggerContainer",
      url: `/api/${apiVersion}/swagger`,
      presets: [SwaggerUi.presets.apis],
      deepLinking: true,
      docExpansion: "none",
      filter: true
    });
  }

  render() {
    return <div id="swaggerContainer" />;
  }
}
Describe the bug you're encountering

When rendering swagger-ui with Next.js, none of the inputs forms' data is actually sent to the server in the API request. This manifests in a few ways:

  • Required params look like they are never filled out
Screen Shot 2020-05-06 at 8 26 08 PM
  • The defaults are always used, no matter what
To reproduce...

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error
Expected behavior

Data the user types into the swagger ui should be sent to the server

Additional context or thoughts

The same swagger doc used on https://editor.swagger.io seems work fine. So I think the problem is isolated to the swagger-ui component. Also, something in Swagger might be conflicting with Next?

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

Start at the SwaggerUi initialization in componentDidMount and compare the Next.js rendering path with editor.swagger.io using the supplied OpenAPI definition. Reproduce a request with the required guid or an edited input; done means values entered in Swagger UI are included in the server request instead of being omitted or replaced by defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.