Added more proper documentation

This commit is contained in:
2021-06-22 23:49:11 +02:00
parent ccafd60923
commit 24f897e907
6 changed files with 552 additions and 123 deletions

View File

@@ -5,7 +5,7 @@
"title": "JWT Auth API",
"contact": {
"name": "Power Plan",
"url": "https://http://pwrpln.com/",
"url": "https://pwrpln.com/",
"email": "lilleman@larvit.se"
},
"license": {
@@ -13,12 +13,11 @@
},
"version": "0.1"
},
"host": "localhost:3000",
"basePath": "/",
"paths": {
"/account": {
"post": {
"description": "Create an account",
"description": "Requires Authorization-header with role \"admin\".\nExample: Authorization: bearer xxx\nWhere \"xxx\" is a valid JWT token",
"consumes": [
"application/json"
],
@@ -27,6 +26,17 @@
],
"summary": "Create an account",
"operationId": "account-create",
"parameters": [
{
"description": "Account object to be written to database",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handlers.AccountInput"
}
}
],
"responses": {
"200": {
"description": "OK",
@@ -37,25 +47,37 @@
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
@@ -63,14 +85,14 @@
},
"/account/{id}": {
"get": {
"description": "Get account",
"description": "Requires Authorization-header with either role \"admin\" or with a matching account id.\nExample: Authorization: bearer xxx\nWhere \"xxx\" is a valid JWT token",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Get account",
"summary": "Get account by id",
"operationId": "get-account-by-id",
"parameters": [
{
@@ -91,25 +113,37 @@
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
@@ -126,35 +160,58 @@
],
"summary": "Authenticate account by API Key",
"operationId": "auth-account-by-api-key",
"parameters": [
{
"description": "API Key as a string in JSON format (just encapsulate the string with \\",
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
"$ref": "#/definitions/handlers.ResToken"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
@@ -171,35 +228,58 @@
],
"summary": "Authenticate account by Password",
"operationId": "auth-account-by-password",
"parameters": [
{
"description": "Name and password to auth by",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/handlers.AuthInput"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
"$ref": "#/definitions/handlers.ResToken"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
@@ -216,35 +296,58 @@
],
"summary": "Renew token",
"operationId": "renew-token",
"parameters": [
{
"description": "Renewal token as a string in JSON format (just encapsulate the string with \\",
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/db.Account"
"$ref": "#/definitions/handlers.ResToken"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"403": {
"description": "Forbidden",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"415": {
"description": "Unsupported Media Type",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/handlers.ResJSONError"
"type": "array",
"items": {
"$ref": "#/definitions/handlers.ResJSONError"
}
}
}
}
@@ -275,6 +378,20 @@
}
}
},
"db.AccountCreateInputFields": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"values": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"db.CreatedAccount": {
"type": "object",
"properties": {
@@ -289,6 +406,34 @@
}
}
},
"handlers.AccountInput": {
"type": "object",
"properties": {
"fields": {
"type": "array",
"items": {
"$ref": "#/definitions/db.AccountCreateInputFields"
}
},
"name": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"handlers.AuthInput": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"handlers.ResJSONError": {
"type": "object",
"properties": {
@@ -299,6 +444,17 @@
"type": "string"
}
}
},
"handlers.ResToken": {
"type": "object",
"properties": {
"jwt": {
"type": "string"
},
"renewalToken": {
"type": "string"
}
}
}
}
}