Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Swagger UI docs #939

Open
wants to merge 1 commit into
base: mainnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading