question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Impossible to submit required params in react app which is using SwaggerUi component

See original GitHub issue

Prerequisites

  • OS: macOS
  • Browser: chrome
  • Version: 67
  • Method of installation: npm
  • Swagger-UI version: 3.17.3
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Swagger UI is used inside react component. React version is ^16.3.2

Example Swagger/OpenAPI definition: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

Swagger-UI configuration options:

SwaggerUI({
  dom_id: "#swagger",
  url: spec_url,
})

Describe the bug you’re encountering

Impossible to specify the required parameter for routes like /get/{petId}. The UI just remove it when I’m clicking on Try it Out -> Execute button.

To reproduce…

Steps to reproduce the behavior:

  1. Click on any route with required parameter. E.g. /pet/{petId}
  2. Click “Try it out” button
  3. Specify pet id
  4. Click on “execute” button
  5. See error - pet id was removed, petId field is red. UI doesn’t send any http request

Expected behavior

UI sends the HTTP request and display the results

Screenshots

video

Additional context or thoughts

This is most visible issue that have direct impact on functionality. However, there are tons of JS errors in the chrome console. They appear on almost every stage: page load, authorization modal window, submiting requests, etc.

I think most of problems come from different react versions used in app and swagger ui

Other related issues: textarea with console curl command always show curl -X "undefined" instead of actual command(HTTP request is different)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
shockeycommented, Mar 2, 2019

Fixed!

We’ve just released swagger-ui-react, which declares React as a peer dependency. I’ve tested this module within a React 16 create-react-app, and the required parameter issue is no longer present.

2reactions
newdaveespionagecommented, Jan 16, 2019

Adding this note in case someone comes upon this issue and thinks “I’m not integrating this into a React 16 app, why might I be seeing this?”

This also happens in a dev environment running Swagger UI “standalone” with another React-dependent tool being used in the same dev install.

To recreate, install Storybook as a devDependency, and implement a simple one page Swagger UI display separately in the same dev environment (meaning, installed as a devDependency as well) following the Swagger UI documentation. Storybook’s React dependency is hard-set, so it’s impossible to avoid installing 16 in this scenario, and this bug is then exposed for any required field.

I’m looking at breaking either Storybook or Swagger into a separate project, but due to requirements around our project, both have to live in the same repository and aren’t easily built separately.

If I can contribute to one of the outstanding issues in the React 16 epic, I’ll give it a shot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger-UI, react app - cannot fill parameter fields (or data ...
I would want to specify them though and get some other responses. Is there something in the swagger json config file or more...
Read more >
How to Document an Express API with Swagger UI and JSDoc
In your Express API's app.js file, add the following code below the list of required modules: // app.js const swaggerJSDoc ...
Read more >
Generating and integrating OpenAPI services in a React app
We look at how to integrate an OpenAPI-generated service from the server, then use this generated service across a React TypeScript app.
Read more >
How to add Swagger UI to an existing Node.js and Express.js ...
Open the server.js file and add the below code for swagger integration const swaggerUi = require('swagger-ui-express'),swaggerDocument = require('.
Read more >
How to implement and use Swagger in Node.js - In Plain English
In this article, I will talk about;. how to implement Swagger to a RESTful web server built with Node.js. Swagger UI. API documentation....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found