Skip to content

Commit a12fe94

Browse files
pyphiliakim
andauthored
docs: improve openapi data for password endpoints (#1938)
* docs: improve openapi data for password endpoints * refactor: apply PR requested changes --------- Co-authored-by: kim <kim.phanhoang@epfl.ch>
1 parent 2937830 commit a12fe94

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

src/services/auth/plugins/password/password.controller.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import {
2323
matchOne,
2424
} from '../passport';
2525
import {
26-
getMembersCurrentPasswordStatus,
27-
passwordLogin,
28-
patchResetPasswordRequest,
29-
postResetPasswordRequest,
30-
setPassword,
26+
createPassword,
27+
getOwnPasswordStatus,
28+
requestPasswordResetLink,
29+
resetPassword,
30+
signInWithPassword,
3131
updatePassword,
3232
} from './password.schemas';
3333
import { MemberPasswordService } from './password.service';
@@ -43,7 +43,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
4343
fastify.post(
4444
'/login-password',
4545
{
46-
schema: passwordLogin,
46+
schema: signInWithPassword,
4747
preHandler: [
4848
captchaPreHandler(RecaptchaAction.SignInWithPassword, {
4949
shouldFail: false,
@@ -81,7 +81,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
8181
fastify.post(
8282
'/password',
8383
{
84-
schema: setPassword,
84+
schema: createPassword,
8585
preHandler: [isAuthenticated, matchOne(validatedMemberAccountRole)],
8686
},
8787
async ({ user, body: { password } }, reply) => {
@@ -129,7 +129,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
129129
fastify.post(
130130
'/password/reset',
131131
{
132-
schema: postResetPasswordRequest,
132+
schema: requestPasswordResetLink,
133133
preHandler: captchaPreHandler(RecaptchaAction.ResetPassword),
134134
},
135135
async (request, reply) => {
@@ -170,7 +170,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
170170
fastify.patch(
171171
'/password/reset',
172172
{
173-
schema: patchResetPasswordRequest,
173+
schema: resetPassword,
174174
preHandler: authenticatePasswordReset,
175175
},
176176
async (request, reply) => {
@@ -206,7 +206,7 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
206206
fastify.get(
207207
'/members/current/password/status',
208208
{
209-
schema: getMembersCurrentPasswordStatus,
209+
schema: getOwnPasswordStatus,
210210
preHandler: [isAuthenticated],
211211
},
212212
async ({ user }) => {

src/services/auth/plugins/password/password.schemas.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import type { FastifySchema } from 'fastify';
66
import { customType } from '../../../../plugins/typebox';
77
import { errorSchemaRef } from '../../../../schemas/global';
88

9-
export const passwordLogin = {
9+
export const signInWithPassword = {
10+
operationId: 'signInWithPassword',
1011
tags: ['password'],
1112
summary: 'Log in with email and password',
1213
description:
@@ -20,9 +21,17 @@ export const passwordLogin = {
2021
querystring: customType.StrictObject({
2122
lang: Type.Optional(Type.String()),
2223
}),
24+
response: {
25+
[StatusCodes.OK]: customType.StrictObject({
26+
resource: Type.String({ description: 'Redirection link' }),
27+
}),
28+
'4xx': errorSchemaRef,
29+
'5xx': errorSchemaRef,
30+
},
2331
} as const satisfies FastifySchema;
2432

25-
export const setPassword = {
33+
export const createPassword = {
34+
operationId: 'createPassword',
2635
tags: ['password'],
2736
summary: 'Set a password for the authenticated member',
2837
description:
@@ -38,6 +47,7 @@ export const setPassword = {
3847
} as const satisfies FastifySchema;
3948

4049
export const updatePassword = {
50+
operationId: 'updatePassword',
4151
tags: ['password'],
4252
summary: 'Update the password of the authenticated member',
4353
description:
@@ -55,7 +65,8 @@ export const updatePassword = {
5565
},
5666
} as const satisfies FastifySchema;
5767

58-
export const postResetPasswordRequest = {
68+
export const requestPasswordResetLink = {
69+
operationId: 'requestPasswordResetLink',
5970
tags: ['password'],
6071
summary: 'Create a reset password request',
6172
description:
@@ -70,7 +81,8 @@ export const postResetPasswordRequest = {
7081
},
7182
} as const satisfies FastifySchema;
7283

73-
export const patchResetPasswordRequest = {
84+
export const resetPassword = {
85+
operationId: 'resetPassword',
7486
tags: ['password'],
7587
summary: 'Confirm the reset password request',
7688
description:
@@ -85,7 +97,8 @@ export const patchResetPasswordRequest = {
8597
},
8698
} as const satisfies FastifySchema;
8799

88-
export const getMembersCurrentPasswordStatus = {
100+
export const getOwnPasswordStatus = {
101+
operationId: 'getOwnPasswordStatus',
89102
tags: ['password', 'current'],
90103
summary: 'Get the current password status of the authenticated member',
91104
description: 'Return whether the authenticated member has a password defined.',

0 commit comments

Comments
 (0)