2828 description : Find out more
2929 url : example.com
3030
31+ - name : Authentication
32+ description : Operations related to user registration and login
33+
3134# --------------------------------------------
3235# Components
3336components :
@@ -108,6 +111,57 @@ components:
108111 type : array
109112 items :
110113 $ref : ' #/components/schemas/BookOutput'
114+
115+ # ----- AUTH schemas -------------
116+
117+ # Schema for the data client POSTs to register a user
118+ UserRegistrationInput :
119+ type : object
120+ properties :
121+ email :
122+ type : string
123+ format : email
124+ description : The user's email address.
125+ 126+ password :
127+ type : string
128+ format : password # This format is a hint for UI tools to obscure the input
129+ description : The user's desired password.
130+ minLength : 8 # It's good practice to suggest a minimum length
131+ example : " a-very-secure-password"
132+ required :
133+ - email
134+ - password
135+
136+ # Schema for the User object as returned by the server on success
137+ UserOutput :
138+ type : object
139+ properties :
140+ id :
141+ type : string
142+ description : The unique 24-character hexadecimal identifier for the user (MongoDB ObjectId).
143+ readOnly : true
144+ example : " 635f3a7e3a8e3bcfc8e6a1e0"
145+ email :
146+ type : string
147+ format : email
148+ readOnly : true
149+ 150+
151+ # Schema for the successful registration response
152+ RegistrationSuccess :
153+ type : object
154+ properties :
155+ message :
156+ type : string
157+ example : " User registered successfully"
158+ user :
159+ $ref : ' #/components/schemas/UserOutput'
160+
161+
162+
163+
164+ # ------ ERROR schemas ----------
111165
112166 # Generic Error schema
113167 StandardError :
@@ -144,6 +198,16 @@ components:
144198 required :
145199 - error
146200
201+ # Schema for a simple message response (useful for errors)
202+ MessageError :
203+ type : object
204+ properties :
205+ message :
206+ type : string
207+ description : A brief error message.
208+ required :
209+ - message
210+
147211 # API Error: Reusable responses for common errors
148212 responses :
149213 BadRequest :
@@ -426,3 +490,50 @@ paths:
426490 error : " Book not found"
427491 ' 500 ' :
428492 $ref : ' #/components/responses/InternalServerError'
493+ # --------------------------------------------
494+ /auth/register :
495+ # --------------------------------------------
496+ post :
497+ tags :
498+ - Authentication
499+ summary : Register a new user
500+ description : >-
501+ Creates a new user account. The server will hash the password and store the user details, returning a unique ID for the new user.
502+ operationId : registerUser
503+ requestBody :
504+ description : User's email and password for registration.
505+ required : true
506+ content :
507+ application/json :
508+ schema :
509+ $ref : ' #/components/schemas/UserRegistrationInput'
510+ responses :
511+ ' 201 ' :
512+ description : User registered successfully.
513+ content :
514+ application/json :
515+ schema :
516+ $ref : ' #/components/schemas/RegistrationSuccess'
517+ ' 400 ' :
518+ description : Bad Request. The request body is missing, not valid JSON, or is missing required fields.
519+ content :
520+ application/json :
521+ schema :
522+ $ref : ' #/components/schemas/MessageError'
523+ examples :
524+ missingFields :
525+ summary : Missing Fields
526+ value :
527+ message : " Email and password are required"
528+ emptyBody :
529+ summary : Empty Body
530+ value :
531+ message : " Request body cannot be empty"
532+ ' 409 ' :
533+ description : Conflict. The provided email is already registered.
534+ content :
535+ application/json :
536+ schema :
537+ $ref : ' #/components/schemas/MessageError' # Reuse the error schema again!
538+ example :
539+ message : " Email is already registered"
0 commit comments