Swagger single interactive html [closed]

。_饼干妹妹 提交于 2020-01-13 19:26:10

问题


I'm trying to make a single html with the try out button. The swagger-code gen nor the swagger-ui gives me that result. Do you have any suggestion?


回答1:


You can try changing Swagger UI into "one big messy HTML file" as follows:

  1. Download Swagger UI (link to the latest master).

  2. Go to the dist folder.

  3. Edit index.html as follows:

    • Delete <link rel="stylesheet" type="text/css" href="./swagger-ui.css" > and paste the contents of the swagger-ui.css file into the <style> element.

    • Replace

      <script src="./swagger-ui-bundle.js"> </script>
      <script src="./swagger-ui-standalone-preset.js"> </script>
      

      with a <script>...</script> element containing the code from swagger-ui-bundle.js and swagger-ui-standalone-preset.js.

    • Replace

      url: "http://petstore.swagger.io/v2/swagger.json",
      

      with the spec parameter containing your API spec in the JSON format, like so:

      spec: {
        "swagger": "2.0",
        "info": ...,
        "paths": ...
      },
      

      If your spec is YAML, convert it to JSON first, e.g. using https://www.json2yaml.com.

    • Remove the favicons: <link rel="icon" type="image/png" href="./favicon-...

Now index.html can be used as a standalone file.



来源:https://stackoverflow.com/questions/45567723/swagger-single-interactive-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!