Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | import path from "path";
import { SwaggerOptions } from "swagger-ui-express";
const port = process.env.PORT || 5123;
const serverUrl = process.env.SERVER_URL || `http://localhost:${port} `
const isProduction = process.env.NODE_ENV === 'production'
export const swaggerConfig: SwaggerOptions = {
swaggerDefinition: {
openapi: "3.0.0",
info: {
title: "Smart Classroom API",
version: "1.0.0",
description: "API documentation for the Smart Classroom application",
},
servers: [
{
url: serverUrl
},
],
components: {
schemas: {
// Base schema for all devices
BaseDevice: {
type: "object",
required: ["id", "macAddress"],
properties: {
macAddress: {
type: "string",
description: "MAC address of the device",
example: "af:23:gh:ee:12:34"
}
}
},
// Reusable location object
Location: {
type: "object",
required: ["floor_id", "x", "y"],
properties: {
floor_id: {
type: "number",
description: "ID of the floor where the device is located",
example: 1
},
x: {
type: "number",
description: "X coordinate of the location",
example: 42.5
},
y: {
type: "number",
description: "Y coordinate of the location",
example: 78.3
}
}
},
// Generic Device registry
Device: {
allOf: [
{ $ref: "#/components/schemas/BaseDevice" },
{
type: "object",
required: ["type", "name", "_deactivate"],
properties: {
type: {
type: "string",
enum: ["Thingy", "Beacon", "Tag"],
description: "Type of the device",
example: "Thingy"
},
name: {
type: "string",
description: "Name for the device",
example: "Thingy_01"
},
_deactivate: {
type: "boolean",
description: "Whether the device is deactivated",
example: true
}
}
}
]
},
// Thingy sensor data
Thingy: {
allOf: [
{ $ref: "#/components/schemas/BaseDevice" },
{
type: "object",
required: ["moment"],
properties: {
temperature: {
type: "number",
description: "Temperature reading (°C)",
example: 22.3
},
humidity: {
type: "number",
description: "Humidity percentage",
example: 45.1
},
co2: {
type: "number",
description: "CO2 level (ppm)",
example: 415
},
pm_1: {
type: "number",
description: "PM 1.0 level (µg/m³)",
example: 5.2
},
pm_2_5: {
type: "number",
description: "PM 2.5 level (µg/m³)",
example: 8.6
},
pm_10: {
type: "number",
description: "PM 5.0 level (µg/m³)",
example: 10.2
},
timestamp: {
type: "Date",
format: "date-time",
description: "Timestamp of the data capture",
example: "2025-04-10T12:30:00Z"
}
}
}
]
},
// Tag device with location info
Tag: {
type: "object",
required: ["macAddress", "timestamp", "beacon", "location"],
properties: {
macAddress: {
type: "string",
description: "MAC address of the tag",
example: "af:23:gh:ee:12:34"
},
timestamp: {
type: "string",
format: "date-time",
description: "Timestamp of the tag data",
example: "2025-04-10T12:30:00Z"
},
beacon: {
type: "array",
items: {
type: "object",
properties: {
macAddress: {
type: "string",
description: "MAC address of the beacon",
example: "be:12:cd:34:56:78"
},
rssi: {
type: "number",
description: "RSSI value of the beacon",
example: -67
}
}
}
},
location: {
$ref: "#/components/schemas/Location"
}
}
}
}
}
},
apis: isProduction ? ['./dist/api/routes/**/*.js'] : ['./src/api/routes/**/*.ts'],
}; |