Skip to content

Commit

Permalink
Add documentation of the API using tspec
Browse files Browse the repository at this point in the history
  • Loading branch information
danial303065 committed Aug 20, 2024
1 parent 95ccfec commit 3282106
Show file tree
Hide file tree
Showing 29 changed files with 4,518 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/relay/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ typechain-types
cache
artifacts

generate/*
1 change: 1 addition & 0 deletions packages/relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"ts-node": "^10.5.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"tspec": "^0.1.116",
"typechain": "^8.1.0",
"typescript": "^4.5.5",
"urijs": "^1.19.7",
Expand Down
22 changes: 11 additions & 11 deletions packages/relay/src/DefaultServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ export class DefaultServer extends WebService {
})
);

this.defaultRouter.registerRoutes();
this.ledgerRouter.registerRoutes();
this.shopRouter.registerRoutes();
this.paymentRouter.registerRoutes();
this.etcRouter.registerRoutes();
this.purchaseRouter.registerRoutes();
this.tokenRouter.registerRoutes();
this.phoneLinkRouter.registerRoutes();
this.providerRouter.registerRoutes();
this.bridgeRouter.registerRoutes();
this.historyRouter.registerRoutes();
await this.defaultRouter.registerRoutes();
await this.ledgerRouter.registerRoutes();
await this.shopRouter.registerRoutes();
await this.paymentRouter.registerRoutes();
await this.etcRouter.registerRoutes();
await this.purchaseRouter.registerRoutes();
await this.tokenRouter.registerRoutes();
await this.phoneLinkRouter.registerRoutes();
await this.providerRouter.registerRoutes();
await this.bridgeRouter.registerRoutes();
await this.historyRouter.registerRoutes();

for (const m of this.schedules) await m.start();

Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/BridgeRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class BridgeRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.post(
"/v1/bridge/withdraw",
[
Expand Down
5 changes: 4 additions & 1 deletion packages/relay/src/routers/DefaultRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ContractManager } from "../contract/ContractManager";
import { Metrics } from "../metrics/Metrics";
import { WebService } from "../service/WebService";

import { Tspec, TspecDocsMiddleware } from "tspec";

import { BigNumber, Wallet } from "ethers";
import express from "express";

Expand All @@ -23,11 +25,12 @@ export class DefaultRouter {
return this.web_service.app;
}

public registerRoutes() {
public async registerRoutes() {
// Get Health Status
this.app.get("/", [], this.getHealthStatus.bind(this));
this.app.post("/callback", [], this.callback.bind(this));
this.app.get("/metrics", [], this.getMetrics.bind(this));
this.app.use("/docs", await TspecDocsMiddleware());
}

private async getHealthStatus(req: express.Request, res: express.Response) {
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/ETCRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ETCRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
// 포인트의 종류를 선택하는 기능
this.app.post(
"/v1/mobile/register",
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/HistoryRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class HistoryRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.get(
"/v1/token/main/history/:account",
[
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/LedgerRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class LedgerRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.get(
"/v1/ledger/nonce/:account",
[param("account").exists().trim().isEthereumAddress()],
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/PaymentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class PaymentRouter {
return this.web_service.app;
}

public registerRoutes() {
public async registerRoutes() {
this.app.get(
"/v1/payment/user/balance",
[query("account").exists().trim().isEthereumAddress()],
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/PhoneLinkRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class PhoneLinkRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.get(
"/v1/link/nonce/:account",
[param("account").exists().trim().isEthereumAddress()],
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/ProviderRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ProviderRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.post(
"/v1/provider/register",
[
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/ShopRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class ShopRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.get(
"/v1/shop/nonce/:account",
[param("account").exists().trim().isEthereumAddress()],
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/StorePurchaseRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class StorePurchaseRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.post(
"/v1/purchase/save",
[
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/routers/TokenRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class TokenRouter {
};
}

public registerRoutes() {
public async registerRoutes() {
this.app.get(
"/v1/token/main/balance/:account",
[param("account").exists().trim().isEthereumAddress()],
Expand Down
13 changes: 13 additions & 0 deletions packages/relay/tspec.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"specPathGlobs": ["tspec/**/*.ts"],
"tsconfigPath": "./tsconfig.json",
"outputPath": "./generate/openapi.json",
"specVersion": 3,
"openapi": {
"title": "Decentralized Loyalty System API",
"version": "1.0.0",
"description": "API of Decentralized Loyalty System</br></br><strong>The amount of tokens and points</strong></br>The amount of tokens and points is a string. The decimal place is 18. One point is expressed as \"100000000000000000000\".</br></br><strong>Responses</strong></br>Response data consists of three parts: `code`, `data`, `error`.</br>The value of code is 0 if normal. In this case, the value of data exists.</br>If an error occurs during the processing, the value of code is not zero. At this time, you can check the contents of error to find the cause."
},
"debug": false,
"ignoreErrors": true
}
Loading

0 comments on commit 3282106

Please sign in to comment.