Skip to content

Commit

Permalink
add new swagger ui docs for api
Browse files Browse the repository at this point in the history
  • Loading branch information
michellewong793 committed Oct 3, 2024
1 parent 8f729e1 commit d96723e
Show file tree
Hide file tree
Showing 8 changed files with 3,626 additions and 2,408 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@
"build:sdk": "cd sdk && yarn build",
"build:create-leo-app": "cd create-leo-app && yarn build",
"build:all": "yarn build:wasm && yarn build:sdk && yarn build:create-leo-app",

"start:website": "cd website && yarn dev",

"test:wasm": "cd wasm && yarn test",
"test:sdk": "cd sdk && yarn test",
"test": "yarn test:wasm && yarn test:sdk",

"change-version": "node scripts/change-version.js",

"deploy:wasm": "cd wasm && npm publish --access=public",
"deploy:sdk": "cd sdk && npm publish --access=public",
"deploy:create-leo-app": "cd create-leo-app && npm publish --access=public",
"deploy": "yarn build:all && yarn deploy:wasm && yarn deploy:sdk && yarn deploy:create-leo-app",

"lint": "prettier . --check",
"pretty": "prettier . --write"
},
Expand All @@ -40,5 +35,9 @@
"devDependencies": {
"prettier": "3.0.3",
"wasm-pack": "^0.12.1"
},
"dependencies": {
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
}
}
177 changes: 177 additions & 0 deletions sdk/routes/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import { Router } from "express";
const router = Router();
/**
* @swagger
* tags:
* - name: Blocks
* description: Operations related to blocks
*
*/

/**
* @swagger
* /latest/block:
* get:
* tags: [Blocks]
* summary: Get latest block
* description: Retrieve latest block
* responses:
* 200:
* description: A block object
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
* 404:
* description: Program not found
* 500:
* description: Server error
*/
router.get("/latest/block", async (req, res) => {
try {
const block = await fetchData(`/latest/block`);
res.json(block);
} catch (error) {
res.status(500).json({ message: "Error fetching latest block" });
}
});

/**
* @swagger
* /latest/height:
* get:
* tags: [Blocks]
* summary: Get latest block height
* description: Retrieve latest block height
* responses:
* 200:
* description: A block height object
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
* 404:
* description: Program not found
* 500:
* description: Server error
*/
router.get("/latest/height", async (req, res) => {
try {
const block = await fetchData(`/latest/height`);
res.json(block);
} catch (error) {
res.status(500).json({ message: "Error fetching latest block height" });
}
});

/**
* @swagger
* /latest/hash:
* get:
* tags: [Blocks]
* summary: Get latest hash
* description: Retrieve latest hash
* responses:
* 200:
* description: A hash object
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
* 404:
* description: Program not found
* 500:
* description: Server error
*/

router.get("/latest/hash", async (req, res) => {
try {
const block = await fetchData(`/latest/hash`);
res.json(block);
} catch (error) {
res.status(500).json({ message: "Error fetching latest hash" });
}
});

/**
* @swagger
* /latest/stateRoot:
* get:
* tags: [Blocks]
* summary: Get latest stateroot
* description: Retrieve latest stateroot
* responses:
* 200:
* description: A stateroot object
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
* 404:
* description: Program not found
* 500:
* description: Server error
*/
router.get("/latest/stateroot", async (req, res) => {
try {
const block = await fetchData(`/latest/stateroot`);
res.json(block);
} catch (error) {
res.status(500).json({ message: "Error fetching latest stateroot" });
}
});

/**
* @swagger
* /latest/committee:
* get:
* tags: [Blocks]
* summary: Get latest committee
* description: Retrieve latest committee
* responses:
* 200:
* description: A committee object
* content:
* application/json:
* schema:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
* 404:
* description: Program not found
* 500:
* description: Server error
*/
router.get("/latest/committee", async (req, res) => {
try {
const block = await fetchData(`/latest/committee`);
res.json(block);
} catch (error) {
res.status(500).json({ message: "Error fetching latest committee" });
}
});

export default router;
Loading

0 comments on commit d96723e

Please sign in to comment.