Browse Source

Put the swagger UI right in the public directory instead of as a node_module so that it deploys correctly.

pull/26/head
Zed A. Shaw 2 months ago
parent
commit
018ce870c1
19 changed files with 418 additions and 9 deletions
  1. +0
    -6
      package-lock.json
  2. +0
    -1
      package.json
  3. +22
    -0
      public/swagger/README.md
  4. +14
    -0
      public/swagger/absolute-path.js
  5. BIN
      public/swagger/favicon-16x16.png
  6. BIN
      public/swagger/favicon-32x32.png
  7. +60
    -0
      public/swagger/index.html
  8. +17
    -0
      public/swagger/index.js
  9. +68
    -0
      public/swagger/oauth2-redirect.html
  10. +72
    -0
      public/swagger/package.json
  11. +126
    -0
      public/swagger/swagger-ui-bundle.js
  12. +1
    -0
      public/swagger/swagger-ui-bundle.js.map
  13. +22
    -0
      public/swagger/swagger-ui-standalone-preset.js
  14. +1
    -0
      public/swagger/swagger-ui-standalone-preset.js.map
  15. +4
    -0
      public/swagger/swagger-ui.css
  16. +1
    -0
      public/swagger/swagger-ui.css.map
  17. +9
    -0
      public/swagger/swagger-ui.js
  18. +1
    -0
      public/swagger/swagger-ui.js.map
  19. +0
    -2
      src/server.js

+ 0
- 6
package-lock.json View File

@@ -16166,12 +16166,6 @@
"integrity": "sha512-LCwv4i+lidORxgzImOVdAHA0xrSK0x6Ej8tIJXAsd8w+Gfheij6d6J/K4Wz8UXURF7LdRD6N3TsZa8jXw3oCfA==",
"dev": true
},
"swagger-ui-dist": {
"version": "3.26.0",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.26.0.tgz",
"integrity": "sha512-z58RlRUk//dTg6jwgFBVv0JNyfDpoRNUgEyoA9cRheNvUuklMTKMY3hgDfXSZpmnGgZEG8iA/SAZGE56hvRuug==",
"dev": true
},
"symbol-tree": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",

+ 0
- 1
package.json View File

@@ -90,7 +90,6 @@
"svelte": "^3.20.1",
"svelte-preprocess": "^3.5.0",
"swagger-editor-dist": "^3.11.1",
"swagger-ui-dist": "^3.26.0",
"wait-on": "^5.0.0",
"watch": "^1.0.2",
"webtorrent": "^0.108.1",

+ 22
- 0
public/swagger/README.md View File

@@ -0,0 +1,22 @@
# Swagger UI Dist
[![NPM version](https://badge.fury.io/js/swagger-ui-dist.svg)](http://badge.fury.io/js/swagger-ui-dist)

# API

This module, `swagger-ui-dist`, exposes Swagger-UI's entire dist folder as a dependency-free npm module.
Use `swagger-ui` instead, if you'd like to have npm install dependencies for you.

`SwaggerUIBundle` and `SwaggerUIStandalonePreset` can be imported:
```javascript
import { SwaggerUIBundle, SwaggerUIStandalonePreset } from "swagger-ui-dist"
```

To get an absolute path to this directory for static file serving, use the exported `getAbsoluteFSPath` method:

```javascript
const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath()

// then instantiate server that serves files from the swaggerUiAssetPath
```

For anything else, check the [Swagger-UI](https://github.com/swagger-api/swagger-ui) repository.

+ 14
- 0
public/swagger/absolute-path.js View File

@@ -0,0 +1,14 @@
/*
* getAbsoluteFSPath
* @return {string} When run in NodeJS env, returns the absolute path to the current directory
* When run outside of NodeJS, will return an error message
*/
const getAbsoluteFSPath = function () {
// detect whether we are running in a browser or nodejs
if (typeof module !== "undefined" && module.exports) {
return require("path").resolve(__dirname)
}
throw new Error('getAbsoluteFSPath can only be called within a Nodejs environment');
}

module.exports = getAbsoluteFSPath

BIN
public/swagger/favicon-16x16.png View File

Before After
Width: 16  |  Height: 16  |  Size: 665B

BIN
public/swagger/favicon-32x32.png View File

Before After
Width: 32  |  Height: 32  |  Size: 628B

+ 60
- 0
public/swagger/index.html View File

@@ -0,0 +1,60 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after
{
box-sizing: inherit;
}

body
{
margin:0;
background: #fafafa;
}
</style>
</head>

<body>
<div id="swagger-ui"></div>

<script src="./swagger-ui-bundle.js"> </script>
<script src="./swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "/openapi.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region

window.ui = ui
}
</script>
</body>
</html>

+ 17
- 0
public/swagger/index.js View File

@@ -0,0 +1,17 @@
try {
module.exports.SwaggerUIBundle = require("./swagger-ui-bundle.js")
module.exports.SwaggerUIStandalonePreset = require("./swagger-ui-standalone-preset.js")
} catch(e) {
// swallow the error if there's a problem loading the assets.
// allows this module to support providing the assets for browserish contexts,
// without exploding in a Node context.
//
// see https://github.com/swagger-api/swagger-ui/issues/3291#issuecomment-311195388
// for more information.
}

// `absolutePath` and `getAbsoluteFSPath` are both here because at one point,
// we documented having one and actually implemented the other.
// They were both retained so we don't break anyone's code.
module.exports.absolutePath = require("./absolute-path.js")
module.exports.getAbsoluteFSPath = require("./absolute-path.js")

+ 68
- 0
public/swagger/oauth2-redirect.html View File

@@ -0,0 +1,68 @@
<!doctype html>
<html lang="en-US">
<title>Swagger UI: OAuth2 Redirect</title>
<body onload="run()">
</body>
</html>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;

if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}

arr = qp.split("&")
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value)
}
) : {}

isValid = qp.state === sentState

if ((
oauth2.auth.schema.get("flow") === "accessCode"||
oauth2.auth.schema.get("flow") === "authorizationCode"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
});
}

if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}

oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
</script>

+ 72
- 0
public/swagger/package.json View File

@@ -0,0 +1,72 @@
{
"_from": "swagger-ui-dist",
"_id": "swagger-ui-dist@3.26.0",
"_inBundle": false,
"_integrity": "sha512-z58RlRUk//dTg6jwgFBVv0JNyfDpoRNUgEyoA9cRheNvUuklMTKMY3hgDfXSZpmnGgZEG8iA/SAZGE56hvRuug==",
"_location": "/swagger-ui-dist",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "swagger-ui-dist",
"name": "swagger-ui-dist",
"escapedName": "swagger-ui-dist",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#DEV:/",
"#USER"
],
"_resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.26.0.tgz",
"_shasum": "6dccd492bf9c97fe508d8438c754991277a6164f",
"_spec": "swagger-ui-dist",
"_where": "/Users/zedshaw/Projects/learnjsthehardway",
"bugs": {
"url": "https://github.com/swagger-api/swagger-ui/issues"
},
"bundleDependencies": false,
"contributors": [
{
"url": "in alphabetical order"
},
{
"name": "Anna Bodnia",
"email": "anna.bodnia@gmail.com"
},
{
"name": "Buu Nguyen",
"email": "buunguyen@gmail.com"
},
{
"name": "Josh Ponelat",
"email": "jponelat@gmail.com"
},
{
"name": "Kyle Shockey",
"email": "kyleshockey1@gmail.com"
},
{
"name": "Robert Barnwell",
"email": "robert@robertismy.name"
},
{
"name": "Sahar Jafari",
"email": "shr.jafari@gmail.com"
}
],
"dependencies": {},
"deprecated": false,
"description": "[![NPM version](https://badge.fury.io/js/swagger-ui-dist.svg)](http://badge.fury.io/js/swagger-ui-dist)",
"devDependencies": {},
"homepage": "https://github.com/swagger-api/swagger-ui#readme",
"license": "Apache-2.0",
"main": "index.js",
"name": "swagger-ui-dist",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/swagger-api/swagger-ui.git"
},
"version": "3.26.0"
}

+ 126
- 0
public/swagger/swagger-ui-bundle.js
File diff suppressed because it is too large
View File


+ 1
- 0
public/swagger/swagger-ui-bundle.js.map
File diff suppressed because it is too large
View File


+ 22
- 0
public/swagger/swagger-ui-standalone-preset.js
File diff suppressed because it is too large
View File


+ 1
- 0
public/swagger/swagger-ui-standalone-preset.js.map
File diff suppressed because it is too large
View File


+ 4
- 0
public/swagger/swagger-ui.css
File diff suppressed because it is too large
View File


+ 1
- 0
public/swagger/swagger-ui.css.map
File diff suppressed because it is too large
View File


+ 9
- 0
public/swagger/swagger-ui.js
File diff suppressed because it is too large
View File


+ 1
- 0
public/swagger/swagger-ui.js.map
File diff suppressed because it is too large
View File


+ 0
- 2
src/server.js View File

@@ -34,8 +34,6 @@ app.use(cookieSession({

if(dev) {
app.use('/swagger/', sirv('node_modules/swagger-editor-dist'));
} else {
app.use('/swagger/', sirv('node_modules/swagger-ui-dist'));
}

app.use(

Loading…
Cancel
Save