Files
mailer/src/swagger.ts

118 lines
2.7 KiB
TypeScript

import { swaggerUI } from '@hono/swagger-ui'
const routes = {
'/api/v1/email': {
post: {
summary: 'Send an email',
requestBody: {
required: true,
content: {
'application/json': {
schema: {
type: 'object',
required: ['to', 'templateName', 'language', 'data'],
properties: {
to: {
type: 'string',
format: 'email'
},
templateName: {
type: 'string'
},
language: {
type: 'string',
enum: ['en', 'de']
},
data: {
type: 'object'
}
}
}
}
}
},
responses: {
'200': {
description: 'Email queued successfully',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: {
type: 'boolean'
}
}
}
}
}
},
'400': {
description: 'Bad request or email queueing failed',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
success: {
type: 'boolean'
},
error: {
type: 'string'
}
}
}
}
}
}
}
},
get: {
path: '/status',
summary: 'Get email queue status',
responses: {
'200': {
description: 'Queue status retrieved successfully',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
waiting: {
type: 'number'
},
active: {
type: 'number'
},
completed: {
type: 'number'
},
failed: {
type: 'number'
}
}
}
}
}
}
}
}
}
}
const apiDoc = {
openapi: '3.0.0',
info: {
title: process.env.npm_package_name,
version: process.env.npm_package_version,
description: 'API for sending templated emails in multiple languages'
},
paths: routes
}
export const createSwaggerUI = () => {
return swaggerUI({
url: '/api/docs',
spec: apiDoc
})
}