Skip to content

Instantly share code, notes, and snippets.

@kmahyyg
Last active April 21, 2021 07:20
Show Gist options
  • Select an option

  • Save kmahyyg/168cab6a3324507a0c4fce03003dbf8e to your computer and use it in GitHub Desktop.

Select an option

Save kmahyyg/168cab6a3324507a0c4fce03003dbf8e to your computer and use it in GitHub Desktop.
swagger-temp1
{
"swagger": "2.0",
"info": {
"title": "PoET YNU Trace - YYG",
"description": "PoET YNU Trace - YYG",
"version": "0.1.0"
},
"host": "localhost:18088",
"schemes": [
"http"
],
"basePath": "/api",
"securityDefinitions": {
"jwt_auth": {
"type": "apiKey",
"name": "jwt_auth",
"description": "Authorization: Bearer TOKEN",
"in": "header"
}
},
"tags": [
{
"name": "agent",
"description": "user related"
},
{
"name": "auth",
"description": "web authentication"
},
{
"name": "asset",
"description": "asset trace related"
},
{
"name": "blockchains",
"description": "blockchians check (low level)"
}
],
"paths": {
"/user/create": {
"post": {
"tags": [
"agent"
],
"summary": "add a new user",
"description": "For init, use action==initNewUser, and also make sure `$(CWD)/.inited-user.json` is not exists, the init will not ask you for authentication. After that, the create API call will verify your identity and must be roleId==1 as admin.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "reqBody",
"schema": {
"type": "object",
"properties": {
"action": {
"type": "string",
"description": "create a new user, the first user will automatically be admin. Allowed values: initNewUser/CreateNewUser. Default Password: 1qaz@WRX3fsc"
},
"password": {
"type": "string",
"description": "New Users' password. Default is: 1qaz@WRX3fsc"
}
}
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/AgentResp"
}
},
"401": {
"description": "Invalid request, only for initNewUser, which means already inited."
},
"403": {
"description": "Authorization Denied"
}
},
"security": [
{
"jwt_auth": []
}
]
}
},
"/user/roles": {
"get": {
"tags": [
"agent"
],
"summary": "Get all roles with its ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"security": [
{
"jwt_auth": []
}
],
"responses": {
"200": {
"description": "Ok",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Role"
}
}
},
"403": {
"description": "Authorization Denied"
}
}
}
},
"/user/{username}/detail": {
"get": {
"tags": [
"agent"
],
"summary": "get user detailed information",
"security": [
{
"jwt_auth": []
}
],
"parameters": [
{
"in": "path",
"name": "username",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "User details",
"schema": {
"$ref": "#/definitions/AgentResp"
}
},
"403": {
"description": "Authorization Denied"
}
}
},
"delete": {
"tags": [
"agent"
],
"summary": "delete current user",
"security": [
{
"jwt_auth": []
}
],
"parameters": [
{
"in": "path",
"name": "username",
"type": "string",
"required": true,
"description": "the user to be deleted, must be admin if you want to delete another not logged-in user"
}
],
"responses": {
"204": {
"description": "User successfully deleted.",
"schema": {
"$ref": "#/definitions/PublicResp"
}
},
"403": {
"description": "Authorization Denied"
}
}
},
"post": {
"tags": [
"agent"
],
"security": [
{
"jwt_auth": []
}
],
"summary": "update current agent",
"parameters": [
{
"in": "path",
"name": "username",
"type": "string",
"required": true
},
{
"in": "body",
"name": "reqBody",
"schema": {
"$ref": "#/definitions/Agent"
}
}
],
"responses": {
"200": {
"description": "successfully updated user details"
},
"403": {
"description": "Authorization Denied"
},
"500": {
"description": "Internal Error occurred"
}
}
}
},
"/user/auth": {
"post": {
"tags": [
"auth"
],
"summary": "login token create",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "formData",
"name": "username",
"type": "string",
"description": "username"
},
{
"in": "formData",
"name": "password",
"type": "string",
"description": "User password"
}
],
"responses": {
"200": {
"description": "authenticate success",
"schema": {
"$ref": "#/definitions/AuthResp"
}
},
"401": {
"description": "other client-side reason errors"
},
"403": {
"description": "password or username incorrect"
}
}
}
},
"/user/logout": {
"get": {
"tags": [
"auth"
],
"summary": "logout current user",
"security": [
{
"jwt_auth": []
}
],
"responses": {
"200": {
"description": "logout authentication succeeded"
},
"401": {
"description": "logout error"
}
}
}
},
"/user/lists": {
"get": {
"tags": [
"agent"
],
"security": [
{
"jwt_auth": []
}
],
"summary": "List all users in the system",
"responses": {
"200": {
"description": "all users list",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Agent"
}
}
},
"403": {
"description": "access denied"
}
}
}
},
"/user/{username}/reset": {
"post": {
"tags": [
"auth"
],
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "path",
"name": "username",
"required": true,
"type": "string"
},
{
"in": "formData",
"name": "privateKey",
"required": true,
"type": "string",
"description": "As the evidence that you are the account owner"
},
{
"in": "formData",
"name": "newPassword",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "account reset succeeded.",
"schema": {
"$ref": "#/definitions/AgentResp"
}
},
"401": {
"description": "either information is not correct."
}
}
}
},
"/blockchains/txn/{txnid}": {
"get": {
"tags": [
"blockchains"
],
"security": [
{
"jwt_auth": []
}
],
"summary": "get specific txn details",
"parameters": [
{
"in": "path",
"name": "txnid",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "forwarded to consensus engine and get result directly"
},
"401": {
"description": "txn id invalid"
},
"403": {
"description": "access denied"
}
}
}
},
"/blockchains/blk/id/{blkid}": {
"get": {
"tags": [
"blockchains"
],
"security": [
{
"jwt_auth": []
}
],
"summary": "get specific block details by id",
"parameters": [
{
"in": "path",
"name": "blkid",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "block details directly from consensus engine response"
},
"401": {
"description": "blkid invalid"
},
"403": {
"description": "access denied"
}
}
}
},
"/blockchains/blk/h/{blknum}": {
"get": {
"tags": [
"blockchains"
],
"security": [
{
"jwt_auth": []
}
],
"parameters": [
{
"in": "path",
"name": "blknum",
"type": "integer",
"format": "int32",
"required": true
}
],
"summary": "Get blocks at current height number",
"responses": {
"200": {
"description": "block IDs from reporting database, not blockchain! As Public Response with msg filled with the array of block IDs.",
"schema": {
"$ref": "#/definitions/PublicResp"
}
},
"401": {
"description": "block num not found or illegal request."
},
"403": {
"description": "access denied"
}
}
}
},
"/assets/list": {
"get": {
"summary": "show all assets",
"security": [
{
"jwt_auth": []
}
],
"parameters": [
{
"in": "query",
"name": "name",
"type": "string",
"required": false,
"description": "asset name as a filter"
}
],
"tags": [
"assets"
],
"responses": {
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/AssetResp"
}
},
"403": {
"description": "access denied"
}
}
}
},
"/assets/create": {
"post": {
"summary": "create new assets",
"security": [
{
"jwt_auth": []
}
],
"parameters": [
{
"in": "body",
"name": "reqBody",
"required": true,
"schema": {
"$ref": "#/definitions/Asset"
}
}
],
"tags": [
"assets"
],
"responses": {
"200": {
"description": "message string as txn id",
"schema": {
"$ref": "#/definitions/PublicResp"
}
},
"401": {
"description": "Invalid request"
},
"403": {
"description": "access denied"
}
}
}
},
"/assets/{asset_nanoid}/details": {
"get": {
"tags": [
"assets"
],
"security": [
{
"jwt_auth": []
}
],
"summary": "get details about an asset, if authed, all attributes shown. Else, only part of data.",
"parameters": [
{
"in": "path",
"name": "asset_nanoid",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "asset details",
"schema": {
"$ref": "#/definitions/AssetResp"
}
},
"401": {
"description": "invalid request"
},
"403": {
"description": "access denied"
}
}
},
"post": {
"tags": [
"assets"
],
"summary": "update current status of assets",
"security": [
{
"jwt_auth": []
}
],
"parameters": [
{
"in": "path",
"name": "asset_nanoid",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "reqBody",
"required": true,
"schema": {
"$ref": "#/definitions/Asset"
}
}
],
"responses": {
"200": {
"description": "ok, message string as txn id ",
"schema": {
"$ref": "#/definitions/PublicResp"
}
},
"401": {
"description": "invalid request"
},
"403": {
"description": "access denied"
},
"500": {
"description": "server internal error"
}
}
},
"delete": {
"tags": [
"assets"
],
"summary": "delete corresponding asset",
"description": "only currentAgent linked to the asset can do this operation",
"security": [
{
"jwt_auth": []
}
],
"parameters": [
{
"in": "path",
"name": "asset_nanoid",
"type": "string",
"required": true
}
],
"responses": {
"200": {
"description": "ok",
"schema": {
"$ref": "#/definitions/PublicResp"
}
},
"401": {
"description": "invalid request"
},
"403": {
"description": "access denied"
},
"500": {
"description": "server internal error"
}
}
}
},
"/assets/{year}/{asset_nanoid}/traces": {
"get": {
"tags": [
"assets"
],
"summary": "get corresponding nanoid trace detailed data",
"parameters": [
{
"in": "path",
"name": "asset_nanoid",
"type": "string",
"required": true
},
{
"in": "path",
"name": "year",
"type": "integer",
"format": "int32",
"required": true
}
],
"responses": {
"200": {
"description": "okay",
"schema": {
"$ref": "#/definitions/AssetResp"
}
},
"404": {
"description": "item not found"
},
"500": {
"description": "internal server error"
}
}
}
}
},
"definitions": {
"PublicResp": {
"type": "object",
"properties": {
"status": {
"type": "integer",
"format": "int32"
},
"msg": {
"type": "integer",
"format": "string"
}
}
},
"RoleResp": {
"type": "object",
"properties": {
"publicResp": {
"$ref": "#/definitions/PublicResp"
},
"roleDetails": {
"$ref": "#/definitions/Role"
}
}
},
"Role": {
"type": "object",
"properties": {
"roleName": {
"type": "string",
"format": "string"
},
"roleId": {
"type": "integer",
"format": "int32",
"description": "Implemented RBAC, Role ID marks everything, rolePerm is assessed in backend"
}
}
},
"AgentResp": {
"type": "object",
"properties": {
"publicResponse": {
"$ref": "#/definitions/PublicResp"
},
"userDetail": {
"$ref": "#/definitions/Agent"
}
}
},
"Agent": {
"type": "object",
"properties": {
"username": {
"type": "string",
"format": "string"
},
"privateKey": {
"type": "string",
"format": "string",
"description": "The Private Key will only show once at creation time, other time will be empty."
},
"publicKey": {
"type": "string",
"format": "string"
},
"roleId": {
"type": "integer",
"format": "int32"
}
}
},
"AuthResp": {
"type": "object",
"properties": {
"publicResponse": {
"$ref": "#/definitions/PublicResp"
},
"token": {
"type": "string",
"format": "string"
}
}
},
"AssetResp": {
"type": "object",
"properties": {
"publicResponse": {
"$ref": "#/definitions/PublicResp"
},
"asset": {
"$ref": "#/definitions/Asset"
}
}
},
"Asset": {
"type": "object",
"properties": {
"nanoId": {
"type": "string",
"format": "string"
},
"name": {
"type": "string",
"format": "string"
},
"status": {
"type": "integer",
"format": "int32",
"description": "0=normal, -1=dropped, 1=produced, 2=transmitted, 3=post-proceeding, 4=sold"
},
"currentAgent": {
"$ref": "#/definitions/Agent"
},
"properties": {
"$ref": "#/definitions/AssetProperties"
}
}
},
"AssetProperties": {
"type": "object",
"properties": {
"nutrition": {
"type": "string",
"format": "string"
},
"process_agent": {
"type": "string",
"format": "string"
},
"process_detail": {
"type": "string",
"format": "string"
},
"effective_date": {
"type": "string",
"format": "string"
},
"weight": {
"type": "integer",
"format": "int32"
},
"internal_trackid": {
"type": "string",
"format": "string"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment