Files
nxxmdata/backend/swagger-config.js

370 lines
10 KiB
JavaScript
Raw Normal View History

/**
* Swagger API文档配置
* @file swagger-config.js
* @description 配置Swagger API文档包含智能耳标预警和智能项圈预警接口
*/
const swaggerJSDoc = require('swagger-jsdoc');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: '智能预警系统 API',
version: '1.0.0',
description: '智能耳标预警和智能项圈预警系统API文档',
contact: {
name: '开发团队',
email: 'dev@example.com'
}
},
servers: [
{
url: 'http://localhost:5350/api',
description: '开发环境'
}
],
tags: [
{
name: '智能耳标预警',
description: '智能耳标预警相关接口'
},
{
name: '智能项圈预警',
description: '智能项圈预警相关接口'
}
],
components: {
schemas: {
EartagAlert: {
type: 'object',
properties: {
id: {
type: 'string',
description: '预警ID',
example: '123_offline'
},
deviceId: {
type: 'integer',
description: '设备ID',
example: 123
},
deviceName: {
type: 'string',
description: '设备名称',
example: 'EARTAG001'
},
eartagNumber: {
type: 'string',
description: '耳标编号',
example: 'EARTAG001'
},
alertType: {
type: 'string',
description: '预警类型',
enum: ['battery', 'offline', 'temperature', 'movement'],
example: 'offline'
},
alertLevel: {
type: 'string',
description: '预警级别',
enum: ['high', 'medium', 'low'],
example: 'high'
},
alertTime: {
type: 'string',
format: 'date-time',
description: '预警时间',
example: '2024-01-15 10:30:00'
},
battery: {
type: 'integer',
description: '设备电量',
example: 85
},
temperature: {
type: 'number',
description: '设备温度',
example: 25.5
},
dailySteps: {
type: 'integer',
description: '当日步数',
example: 0
},
totalSteps: {
type: 'integer',
description: '总步数',
example: 1500
},
yesterdaySteps: {
type: 'integer',
description: '昨日步数',
example: 1500
},
deviceStatus: {
type: 'string',
description: '设备状态',
example: '离线'
},
gpsSignal: {
type: 'string',
description: 'GPS信号',
example: '无'
},
movementStatus: {
type: 'string',
description: '运动状态',
example: '静止'
},
description: {
type: 'string',
description: '预警描述',
example: '设备已离线超过30分钟'
},
longitude: {
type: 'number',
description: '经度',
example: 116.3974
},
latitude: {
type: 'number',
description: '纬度',
example: 39.9093
}
}
},
CollarAlert: {
type: 'object',
properties: {
id: {
type: 'string',
description: '预警ID',
example: '123_offline'
},
deviceId: {
type: 'integer',
description: '设备ID',
example: 123
},
deviceName: {
type: 'string',
description: '设备名称',
example: 'COLLAR001'
},
collarNumber: {
type: 'string',
description: '项圈编号',
example: 'COLLAR001'
},
alertType: {
type: 'string',
description: '预警类型',
enum: ['battery', 'offline', 'temperature', 'movement', 'wear'],
example: 'offline'
},
alertLevel: {
type: 'string',
description: '预警级别',
enum: ['high', 'medium', 'low'],
example: 'high'
},
alertTime: {
type: 'string',
format: 'date-time',
description: '预警时间',
example: '2024-01-15 10:30:00'
},
battery: {
type: 'integer',
description: '设备电量',
example: 85
},
temperature: {
type: 'number',
description: '设备温度',
example: 25.5
},
dailySteps: {
type: 'integer',
description: '当日步数',
example: 0
},
totalSteps: {
type: 'integer',
description: '总步数',
example: 1500
},
yesterdaySteps: {
type: 'integer',
description: '昨日步数',
example: 1500
},
deviceStatus: {
type: 'string',
description: '设备状态',
example: '离线'
},
gpsSignal: {
type: 'string',
description: 'GPS信号',
example: '无'
},
wearStatus: {
type: 'string',
description: '佩戴状态',
example: '未佩戴'
},
movementStatus: {
type: 'string',
description: '运动状态',
example: '静止'
},
description: {
type: 'string',
description: '预警描述',
example: '设备已离线超过30分钟'
},
longitude: {
type: 'number',
description: '经度',
example: 116.3974
},
latitude: {
type: 'number',
description: '纬度',
example: 39.9093
}
}
},
AlertStats: {
type: 'object',
properties: {
totalDevices: {
type: 'integer',
description: '设备总数',
example: 150
},
lowBattery: {
type: 'integer',
description: '低电量预警数量',
example: 12
},
offline: {
type: 'integer',
description: '离线预警数量',
example: 8
},
highTemperature: {
type: 'integer',
description: '高温预警数量',
example: 5
},
lowTemperature: {
type: 'integer',
description: '低温预警数量',
example: 3
},
abnormalMovement: {
type: 'integer',
description: '异常运动预警数量',
example: 7
},
wearOff: {
type: 'integer',
description: '项圈脱落预警数量(仅项圈)',
example: 2
},
totalAlerts: {
type: 'integer',
description: '预警总数',
example: 35
}
}
},
ApiResponse: {
type: 'object',
properties: {
success: {
type: 'boolean',
description: '请求是否成功',
example: true
},
data: {
type: 'object',
description: '响应数据'
},
message: {
type: 'string',
description: '响应消息',
example: '操作成功'
},
total: {
type: 'integer',
description: '数据总数(分页时使用)',
example: 100
},
stats: {
$ref: '#/components/schemas/AlertStats'
},
pagination: {
type: 'object',
properties: {
page: {
type: 'integer',
description: '当前页码',
example: 1
},
limit: {
type: 'integer',
description: '每页数量',
example: 10
},
total: {
type: 'integer',
description: '总数据量',
example: 100
},
pages: {
type: 'integer',
description: '总页数',
example: 10
}
}
}
}
},
ErrorResponse: {
type: 'object',
properties: {
success: {
type: 'boolean',
description: '请求是否成功',
example: false
},
message: {
type: 'string',
description: '错误消息',
example: '请求失败'
},
error: {
type: 'string',
description: '详细错误信息',
example: '具体错误描述'
}
}
}
}
}
},
apis: [
'./routes/smart-alerts.js',
'./controllers/smartEartagAlertController.js',
'./controllers/smartCollarAlertController.js'
]
};
const specs = swaggerJSDoc(options);
module.exports = specs;