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?
Asked
Active
Viewed 2,623 times
3
-
'Single HTML with the "try out" button' is Swagger UI. How exactly does it not work for you? – Helen Aug 08 '17 at 12:15
-
I need a single html what I can use as an attachment :) – Béla Olcsán Aug 08 '17 at 12:27
-
Uhm... zip Swagger UI? It's 1 HTML + 1 CSS + 2 .js + your spec. – Helen Aug 08 '17 at 13:20
-
Nope.. that is not an option.. I need one big messy html ^_^ – Béla Olcsán Aug 08 '17 at 13:23
1 Answers
9
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
distfolder.Edit
index.htmlas follows:Delete
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >and paste the contents of theswagger-ui.cssfile 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.jsandswagger-ui-standalone-preset.js.Replace
url: "http://petstore.swagger.io/v2/swagger.json",with the
specparameter 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.
Helen
- 87,344
- 17
- 243
- 314
-
Nowadays, the initialization of `SwaggerUIBundle` (with "url") is in "swagger-initializer.js", so you need to copy in that one too. Otherwise, the instructions still work. – Christian Davén Nov 07 '22 at 09:50