MeetUp/src/app/api/event/[eventID]/participant/[user]/swagger.ts
Dominik Stahl eef17c5360
All checks were successful
container-scan / Container Scan (pull_request) Successful in 5m17s
docker-build / docker (pull_request) Successful in 6m1s
refactor(validation): restucture api input and output validation
2025-06-19 15:53:53 +02:00

102 lines
2.5 KiB
TypeScript

import { OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
import zod from 'zod/v4';
import {
ParticipantResponseSchema,
updateParticipantSchema,
} from '../validation';
import {
invalidRequestDataResponse,
notAuthenticatedResponse,
serverReturnedDataValidationErrorResponse,
userNotFoundResponse,
} from '@/lib/defaultApiResponses';
import {
EventIdParamSchema,
UserIdParamSchema,
SuccessResponseSchema,
} from '@/app/api/validation';
export default function registerSwaggerPaths(registry: OpenAPIRegistry) {
registry.registerPath({
method: 'get',
path: '/event/{eventID}/participant/{user}',
request: {
params: zod.object({
eventID: EventIdParamSchema,
user: UserIdParamSchema,
}),
},
responses: {
200: {
description: 'Get a participant for the event',
content: {
'application/json': {
schema: ParticipantResponseSchema,
},
},
},
...notAuthenticatedResponse,
...userNotFoundResponse,
...serverReturnedDataValidationErrorResponse,
},
tags: ['Event Participant'],
});
registry.registerPath({
method: 'delete',
path: '/event/{eventID}/participant/{user}',
request: {
params: zod.object({
eventID: EventIdParamSchema,
user: UserIdParamSchema,
}),
},
responses: {
200: {
description: 'Participant removed successfully',
content: {
'application/json': {
schema: SuccessResponseSchema,
},
},
},
...notAuthenticatedResponse,
...userNotFoundResponse,
...serverReturnedDataValidationErrorResponse,
},
tags: ['Event Participant'],
});
registry.registerPath({
method: 'patch',
path: '/event/{eventID}/participant/{user}',
request: {
params: zod.object({
eventID: EventIdParamSchema,
user: UserIdParamSchema,
}),
body: {
content: {
'application/json': {
schema: updateParticipantSchema,
},
},
},
},
responses: {
200: {
description: 'Participant updated successfully',
content: {
'application/json': {
schema: ParticipantResponseSchema,
},
},
},
...notAuthenticatedResponse,
...userNotFoundResponse,
...serverReturnedDataValidationErrorResponse,
...invalidRequestDataResponse,
},
tags: ['Event Participant'],
});
}