File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 "express" : " ^4.21.2" ,
1616 "jsonwebtoken" : " ^9.0.3" ,
1717 "mongoose" : " ^8.9.5" ,
18- "socket.io" : " ^4.8.1"
18+ "socket.io" : " ^4.8.1" ,
19+ "swagger-ui-express" : " ^5.0.1" ,
20+ "yamljs" : " ^0.3.0"
1921 },
2022 "devDependencies" : {
2123 "@types/cors" : " ^2.8.17" ,
2224 "@types/express" : " ^4.17.21" ,
2325 "@types/jsonwebtoken" : " ^9.0.7" ,
2426 "@types/node" : " ^20.10.6" ,
27+ "@types/swagger-ui-express" : " ^4.1.8" ,
28+ "@types/yamljs" : " ^0.2.34" ,
2529 "nodemon" : " ^3.1.9" ,
2630 "ts-node" : " ^10.9.2" ,
2731 "tsx" : " ^4.7.0" ,
3337 "keywords" : [],
3438 "author" : " " ,
3539 "license" : " ISC"
36- }
40+ }
Original file line number Diff line number Diff line change 1+ openapi : 3.1.0
2+ info :
3+ title : Pixie API
4+ version : 1.0.0
5+ description : API for Pixie application, providing user authentication and management.
6+ servers :
7+ - url : http://localhost:3000/api
8+ description : Local server
9+ paths :
10+ /login :
11+ post :
12+ summary : User login
13+ description : Authenticates a user or registers a new one if not found.
14+ tags :
15+ - Auth
16+ requestBody :
17+ required : true
18+ content :
19+ application/json :
20+ schema :
21+ type : object
22+ properties :
23+ username :
24+ type : string
25+ example : " playerOne"
26+ required :
27+ - username
28+ responses :
29+ ' 200 ' :
30+ description : Successful login
31+ content :
32+ application/json :
33+ schema :
34+ $ref : ' #/components/schemas/LoginResponse'
35+ ' 400 ' :
36+ description : Bad Request (Missing username)
37+ /users :
38+ get :
39+ summary : Get all users
40+ description : Retrieve a list of all users. Requires authentication.
41+ tags :
42+ - Users
43+ security :
44+ - bearerAuth : []
45+ responses :
46+ ' 200 ' :
47+ description : List of users
48+ content :
49+ application/json :
50+ schema :
51+ type : array
52+ items :
53+ $ref : ' #/components/schemas/UserSummary'
54+ ' 401 ' :
55+ description : Unauthorized (Missing token)
56+ ' 403 ' :
57+ description : Forbidden (Invalid token)
58+ components :
59+ securitySchemes :
60+ bearerAuth :
61+ type : http
62+ scheme : bearer
63+ bearerFormat : JWT
64+ schemas :
65+ UserSummary :
66+ type : object
67+ properties :
68+ username :
69+ type : string
70+ example : " playerOne"
71+ isAdmin :
72+ type : boolean
73+ example : false
74+ _id :
75+ type : string
76+ example : " 60d0fe4f5311236168a109ca"
77+ LoginResponse :
78+ type : object
79+ properties :
80+ username :
81+ type : string
82+ example : " playerOne"
83+ id :
84+ type : string
85+ example : " 60d0fe4f5311236168a109ca"
86+ token :
87+ type : string
88+ description : JWT token for authentication
89+ isNewUser :
90+ type : boolean
91+ description : True if a new account was created
Original file line number Diff line number Diff line change 11import mongoose from "mongoose"
2- import { seedUsers } from "./seed"
2+ import { seedUsers } from "./seed.js "
33
44const MONGO_URI = process . env . MONGO_URI || "mongodb://localhost:27017/pixie"
55
Original file line number Diff line number Diff line change 1- import { User } from "../models/User"
1+ import { User } from "../models/User.js "
22
33export const seedUsers = async ( ) : Promise < void > => {
44 const users = [
Original file line number Diff line number Diff line change @@ -33,6 +33,12 @@ import { errorHandler } from "./middlewares/errorMiddleware.js";
3333// API Routes (REST)
3434app . use ( "/api" , router ) ;
3535
36+ // Swagger UI
37+ import swaggerUi from "swagger-ui-express" ;
38+ import YAML from "yamljs" ;
39+ const swaggerDocument = YAML . load ( "./pixie-api.yaml" ) ;
40+ app . use ( "/api-docs" , swaggerUi . serve , swaggerUi . setup ( swaggerDocument ) ) ;
41+
3642// Global Error Handler
3743app . use ( errorHandler ) ;
3844
You can’t perform that action at this time.
0 commit comments