Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do render swagger.json content in reactjs

I am trying to create a document portal for my API’s with Express and reactJs. Basically, I get the JSON content(swagger.json) from the Express server and I want to pass it to swagger UI on the client to display

In the docs (https://www.npmjs.com/package/swagger-ui-react), I only see an option to display the URL.

render() {
        return <SwaggerUI url="https://petstore.swagger.io/v2/swagger.json" />;
      }

I have the json content. Is their another method to pass the json content and have it display in Swagger UI?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

According their docs, you can pass content directly using the spec props:

spec: PropTypes.object

An OpenAPI document respresented as a JavaScript object, JSON string, or YAML string for Swagger UI to display.

⚠️ Don’t use this in conjunction with url – unpredictable behavior may occur.

Example:

<SwaggerUI spec={jsonData} />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading