320 lines
8.5 KiB
JavaScript
320 lines
8.5 KiB
JavaScript
const swaggerJsdoc = require('swagger-jsdoc');
|
|
|
|
const options = {
|
|
definition: {
|
|
openapi: '3.0.0',
|
|
info: {
|
|
title: '宁夏智慧养殖监管平台 API',
|
|
version: '1.0.0',
|
|
description: '宁夏智慧养殖监管平台后端 API 文档',
|
|
},
|
|
servers: [
|
|
{
|
|
url: 'http://localhost:5350',
|
|
description: '开发服务器',
|
|
},
|
|
],
|
|
components: {
|
|
securitySchemes: {
|
|
bearerAuth: {
|
|
type: 'http',
|
|
scheme: 'bearer',
|
|
bearerFormat: 'JWT',
|
|
}
|
|
},
|
|
schemas: {
|
|
MapGeocode: {
|
|
type: 'object',
|
|
properties: {
|
|
address: {
|
|
type: 'string',
|
|
description: '地址'
|
|
},
|
|
result: {
|
|
type: 'object',
|
|
properties: {
|
|
location: {
|
|
type: 'object',
|
|
properties: {
|
|
lng: {
|
|
type: 'number',
|
|
description: '经度'
|
|
},
|
|
lat: {
|
|
type: 'number',
|
|
description: '纬度'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
MapReverseGeocode: {
|
|
type: 'object',
|
|
properties: {
|
|
lat: {
|
|
type: 'number',
|
|
description: '纬度'
|
|
},
|
|
lng: {
|
|
type: 'number',
|
|
description: '经度'
|
|
},
|
|
result: {
|
|
type: 'object',
|
|
properties: {
|
|
formatted_address: {
|
|
type: 'string',
|
|
description: '结构化地址'
|
|
},
|
|
addressComponent: {
|
|
type: 'object',
|
|
description: '地址组成部分'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
MapDirection: {
|
|
type: 'object',
|
|
properties: {
|
|
origin: {
|
|
type: 'string',
|
|
description: '起点坐标,格式:纬度,经度'
|
|
},
|
|
destination: {
|
|
type: 'string',
|
|
description: '终点坐标,格式:纬度,经度'
|
|
},
|
|
mode: {
|
|
type: 'string',
|
|
enum: ['driving', 'walking', 'riding', 'transit'],
|
|
description: '交通方式'
|
|
}
|
|
}
|
|
},
|
|
Farm: {
|
|
type: 'object',
|
|
properties: {
|
|
id: {
|
|
type: 'integer',
|
|
description: '养殖场ID'
|
|
},
|
|
name: {
|
|
type: 'string',
|
|
description: '养殖场名称'
|
|
},
|
|
type: {
|
|
type: 'string',
|
|
description: '养殖场类型'
|
|
},
|
|
location: {
|
|
type: 'object',
|
|
properties: {
|
|
latitude: {
|
|
type: 'number',
|
|
format: 'float',
|
|
description: '纬度'
|
|
},
|
|
longitude: {
|
|
type: 'number',
|
|
format: 'float',
|
|
description: '经度'
|
|
}
|
|
},
|
|
description: '地理位置'
|
|
},
|
|
address: {
|
|
type: 'string',
|
|
description: '详细地址'
|
|
},
|
|
contact: {
|
|
type: 'string',
|
|
description: '联系人'
|
|
},
|
|
phone: {
|
|
type: 'string',
|
|
description: '联系电话'
|
|
},
|
|
status: {
|
|
type: 'string',
|
|
enum: ['active', 'inactive', 'maintenance'],
|
|
description: '养殖场状态'
|
|
},
|
|
createdAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '创建时间'
|
|
},
|
|
updatedAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '更新时间'
|
|
}
|
|
}
|
|
},
|
|
Animal: {
|
|
type: 'object',
|
|
properties: {
|
|
id: {
|
|
type: 'integer',
|
|
description: '动物ID'
|
|
},
|
|
type: {
|
|
type: 'string',
|
|
description: '动物类型'
|
|
},
|
|
count: {
|
|
type: 'integer',
|
|
description: '数量'
|
|
},
|
|
farmId: {
|
|
type: 'integer',
|
|
description: '所属养殖场ID'
|
|
},
|
|
health_status: {
|
|
type: 'string',
|
|
enum: ['healthy', 'sick', 'quarantined'],
|
|
description: '健康状态'
|
|
},
|
|
last_check_time: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '上次检查时间'
|
|
},
|
|
notes: {
|
|
type: 'string',
|
|
description: '备注'
|
|
},
|
|
createdAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '创建时间'
|
|
},
|
|
updatedAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '更新时间'
|
|
}
|
|
}
|
|
},
|
|
Device: {
|
|
type: 'object',
|
|
properties: {
|
|
id: {
|
|
type: 'integer',
|
|
description: '设备ID'
|
|
},
|
|
name: {
|
|
type: 'string',
|
|
description: '设备名称'
|
|
},
|
|
type: {
|
|
type: 'string',
|
|
description: '设备类型'
|
|
},
|
|
status: {
|
|
type: 'string',
|
|
enum: ['online', 'offline', 'maintenance'],
|
|
description: '设备状态'
|
|
},
|
|
farmId: {
|
|
type: 'integer',
|
|
description: '所属养殖场ID'
|
|
},
|
|
last_maintenance: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '上次维护时间'
|
|
},
|
|
installation_date: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '安装日期'
|
|
},
|
|
metrics: {
|
|
type: 'object',
|
|
description: '设备指标'
|
|
},
|
|
createdAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '创建时间'
|
|
},
|
|
updatedAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '更新时间'
|
|
}
|
|
}
|
|
},
|
|
Alert: {
|
|
type: 'object',
|
|
properties: {
|
|
id: {
|
|
type: 'integer',
|
|
description: '预警ID'
|
|
},
|
|
type: {
|
|
type: 'string',
|
|
description: '预警类型'
|
|
},
|
|
level: {
|
|
type: 'string',
|
|
enum: ['low', 'medium', 'high', 'critical'],
|
|
description: '预警级别'
|
|
},
|
|
message: {
|
|
type: 'string',
|
|
description: '预警消息'
|
|
},
|
|
status: {
|
|
type: 'string',
|
|
enum: ['active', 'acknowledged', 'resolved'],
|
|
description: '预警状态'
|
|
},
|
|
farmId: {
|
|
type: 'integer',
|
|
description: '所属养殖场ID'
|
|
},
|
|
deviceId: {
|
|
type: 'integer',
|
|
description: '关联设备ID'
|
|
},
|
|
resolved_at: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '解决时间'
|
|
},
|
|
resolved_by: {
|
|
type: 'integer',
|
|
description: '解决人ID'
|
|
},
|
|
resolution_notes: {
|
|
type: 'string',
|
|
description: '解决备注'
|
|
},
|
|
createdAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '创建时间'
|
|
},
|
|
updatedAt: {
|
|
type: 'string',
|
|
format: 'date-time',
|
|
description: '更新时间'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
security: [{
|
|
bearerAuth: []
|
|
}]
|
|
},
|
|
apis: ['./routes/*.js'], // 指定包含 API 注释的文件路径
|
|
};
|
|
|
|
const specs = swaggerJsdoc(options);
|
|
module.exports = specs; |