Skip to content

Commit 91c1c23

Browse files
committed
Swagger for location routes
1 parent 7c6efbb commit 91c1c23

File tree

5 files changed

+380
-49
lines changed

5 files changed

+380
-49
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ app.get("/api/status", async (req, res) => {
7979
// Swagger
8080
const swaggerOptions: Options = {
8181
definition: {
82-
openapi: "3.1.0",
82+
openapi: "3.0.0",
8383
info: {
8484
title: "Onloc API",
8585
version: "1.1.0",

src/openapi/schemas.yaml

Lines changed: 105 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ components:
44
type: object
55
properties:
66
id:
7-
type: integer
8-
format: int64
7+
type: string
98
username:
109
type: string
1110
admin:
@@ -59,9 +58,7 @@ components:
5958
type: object
6059
properties:
6160
id:
62-
type: integer
63-
format: int64
64-
description: API key ID
61+
type: string
6562
name:
6663
type: string
6764
key:
@@ -80,37 +77,13 @@ components:
8077
- created_at
8178
- updated_at
8279

83-
ApiKeyList:
84-
type: array
85-
items:
86-
type: object
87-
properties:
88-
id:
89-
type: integer
90-
format: int64
91-
name:
92-
type: string
93-
created_at:
94-
type: string
95-
format: date-time
96-
updated_at:
97-
type: string
98-
format: date-time
99-
required:
100-
- id
101-
- name
102-
- created_at
103-
- updated_at
104-
10580
DeviceSafe:
10681
type: object
10782
properties:
10883
id:
109-
type: integer
110-
format: int64
84+
type: string
11185
user_id:
112-
type: integer
113-
format: int64
86+
type: string
11487
name:
11588
type: string
11689
icon:
@@ -136,28 +109,125 @@ components:
136109
type: object
137110
properties:
138111
id:
139-
type: integer
140-
format: int64
112+
type: string
141113
device_id:
142-
type: integer
143-
format: int64
114+
type: string
144115
latitude:
145116
type: number
146117
longitude:
147118
type: number
148119
accuracy:
149120
type: number
150121
nullable: true
122+
altitude:
123+
type: number
124+
nullable: true
125+
altitude_accuracy:
126+
type: number
127+
nullable: true
128+
battery:
129+
type: integer
130+
nullable: true
131+
description: Battery percentage (1-100)
151132
created_at:
152133
type: string
153134
format: date-time
135+
updated_at:
136+
type: string
137+
format: date-time
154138
required:
155139
- id
156140
- device_id
157141
- latitude
158142
- longitude
159143
- created_at
160144

145+
# Reusable request bodies for locations
146+
LocationCreate:
147+
type: object
148+
description: Payload to create a new location for a device
149+
required:
150+
- device_id
151+
- latitude
152+
- longitude
153+
properties:
154+
device_id:
155+
type: string
156+
description: Device ID this location belongs to
157+
example: "123"
158+
latitude:
159+
type: number
160+
format: float
161+
example: 51.5074
162+
longitude:
163+
type: number
164+
format: float
165+
example: -0.1278
166+
accuracy:
167+
type: number
168+
nullable: true
169+
description: Accuracy in meters
170+
altitude:
171+
type: number
172+
nullable: true
173+
description: Altitude in meters
174+
altitude_accuracy:
175+
type: number
176+
nullable: true
177+
battery:
178+
type: integer
179+
nullable: true
180+
description: Battery percentage (1-100)
181+
example:
182+
device_id: "123"
183+
latitude: 51.5074
184+
longitude: -0.1278
185+
accuracy: 5.2
186+
altitude: 15.0
187+
altitude_accuracy: 1.0
188+
battery: 78
189+
190+
LocationUpdate:
191+
type: object
192+
description: Payload to update an existing location
193+
required:
194+
- id
195+
properties:
196+
id:
197+
type: string
198+
description: Location ID to update
199+
example: "456"
200+
device_id:
201+
type: string
202+
description: Device ID this location belongs to (optional)
203+
latitude:
204+
type: number
205+
format: float
206+
longitude:
207+
type: number
208+
format: float
209+
accuracy:
210+
type: number
211+
nullable: true
212+
altitude:
213+
type: number
214+
nullable: true
215+
altitude_accuracy:
216+
type: number
217+
nullable: true
218+
battery:
219+
type: integer
220+
nullable: true
221+
example:
222+
id: "123"
223+
device_id: "456"
224+
latitude: 51.5074
225+
longitude: -0.1278
226+
accuracy: 5.2
227+
altitude: 15.0
228+
altitude_accuracy: 1.0
229+
battery: 78
230+
161231
DeviceWithExtras:
162232
allOf:
163233
- $ref: "#/components/schemas/DeviceSafe"

src/routes/apiKeyRoutes.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ router.post("/", createApiKey)
6262
* /api/apikeys:
6363
* get:
6464
* summary: List all API keys for the current user
65-
* description: Returns all API keys belonging to the authenticated user. The actual key value is never returned in this endpoint for security.
65+
* description: Returns all API keys belonging to the authenticated user.
6666
* tags: [API Keys]
6767
* security:
6868
* - bearerAuth: []
@@ -75,7 +75,9 @@ router.post("/", createApiKey)
7575
* type: object
7676
* properties:
7777
* api_keys:
78-
* $ref: "#/components/schemas/ApiKeyList"
78+
* type: array
79+
* items:
80+
* $ref: "#/components/schemas/ApiKeySafe"
7981
* 401:
8082
* $ref: "#/components/responses/Unauthorized"
8183
* 500:
@@ -96,11 +98,10 @@ router.get("/", readApiKeys)
9698
* - in: path
9799
* name: id
98100
* schema:
99-
* type: integer
100-
* format: int64
101+
* type: string
101102
* required: true
102103
* description: The API key ID to delete
103-
* example: 123
104+
* example: "123"
104105
* responses:
105106
* 204:
106107
* description: API key deleted successfully (no content)

src/routes/deviceRoutes.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ router.get("/", readDevices)
101101
* in: path
102102
* required: true
103103
* schema:
104-
* type: integer
105-
* format: int64
104+
* type: string
106105
* description: Device ID
106+
* example: "123"
107107
* responses:
108108
* 200:
109109
* description: Device details
@@ -145,8 +145,7 @@ router.get("/:id", readDevice)
145145
* required: [id]
146146
* properties:
147147
* id:
148-
* type: integer
149-
* format: int64
148+
* type: string
150149
* name:
151150
* type: string
152151
* icon:
@@ -187,9 +186,9 @@ router.patch("/", updateDevice)
187186
* in: path
188187
* required: true
189188
* schema:
190-
* type: integer
191-
* format: int64
189+
* type: string
192190
* description: Device ID to delete
191+
* example: "123"
193192
* responses:
194193
* 204:
195194
* description: Device deleted successfully (no content)
@@ -219,9 +218,9 @@ router.delete("/:id", deleteDevice)
219218
* in: path
220219
* required: true
221220
* schema:
222-
* type: integer
223-
* format: int64
221+
* type: string
224222
* description: Device ID
223+
* example: "123"
225224
* responses:
226225
* 200:
227226
* description: Ring command sent (device online)

0 commit comments

Comments
 (0)