start new swagger

This commit is contained in:
breel
2020-08-09 19:03:25 -06:00
parent 02c5d795cf
commit f11261f0da
11 changed files with 275 additions and 2 deletions

View File

@@ -0,0 +1,55 @@
paths:
get:
tags:
- files
summary: "Fetch a file"
parameters:
- $ref: "#/components/parameters/path"
- $ref: "#/components/parameters/namespace"
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/namespace"
- $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"
namespace:
$ref: "./swagger.yaml#/components/parameters/namespacePath"
direct:
name: direct
in: query
schema:
type: bool
schemas:
ok:
$ref: "./swagger.yaml#/components/schemas/ok"

View File

@@ -0,0 +1,50 @@
paths:
get:
tags:
- port
summary: "Export entities from a namespace"
parameters:
- $ref: "#/components/parameters/namespace"
responses:
200:
$ref: "#/components/schemas/port"
post:
tags:
- port
summary: "Import entities into a namespace"
parameters:
- $ref: "#/components/parameters/namespace"
requestBody:
$ref: "#/components/schemas/port"
responses:
200:
content:
application/json:
schema:
type: object
properties:
namespace:
type: int
example: "5"
components:
parameters:
namespace:
$ref: "./swagger.yaml#/components/parameters/namespace"
schemas:
one:
$ref: "./swagger.yaml#/components/schemas/one"
port:
description: "A {namespace:[entity]} json object"
content:
application/json:
schema:
type: object
properties:
namespace:
type: array
items:
$ref: "#/components/schemas/one"

View File

@@ -0,0 +1,36 @@
paths:
post:
tags:
- register
summary: "Register a new namespace"
parameters:
- $ref: "#/components/parameters/namespace"
- $ref: "#/components/parameters/public"
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"
public:
name: public
in: query
description: "if not empty, then namespace is accessible without auth"
schema:
type: string
schemas:
ok:
$ref: "./swagger.yaml#/components/schemas/ok"

View File

@@ -0,0 +1,163 @@
paths:
get:
tags:
- who
summary: "Get an entity. If ?id not provided, see TRACE. ?sort and ?order apply to connections."
parameters:
- $ref: "#/components/parameters/id"
- $ref: "#/components/parameters/namespace"
- $ref: "#/components/parameters/light"
- $ref: "#/components/parameters/md"
- $ref: "#/components/parameters/sort"
- $ref: "#/components/parameters/order"
responses:
200:
$ref: "#/components/schemas/200"
trace:
deprecated: true
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:
$ref: "#/components/schemas/oneContent"
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. Modifying sub-documents is possible via dot notation."
content:
$ref: "#/components/schemas/oneContent"
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:
$ref: "#/components/schemas/oneContent"
responses:
200:
$ref: "#/components/schemas/200"
delete:
tags:
- who
summary: "Delete the specified entity, which is assumed to be a leaf, or only its connection if specified"
parameters:
- $ref: "#/components/parameters/id"
- $ref: "#/components/parameters/namespace"
- $ref: "#/components/parameters/connection"
responses:
200:
$ref: "#/components/schemas/ok"
components:
parameters:
id:
name: id
in: query
description: "An entity's unique name, case insensitive for reads"
schema:
type: string
namespace:
$ref: "./swagger.yaml#/components/parameters/namespace"
connection:
name: connection
in: query
description: "An entity's connection's name"
schema:
type: string
light:
name: light
in: query
description: "A lighter response body"
schema:
type: string
md:
name: md
in: query
description: "Include a html rendered markdown notes section as .md"
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:
oneContent:
application/json:
schema:
$ref: "#/components/schemas/one"
one:
$ref: "./swagger.yaml#/components/schemas/one"
200:
content:
application/json:
schema:
$ref: "#/components/schemas/one"
ok:
$ref: "./swagger.yaml#/components/schemas/ok"

View File

@@ -0,0 +1,174 @@
openapi: 3.0.2
info:
title: DnDex
description: |
DnD indexing, pronounced dee-in-dex
UI via http://ui.dndex.lan:8080/, API via http://api.dndex.lan:8080/
Sources
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject">OpenAPI</a>
* <a href="http://api.dndex.lan:8080/__files__/swagger/swagger.html#/">Swagger UI</a>
version: 0.0.2
servers:
- url: http://api.dndex.lan:8080/
- url: http://authapi.dndex.lan:8080/
paths:
/who:
$ref: "./swagger-who.yaml#/paths"
/register:
$ref: "./swagger-register.yaml#/paths"
/port:
$ref: "./swagger-port.yaml#/paths"
/__files__/{namespace}/{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
namespacePath:
name: namespace
in: path
required: true
schema:
type: string
schemas:
ok:
content:
application/json:
properties:
status:
type: string
example: "ok"
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
securitySchemes:
token:
type: apiKey
description: |
Disabled by default but required by all endpoints when enabled
Provided as AES-GCM 12-byte-padded ciphertext on all unauthorized requests via the header "Set-Cookie:New-DnDex-Auth=encode-token"
<details>
<summary>
[Code example of decrypting a token in Javascript](https://notes-server.remote.blapointe.com/notes/disciplines/tech/languages/Encryption.md#toc_1)
</summary>
```javascript
class NewAuthToken {
constructor(key) {
if (!key) {
throw "invalid key"
}
this.key = key.repeat(32).substr(0, 32)
}
decode(b64, callback) {
var ciphertext = this.base64_decode(b64)
var iv = ciphertext.substr(0, 12)
var encrypted = ciphertext.substr(iv.length, ciphertext.length-iv.length)
this.get_crypto_key()
.then(function(crypto_key) {
NewAuthToken.decrypt(crypto_key, iv, encrypted, callback)
})
}
base64_decode(b64) {
return atob(b64)
}
static to_buffer(s) {
var bytes = new Uint8Array(s.length)
for (var i = 0; i < s.length; i++) {
bytes[i] = s.charCodeAt(i)
}
return bytes.buffer
}
static decrypt(crypto_key, iv, encrypted, callback) {
window.crypto.subtle.decrypt(
{name: "AES-GCM", iv: NewAuthToken.to_buffer(iv)},
crypto_key,
NewAuthToken.to_buffer(encrypted),
)
.then(function(decrypted) {
callback(String.fromCharCode.apply(null, new Uint8Array(decrypted)))
})
}
get_crypto_key() {
return crypto.subtle.importKey(
"raw",
NewAuthToken.to_buffer(this.key),
"AES-GCM",
false,
["decrypt"]
)
}
set_token(encoded_token) {
this.decode(encoded_token, function (token) {
console.log("Set-Cookie DnDex-Auth="+token)
document.cookie = "DnDex-Auth=" + token + ";path=/"
})
}
}
authtoken = new NewAuthToken("123").set_token("SOY05yF/9iv3YG71sKkQPVaEwO53PCX8qZhDHS9JUohBgVl5Qr9/GTKK/TJ6OozhHN7QBIGmHNzQxTRRSLs4Lw==")
```
</details>
name: DnDex-Auth
in: cookie
security:
- {}
- token: []