runnable swagger

master
Bel LaPointe 2020-07-24 23:23:50 -06:00
parent 95555f46ec
commit 55d8cf5d43
15 changed files with 556 additions and 0 deletions

61
public/swagger/index.html Normal file
View File

@ -0,0 +1,61 @@
<!-- 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: "https://petstore.swagger.io/v2/swagger.json",
url: "./swagger.yaml",
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>

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>

View File

@ -0,0 +1,50 @@
paths:
get:
tags:
- files
summary: "Fetch a file"
parameters:
- $ref: "#/components/parameters/path"
responses:
200:
content:
text/plain:
schema:
type: string
post:
tags:
- files
summary: "Provide or direct link to a file"
parameters:
- $ref: "#/components/parameters/path"
- $ref: "#/components/parameters/direct"
requestBody:
description: "If ?direct=true, then a direct link to the file, else a multi-part form"
content:
text/plain:
schema:
type: string
example: "http://imgur.com/img/mine.png"
application/x-www-form-urlencoded:
schema:
type: string
example: "password=123"
responses:
200:
$ref: "#/components/schemas/ok"
components:
parameters:
path:
$ref: "./swagger.yaml#/components/parameters/path"
direct:
name: direct
in: query
schema:
type: bool
schemas:
ok:
$ref: "./swagger.yaml#/components/schemas/ok"

View File

@ -0,0 +1,27 @@
paths:
post:
tags:
- register
summary: "Register a new namespace"
parameters:
- $ref: "#/components/parameters/namespace"
requestBody:
description: "A url-form-encoded password for the namespace"
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
password:
type: string
responses:
200:
$ref: "#/components/schemas/ok"
components:
parameters:
namespace:
$ref: "./swagger.yaml#/components/parameters/namespace"
schemas:
ok:
$ref: "./swagger.yaml#/components/schemas/ok"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,174 @@
paths:
get:
tags:
- who
summary: "Get an entity"
parameters:
- $ref: "#/components/parameters/id"
- $ref: "#/components/parameters/namespace"
- $ref: "#/components/parameters/light"
responses:
200:
$ref: "#/components/schemas/200"
trace:
tags:
- who
summary: "List all entities"
parameters:
- $ref: "#/components/parameters/namespace"
- $ref: "#/components/parameters/sort"
- $ref: "#/components/parameters/order"
responses:
200:
content:
application/json:
schema:
title: "Results"
type: array
items:
type: string
post:
tags:
- who
summary: "Create a new entity"
parameters:
- $ref: "#/components/parameters/id"
- $ref: "#/components/parameters/namespace"
requestBody:
description: "An entity where all fields are optional and modified is disallowed"
content:
application/json:
schema:
$ref: "#/components/schemas/one"
responses:
200:
$ref: "#/components/schemas/200"
put:
tags:
- who
summary: "Update an existing entity"
parameters:
- $ref: "#/components/parameters/id"
- $ref: "#/components/parameters/namespace"
requestBody:
description: "An entity where all fields are optional and modified is disallowed"
content:
application/json:
schema:
$ref: "#/components/schemas/one"
responses:
200:
$ref: "#/components/schemas/200"
patch:
tags:
- who
summary: "Connect the entity identified by ?id to the supplied new entity"
parameters:
- $ref: "#/components/parameters/id"
- $ref: "#/components/parameters/namespace"
requestBody:
description: "An entity where all fields are optional and modified is disallowed"
content:
application/json:
schema:
$ref: "#/components/schemas/one"
responses:
200:
$ref: "#/components/schemas/200"
delete:
tags:
- who
summary: "Delete the specified entity, which is assumed to be a leaf"
parameters:
- $ref: "#/components/parameters/id"
- $ref: "#/components/parameters/namespace"
responses:
200:
$ref: "#/components/schemas/ok"
components:
parameters:
id:
name: id
in: query
required: true
description: "An entity's unique name"
schema:
type: string
namespace:
$ref: "./swagger.yaml#/components/parameters/namespace"
light:
name: light
in: query
description: "A lighter response body"
schema:
type: string
order:
name: order
in: query
description: "-1 for descending, the default, or 1 for ascending"
schema:
type: int
sort:
name: sort
in: query
description: "A field to sort entites by, defaults to `modified`"
schema:
type: string
one:
name: one
in: body
description: "An entire entity definition"
schema:
$ref: "#/components/schemas/one"
schemas:
one:
title: "One entity"
type: object
properties:
name:
type: string
example: "Jeff Snow"
type:
type: string
example: "doggo"
title:
type: string
example: "Meme Lord"
text:
type: string
example: "Lorem ipsum"
relationship:
type: string
example: "Good boi"
modified:
type: int
example: 8675309
attachments:
type: object
additionalProperties:
type: string
connections:
type: object
additionalProperties:
type: object
200:
content:
application/json:
schema:
$ref: "#/components/schemas/one"
ok:
$ref: "./swagger.yaml#/components/schemas/ok"

View File

@ -0,0 +1,44 @@
openapi: 3.0.2
info:
title: DnDex
description: "DnD indexing, pronounced dee-en-dex. UI via http://ui.dndex.lan:8080/, API via http://api.dndex.lan:8080/"
version: 0.0.1
servers:
- url: http://api.dndex.lan:8080/
paths:
/who:
$ref: "./swagger-who.yaml#/paths"
/register:
$ref: "./swagger-register.yaml#/paths"
/__files__/{path}:
$ref: "./swagger-files.yaml#/paths"
components:
parameters:
namespace:
name: namespace
in: query
required: true
description: "An authorized universe"
schema:
type: string
path:
name: path
in: path
required: true
schema:
type: string
schemas:
ok:
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: "ok"

View File

@ -77,6 +77,7 @@ func filesPostFromDirectLink(w http.ResponseWriter, r *http.Request) error {
return err
}
defer f.Close()
// TODO max bytes reader
_, err = io.Copy(f, resp.Body)
return err
}