github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/internal/oapispec/swaggerui.go (about)

     1  // Copyright © 2021 Kaleido, Inc.
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package oapispec
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  )
    23  
    24  var swaggerUIHTML = `<!DOCTYPE html>
    25  <html lang="en">
    26    <head>
    27      <meta charset="UTF-8">
    28      <title>Swagger UI</title>
    29      <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
    30      <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
    31      <link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@3/swagger-ui.css">
    32  		<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
    33    </head>
    34  
    35    <body>
    36      <div id="swagger-ui"></div>
    37  
    38  		<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
    39  		<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js" charset="UTF-8"></script>
    40      <script>
    41      window.onload = function() {
    42        // Begin Swagger UI call region
    43        const ui = SwaggerUIBundle({
    44          url: "%s/api/swagger.yaml",
    45          dom_id: '#swagger-ui',
    46          deepLinking: true,
    47          presets: [
    48            SwaggerUIBundle.presets.apis,
    49            SwaggerUIStandalonePreset
    50          ],
    51          plugins: [
    52            SwaggerUIBundle.plugins.DownloadUrl
    53          ],
    54          layout: "StandaloneLayout"
    55        });
    56        // End Swagger UI call region
    57  
    58        window.ui = ui;
    59      };
    60    </script>
    61    </body>
    62  </html>
    63  `
    64  
    65  func SwaggerUIHTML(ctx context.Context) []byte {
    66  	return []byte(fmt.Sprintf(
    67  		swaggerUIHTML,
    68  		getHost(),
    69  	))
    70  }