You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

822 regels
22 KiB

  1. openapi: 3.0.3
  2. info:
  3. title: Presence API
  4. description: API for gateways, zones, trackers, parser configs, settings, alerts, and tracks.
  5. version: 1.0.0
  6. servers:
  7. - url: /
  8. description: Default server
  9. paths:
  10. # --- Health ---
  11. /health:
  12. get:
  13. summary: Liveness check
  14. operationId: health
  15. tags: [Health]
  16. responses:
  17. '200':
  18. description: Service is alive
  19. content:
  20. application/json:
  21. schema:
  22. type: object
  23. properties:
  24. status:
  25. type: string
  26. example: ok
  27. /ready:
  28. get:
  29. summary: Readiness check (DB connectivity)
  30. operationId: ready
  31. tags: [Health]
  32. responses:
  33. '200':
  34. description: Service is ready
  35. content:
  36. application/json:
  37. schema:
  38. type: object
  39. properties:
  40. status:
  41. type: string
  42. example: ready
  43. '503':
  44. $ref: '#/components/responses/ServiceUnavailable'
  45. # --- Gateways ---
  46. /reslevis/getGateways:
  47. get:
  48. summary: List all gateways
  49. operationId: getGateways
  50. tags: [Gateways]
  51. responses:
  52. '200':
  53. description: List of gateways
  54. content:
  55. application/json:
  56. schema:
  57. type: array
  58. items:
  59. $ref: '#/components/schemas/Gateway'
  60. '500':
  61. $ref: '#/components/responses/InternalError'
  62. /reslevis/postGateway:
  63. post:
  64. summary: Create a gateway
  65. operationId: postGateway
  66. tags: [Gateways]
  67. requestBody:
  68. required: true
  69. content:
  70. application/json:
  71. schema:
  72. $ref: '#/components/schemas/Gateway'
  73. responses:
  74. '201':
  75. description: Gateway created
  76. content:
  77. application/json:
  78. schema:
  79. $ref: '#/components/schemas/StatusCreated'
  80. '400':
  81. $ref: '#/components/responses/BadRequest'
  82. '500':
  83. $ref: '#/components/responses/InternalError'
  84. /reslevis/removeGateway/{id}:
  85. delete:
  86. summary: Delete a gateway by ID
  87. operationId: removeGateway
  88. tags: [Gateways]
  89. parameters:
  90. - $ref: '#/components/parameters/PathId'
  91. responses:
  92. '200':
  93. description: Gateway deleted
  94. content:
  95. application/json:
  96. schema:
  97. $ref: '#/components/schemas/StatusDeleted'
  98. '404':
  99. $ref: '#/components/responses/NotFound'
  100. '500':
  101. $ref: '#/components/responses/InternalError'
  102. /reslevis/updateGateway/{id}:
  103. put:
  104. summary: Update a gateway by ID
  105. operationId: updateGateway
  106. tags: [Gateways]
  107. parameters:
  108. - $ref: '#/components/parameters/PathId'
  109. requestBody:
  110. required: true
  111. content:
  112. application/json:
  113. schema:
  114. $ref: '#/components/schemas/Gateway'
  115. responses:
  116. '200':
  117. description: Gateway updated
  118. content:
  119. application/json:
  120. schema:
  121. $ref: '#/components/schemas/StatusUpdated'
  122. '400':
  123. $ref: '#/components/responses/BadRequest'
  124. '404':
  125. $ref: '#/components/responses/NotFound'
  126. '500':
  127. $ref: '#/components/responses/InternalError'
  128. # --- Zones ---
  129. /reslevis/getZones:
  130. get:
  131. summary: List all zones
  132. operationId: getZones
  133. tags: [Zones]
  134. responses:
  135. '200':
  136. description: List of zones
  137. content:
  138. application/json:
  139. schema:
  140. type: array
  141. items:
  142. $ref: '#/components/schemas/Zone'
  143. '500':
  144. $ref: '#/components/responses/InternalError'
  145. /reslevis/postZone:
  146. post:
  147. summary: Create a zone
  148. operationId: postZone
  149. tags: [Zones]
  150. requestBody:
  151. required: true
  152. content:
  153. application/json:
  154. schema:
  155. $ref: '#/components/schemas/Zone'
  156. responses:
  157. '201':
  158. description: Zone created
  159. content:
  160. application/json:
  161. schema:
  162. $ref: '#/components/schemas/StatusCreated'
  163. '400':
  164. $ref: '#/components/responses/BadRequest'
  165. '500':
  166. $ref: '#/components/responses/InternalError'
  167. /reslevis/removeZone/{id}:
  168. delete:
  169. summary: Delete a zone by ID
  170. operationId: removeZone
  171. tags: [Zones]
  172. parameters:
  173. - $ref: '#/components/parameters/PathId'
  174. responses:
  175. '200':
  176. description: Zone deleted
  177. content:
  178. application/json:
  179. schema:
  180. $ref: '#/components/schemas/StatusDeleted'
  181. '404':
  182. $ref: '#/components/responses/NotFound'
  183. '500':
  184. $ref: '#/components/responses/InternalError'
  185. /reslevis/updateZone:
  186. put:
  187. summary: Update a zone
  188. operationId: updateZone
  189. tags: [Zones]
  190. requestBody:
  191. required: true
  192. content:
  193. application/json:
  194. schema:
  195. $ref: '#/components/schemas/Zone'
  196. responses:
  197. '200':
  198. description: Zone updated
  199. content:
  200. application/json:
  201. schema:
  202. $ref: '#/components/schemas/StatusUpdated'
  203. '400':
  204. $ref: '#/components/responses/BadRequest'
  205. '404':
  206. $ref: '#/components/responses/NotFound'
  207. '500':
  208. $ref: '#/components/responses/InternalError'
  209. # --- Tracker zones ---
  210. /reslevis/getTrackerZones:
  211. get:
  212. summary: List all tracker zones
  213. operationId: getTrackerZones
  214. tags: [TrackerZones]
  215. responses:
  216. '200':
  217. description: List of tracker zones
  218. content:
  219. application/json:
  220. schema:
  221. type: array
  222. items:
  223. $ref: '#/components/schemas/TrackerZone'
  224. '500':
  225. $ref: '#/components/responses/InternalError'
  226. /reslevis/postTrackerZone:
  227. post:
  228. summary: Create a tracker zone
  229. operationId: postTrackerZone
  230. tags: [TrackerZones]
  231. requestBody:
  232. required: true
  233. content:
  234. application/json:
  235. schema:
  236. $ref: '#/components/schemas/TrackerZone'
  237. responses:
  238. '201':
  239. description: Tracker zone created
  240. content:
  241. application/json:
  242. schema:
  243. $ref: '#/components/schemas/StatusCreated'
  244. '400':
  245. $ref: '#/components/responses/BadRequest'
  246. '500':
  247. $ref: '#/components/responses/InternalError'
  248. /reslevis/removeTrackerZone/{id}:
  249. delete:
  250. summary: Delete a tracker zone by ID
  251. operationId: removeTrackerZone
  252. tags: [TrackerZones]
  253. parameters:
  254. - $ref: '#/components/parameters/PathId'
  255. responses:
  256. '200':
  257. description: Tracker zone deleted
  258. content:
  259. application/json:
  260. schema:
  261. $ref: '#/components/schemas/StatusDeleted'
  262. '404':
  263. $ref: '#/components/responses/NotFound'
  264. '500':
  265. $ref: '#/components/responses/InternalError'
  266. /reslevis/updateTrackerZone:
  267. put:
  268. summary: Update a tracker zone
  269. operationId: updateTrackerZone
  270. tags: [TrackerZones]
  271. requestBody:
  272. required: true
  273. content:
  274. application/json:
  275. schema:
  276. $ref: '#/components/schemas/TrackerZone'
  277. responses:
  278. '200':
  279. description: Tracker zone updated
  280. content:
  281. application/json:
  282. schema:
  283. $ref: '#/components/schemas/StatusUpdated'
  284. '400':
  285. $ref: '#/components/responses/BadRequest'
  286. '404':
  287. $ref: '#/components/responses/NotFound'
  288. '500':
  289. $ref: '#/components/responses/InternalError'
  290. # --- Trackers ---
  291. /reslevis/getTrackers:
  292. get:
  293. summary: List all trackers
  294. operationId: getTrackers
  295. tags: [Trackers]
  296. responses:
  297. '200':
  298. description: List of trackers
  299. content:
  300. application/json:
  301. schema:
  302. type: array
  303. items:
  304. $ref: '#/components/schemas/Tracker'
  305. '500':
  306. $ref: '#/components/responses/InternalError'
  307. /reslevis/postTracker:
  308. post:
  309. summary: Create a tracker
  310. operationId: postTracker
  311. tags: [Trackers]
  312. requestBody:
  313. required: true
  314. content:
  315. application/json:
  316. schema:
  317. $ref: '#/components/schemas/Tracker'
  318. responses:
  319. '201':
  320. description: Tracker created
  321. content:
  322. application/json:
  323. schema:
  324. $ref: '#/components/schemas/StatusCreated'
  325. '400':
  326. $ref: '#/components/responses/BadRequest'
  327. '500':
  328. $ref: '#/components/responses/InternalError'
  329. /reslevis/removeTracker/{id}:
  330. delete:
  331. summary: Delete a tracker by ID
  332. operationId: removeTracker
  333. tags: [Trackers]
  334. parameters:
  335. - $ref: '#/components/parameters/PathId'
  336. responses:
  337. '200':
  338. description: Tracker deleted
  339. content:
  340. application/json:
  341. schema:
  342. $ref: '#/components/schemas/StatusDeleted'
  343. '404':
  344. $ref: '#/components/responses/NotFound'
  345. '500':
  346. $ref: '#/components/responses/InternalError'
  347. /reslevis/updateTracker:
  348. put:
  349. summary: Update a tracker
  350. operationId: updateTracker
  351. tags: [Trackers]
  352. requestBody:
  353. required: true
  354. content:
  355. application/json:
  356. schema:
  357. $ref: '#/components/schemas/Tracker'
  358. responses:
  359. '200':
  360. description: Tracker updated
  361. content:
  362. application/json:
  363. schema:
  364. $ref: '#/components/schemas/StatusUpdated'
  365. '400':
  366. $ref: '#/components/responses/BadRequest'
  367. '404':
  368. $ref: '#/components/responses/NotFound'
  369. '500':
  370. $ref: '#/components/responses/InternalError'
  371. # --- Parser configs (beacons) ---
  372. /configs/beacons:
  373. get:
  374. summary: List all beacon parser configs
  375. operationId: listParserConfigs
  376. tags: [ParserConfigs]
  377. responses:
  378. '200':
  379. description: List of parser configs
  380. content:
  381. application/json:
  382. schema:
  383. type: array
  384. items:
  385. $ref: '#/components/schemas/ParserConfig'
  386. '500':
  387. $ref: '#/components/responses/InternalError'
  388. post:
  389. summary: Create a beacon parser config
  390. operationId: addParserConfig
  391. tags: [ParserConfigs]
  392. requestBody:
  393. required: true
  394. content:
  395. application/json:
  396. schema:
  397. $ref: '#/components/schemas/ParserConfig'
  398. responses:
  399. '201':
  400. description: Parser config created
  401. content:
  402. application/json:
  403. schema:
  404. $ref: '#/components/schemas/StatusCreated'
  405. '400':
  406. $ref: '#/components/responses/BadRequest'
  407. '500':
  408. $ref: '#/components/responses/InternalError'
  409. /configs/beacons/{id}:
  410. put:
  411. summary: Update a beacon parser config by name (id)
  412. operationId: updateParserConfig
  413. tags: [ParserConfigs]
  414. parameters:
  415. - name: id
  416. in: path
  417. required: true
  418. description: Config name (identifier)
  419. schema:
  420. type: string
  421. requestBody:
  422. required: true
  423. content:
  424. application/json:
  425. schema:
  426. $ref: '#/components/schemas/ParserConfig'
  427. responses:
  428. '200':
  429. description: Parser config updated
  430. content:
  431. application/json:
  432. schema:
  433. $ref: '#/components/schemas/StatusUpdated'
  434. '400':
  435. $ref: '#/components/responses/BadRequest'
  436. '404':
  437. $ref: '#/components/responses/NotFound'
  438. '500':
  439. $ref: '#/components/responses/InternalError'
  440. delete:
  441. summary: Delete a beacon parser config by name (id)
  442. operationId: deleteParserConfig
  443. tags: [ParserConfigs]
  444. parameters:
  445. - name: id
  446. in: path
  447. required: true
  448. description: Config name (identifier)
  449. schema:
  450. type: string
  451. responses:
  452. '200':
  453. description: Parser config deleted
  454. content:
  455. application/json:
  456. schema:
  457. $ref: '#/components/schemas/StatusDeleted'
  458. '404':
  459. $ref: '#/components/responses/NotFound'
  460. '500':
  461. $ref: '#/components/responses/InternalError'
  462. # --- Settings ---
  463. /reslevis/settings:
  464. get:
  465. summary: List settings
  466. operationId: getSettings
  467. tags: [Settings]
  468. responses:
  469. '200':
  470. description: List of settings (typically one row)
  471. content:
  472. application/json:
  473. schema:
  474. type: array
  475. items:
  476. $ref: '#/components/schemas/Settings'
  477. '500':
  478. $ref: '#/components/responses/InternalError'
  479. patch:
  480. summary: Partially update settings
  481. operationId: updateSettings
  482. tags: [Settings]
  483. requestBody:
  484. required: true
  485. content:
  486. application/json:
  487. schema:
  488. $ref: '#/components/schemas/SettingsUpdate'
  489. responses:
  490. '200':
  491. description: Settings updated
  492. content:
  493. application/json:
  494. schema:
  495. $ref: '#/components/schemas/StatusUpdated'
  496. '400':
  497. $ref: '#/components/responses/BadRequest'
  498. '500':
  499. $ref: '#/components/responses/InternalError'
  500. # --- Alerts ---
  501. /reslevis/alerts:
  502. get:
  503. summary: List all alerts
  504. operationId: listAlerts
  505. tags: [Alerts]
  506. responses:
  507. '200':
  508. description: List of alerts
  509. content:
  510. application/json:
  511. schema:
  512. type: array
  513. items:
  514. $ref: '#/components/schemas/Alert'
  515. '500':
  516. $ref: '#/components/responses/InternalError'
  517. /reslevis/alerts/{id}:
  518. get:
  519. summary: Get alert by ID (or tracker ID depending on usage)
  520. operationId: getAlertById
  521. tags: [Alerts]
  522. parameters:
  523. - $ref: '#/components/parameters/PathId'
  524. responses:
  525. '200':
  526. description: Single alert
  527. content:
  528. application/json:
  529. schema:
  530. $ref: '#/components/schemas/Alert'
  531. '404':
  532. $ref: '#/components/responses/NotFound'
  533. '500':
  534. $ref: '#/components/responses/InternalError'
  535. delete:
  536. summary: Delete alert by ID
  537. operationId: deleteAlert
  538. tags: [Alerts]
  539. parameters:
  540. - $ref: '#/components/parameters/PathId'
  541. responses:
  542. '200':
  543. description: Alert deleted
  544. content:
  545. application/json:
  546. schema:
  547. $ref: '#/components/schemas/StatusDeleted'
  548. '500':
  549. $ref: '#/components/responses/InternalError'
  550. # --- Tracks ---
  551. /reslevis/getTracks/{id}:
  552. get:
  553. summary: List tracks for a tracker UUID
  554. operationId: getTracks
  555. tags: [Tracks]
  556. parameters:
  557. - name: id
  558. in: path
  559. required: true
  560. description: Tracker UUID
  561. schema:
  562. type: string
  563. - name: limit
  564. in: query
  565. description: Max number of tracks to return (default 10)
  566. schema:
  567. type: integer
  568. default: 10
  569. - name: from
  570. in: query
  571. description: Start time (RFC3339)
  572. schema:
  573. type: string
  574. format: date-time
  575. - name: to
  576. in: query
  577. description: End time (RFC3339)
  578. schema:
  579. type: string
  580. format: date-time
  581. responses:
  582. '200':
  583. description: List of tracks
  584. content:
  585. application/json:
  586. schema:
  587. type: array
  588. items:
  589. $ref: '#/components/schemas/Track'
  590. '500':
  591. $ref: '#/components/responses/InternalError'
  592. components:
  593. parameters:
  594. PathId:
  595. name: id
  596. in: path
  597. required: true
  598. description: Resource ID
  599. schema:
  600. type: string
  601. responses:
  602. BadRequest:
  603. description: Invalid request (e.g. invalid JSON)
  604. content:
  605. application/json:
  606. schema:
  607. $ref: '#/components/schemas/Error'
  608. example:
  609. error: bad_request
  610. message: invalid request body
  611. NotFound:
  612. description: Resource not found
  613. content:
  614. application/json:
  615. schema:
  616. $ref: '#/components/schemas/Error'
  617. example:
  618. error: not_found
  619. message: resource not found
  620. InternalError:
  621. description: Internal server error
  622. content:
  623. application/json:
  624. schema:
  625. $ref: '#/components/schemas/Error'
  626. example:
  627. error: internal_error
  628. message: failed to complete operation
  629. ServiceUnavailable:
  630. description: Service not ready (e.g. DB unavailable)
  631. content:
  632. application/json:
  633. schema:
  634. $ref: '#/components/schemas/Error'
  635. example:
  636. error: not_ready
  637. message: database not available
  638. schemas:
  639. Error:
  640. type: object
  641. required: [error]
  642. properties:
  643. error:
  644. type: string
  645. description: Error code (bad_request, not_found, internal_error, not_ready)
  646. message:
  647. type: string
  648. description: Human-readable message
  649. StatusCreated:
  650. type: object
  651. properties:
  652. status:
  653. type: string
  654. example: created
  655. StatusUpdated:
  656. type: object
  657. properties:
  658. status:
  659. type: string
  660. example: updated
  661. StatusDeleted:
  662. type: object
  663. properties:
  664. status:
  665. type: string
  666. example: deleted
  667. Gateway:
  668. type: object
  669. properties:
  670. id: { type: string }
  671. name: { type: string }
  672. mac: { type: string }
  673. status: { type: string }
  674. model: { type: string }
  675. ip: { type: string }
  676. position: { type: string }
  677. x: { type: number, format: float }
  678. y: { type: number, format: float }
  679. notes: { type: string }
  680. floor: { type: string }
  681. building: { type: string }
  682. Zone:
  683. type: object
  684. properties:
  685. id: { type: string }
  686. name: { type: string }
  687. groups:
  688. type: array
  689. items: { type: string }
  690. floor: { type: string }
  691. building: { type: string }
  692. TrackerZone:
  693. type: object
  694. properties:
  695. id: { type: string }
  696. zoneList:
  697. type: array
  698. items: { type: string }
  699. tracker: { type: string }
  700. days: { type: string }
  701. time: { type: string }
  702. Tracker:
  703. type: object
  704. properties:
  705. id: { type: string }
  706. name: { type: string }
  707. mac: { type: string }
  708. status: { type: string }
  709. model: { type: string }
  710. ip: { type: string }
  711. position: { type: string }
  712. x: { type: number, format: float }
  713. y: { type: number, format: float }
  714. notes: { type: string }
  715. floor: { type: string }
  716. building: { type: string }
  717. battery: { type: integer }
  718. batteryThreshold: { type: integer }
  719. temperature: { type: integer }
  720. ParserConfig:
  721. type: object
  722. description: Beacon parser configuration (name is the primary key)
  723. properties:
  724. name: { type: string }
  725. min: { type: integer }
  726. max: { type: integer }
  727. pattern:
  728. type: array
  729. items: { type: string }
  730. configs:
  731. type: object
  732. additionalProperties:
  733. $ref: '#/components/schemas/ParserConfigEntry'
  734. ParserConfigEntry:
  735. type: object
  736. properties:
  737. length: { type: integer }
  738. offset: { type: integer }
  739. order: { type: string }
  740. Settings:
  741. type: object
  742. properties:
  743. ID: { type: integer }
  744. current_algorithm: { type: string }
  745. location_confidence: { type: integer }
  746. last_seen_threshold: { type: integer }
  747. beacon_metric_size: { type: integer }
  748. HA_send_interval: { type: integer }
  749. HA_send_changes_only: { type: boolean }
  750. RSSI_enforce_threshold: { type: boolean }
  751. RSSI_min_threshold: { type: integer }
  752. SettingsUpdate:
  753. type: object
  754. description: Partial update; only provided fields are updated
  755. additionalProperties: true
  756. Alert:
  757. type: object
  758. properties:
  759. id: { type: string }
  760. tracker_id: { type: string }
  761. type: { type: string }
  762. value: { type: string }
  763. Track:
  764. type: object
  765. properties:
  766. id: { type: string }
  767. timestamp: { type: string, format: date-time }
  768. type: { type: string }
  769. status: { type: string }
  770. gateway: { type: string }
  771. gatewayMac: { type: string }
  772. tracker: { type: string }
  773. trackerMac: { type: string }
  774. subject: { type: string }
  775. subjectName: { type: string }
  776. floor: { type: string }
  777. signal: { type: integer }
  778. building: { type: string }