Class: Whoosh::OpenAPI::UI
- Inherits:
-
Object
- Object
- Whoosh::OpenAPI::UI
- Defined in:
- lib/whoosh/openapi/ui.rb
Constant Summary collapse
- SWAGGER_CDN =
"https://unpkg.com/swagger-ui-dist@5"
Class Method Summary collapse
- .rack_response(spec_url) ⇒ Object
- .redoc_html(spec_url) ⇒ Object
- .redoc_response(spec_url) ⇒ Object
- .swagger_html(spec_url) ⇒ Object
Class Method Details
.rack_response(spec_url) ⇒ Object
34 35 36 37 |
# File 'lib/whoosh/openapi/ui.rb', line 34 def self.rack_response(spec_url) html = swagger_html(spec_url) [200, { "content-type" => "text/html", "content-length" => html.bytesize.to_s }, [html]] end |
.redoc_html(spec_url) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/whoosh/openapi/ui.rb', line 39 def self.redoc_html(spec_url) <<~HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>API Docs - ReDoc</title> </head> <body> <redoc spec-url="#{spec_url}"></redoc> <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script> </body> </html> HTML end |
.redoc_response(spec_url) ⇒ Object
56 57 58 59 |
# File 'lib/whoosh/openapi/ui.rb', line 56 def self.redoc_response(spec_url) html = redoc_html(spec_url) [200, { "content-type" => "text/html", "content-length" => html.bytesize.to_s }, [html]] end |
.swagger_html(spec_url) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/whoosh/openapi/ui.rb', line 8 def self.swagger_html(spec_url) <<~HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>API Docs</title> <link rel="stylesheet" href="#{SWAGGER_CDN}/swagger-ui.css"> </head> <body> <div id="swagger-ui"></div> <script src="#{SWAGGER_CDN}/swagger-ui-bundle.js"></script> <script> SwaggerUIBundle({ url: "#{spec_url}", dom_id: '#swagger-ui', presets: [SwaggerUIBundle.presets.apis], layout: "BaseLayout" }); </script> </body> </html> HTML end |