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:
Download Swagger UI (link to the latest master).
Go to the
dist
folder.Edit
index.html
as follows:Delete
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
and paste the contents of theswagger-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 fromswagger-ui-bundle.js
andswagger-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.