How to embed Swagger UI into a webpage?

前端 未结 1 1560
星月不相逢
星月不相逢 2020-12-05 07:24

How to embed Swagger UI into a webpage? Basically I want an API endpoint test environment to embed into my webpage.

1条回答
  •  攒了一身酷
    2020-12-05 08:10

    The answer depends on whether you have a plain web page you edit directly, or use a framework like Node.js or React. For simplicity, I'll assume the former.

    Download (or clone) the Swagger UI repository. You'll need the following files from the dist folder:

    swagger-ui.css
    swagger-ui-bundle.js
    swagger-ui-standalone-preset.js
    

    In the section of your web page, add:

    
    

    Inside the , add:

    is the DOM node inside which Swagger UI will be rendered. The SwaggerUIBundle constructor initializes Swagger UI. This is where you specify your spec URL and other parameters.

    0 讨论(0)
提交回复
热议问题