Skip to content

Commit dc8020f

Browse files
committed
feat: add openapi and swagger for documentation
1 parent ee01882 commit dc8020f

File tree

15 files changed

+802
-20
lines changed

15 files changed

+802
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
docs/examples
22
node_modules/
33
.env
4-
*.pdf
4+
*.pdf
5+
dist/

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"dataproviders",
55
"gemini",
66
"nodenext",
7+
"openapi",
78
"predev",
89
"prestart",
910
"usecases"

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
This is an Express service written in [TypeScript](https://www.typescriptlang.org/) that provides authorization functionality and includes gen-AI features, using RAG concepts, vector database and implements AI memory history with Redis DB.
44

5-
> 🌱 This project is under development.
5+
<center>
6+
<img src="docs/docs-screenshot.jpeg" alt="Swagger UI screenshot">
7+
</center>
68

79
## Resources
810

@@ -15,6 +17,7 @@ This is an Express service written in [TypeScript](https://www.typescriptlang.or
1517
- [Docker](https://docs.docker.com/) Containers for setting up environment.
1618
- [Redis](https://redis.io/) database for storing AI messages.
1719
- [ZOD](https://zod.dev/) as body parameters validation.
20+
- Automated [OpenAPI](https://www.openapis.org/what-is-openapi) specifications using [JsDocs](https://jsdoc.app/) and [Swagger UI](https://swagger.io/tools/swagger-ui/) for generating documentation.
1821

1922
## Project Structure
2023

@@ -79,4 +82,12 @@ cp .env.example .env
7982
docker compose up --build
8083
```
8184

82-
> The application will be available at `http://localhost:3000`.
85+
> The application will be available at `http://localhost:3000`.<br>
86+
87+
## Documentation
88+
89+
The documentation process is automated using `swagger-ui-express` and `swagger-jsdoc` libraries, on each application route definition you will find a comment with the necessary specifications for that route in particular.
90+
91+
During the build process the application will handle the route comments and generate the final `OpenApi` specification for the `Swagger UI`.
92+
93+
After that you will be able to access: `localhost:3000/docs` in your browser and see the docs.

docs/docs-screenshot.jpeg

419 KB
Loading
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Generate the JSDocs comments using OpenAPI for the following API specs:
2+
3+
```yaml
4+
endpoint name: /users/all
5+
# path parameter type: string
6+
method: GET
7+
request body: {
8+
"name": "John Doe",
9+
"email": "[email protected]",
10+
}
11+
summary: Returns all users
12+
200_response: {
13+
"success": true,
14+
"data": [
15+
{
16+
"id": "367b2539-bef4-412b-b94d-c9d2178dcdaa",
17+
"name": "John Doe",
18+
"email": "[email protected]",
19+
"createdAt": "2024-09-30T21:04:18.656Z"
20+
}
21+
]
22+
}
23+
# 400_response: {
24+
# "success": false,
25+
# "error": {
26+
# "message": [
27+
# "Invalid email address",
28+
# "name field is required"
29+
# ]
30+
# }
31+
# }
32+
headers: {
33+
"Content-Type": "application/json",
34+
"Authorization": "Bearer <token>"
35+
}
36+
```
37+
38+
More context: I'm using `swagger-ui-express` and `swagger-jsdoc` libraries to setup the Swagger documentation.
39+
Give me only the response, without explanations.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "genai-langchain-api",
33
"version": "1.0.0",
4-
"description": "This is an Express service that provides authorization functionality and includes gen-AI features.",
4+
"description": "This is an Express service that provides authorization functionality and includes gen-AI features using RAG, Redis, Postgres, and Langchain.",
55
"scripts": {
66
"prestart": "node dynamic-url-config.js",
77
"predev": "node dynamic-url-config.js",
@@ -30,6 +30,8 @@
3030
"multer": "1.4.5-lts.1",
3131
"pdf-parse": "^1.1.1",
3232
"redis": "^4.7.0",
33+
"swagger-jsdoc": "^6.2.8",
34+
"swagger-ui-express": "^5.0.1",
3335
"zod": "^3.23.8"
3436
},
3537
"devDependencies": {
@@ -38,6 +40,8 @@
3840
"@types/jsonwebtoken": "^9.0.7",
3941
"@types/multer": "^1.4.12",
4042
"@types/node": "^22.5.5",
43+
"@types/swagger-jsdoc": "^6.0.4",
44+
"@types/swagger-ui-express": "^4.1.6",
4145
"cors": "^2.8.5",
4246
"dotenv": "^16.4.5",
4347
"nodemon": "^3.1.4",

0 commit comments

Comments
 (0)