Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger docs #892

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a3d2f1b
docs(swagger): Add initial Swagger infrastructure
depau May 4, 2021
24ee78e
docs(swagger): Add @swagger defs for ValetudoRouter
depau May 4, 2021
10fd1f4
docs(swagger): gitignore swagger.json
depau May 4, 2021
159b6a2
docs: Generate swagger on build_docs
depau May 4, 2021
e6fe807
docs(swagger): Generate swagger.json into main back-end res
depau May 4, 2021
61b5ade
docs(swagger): Add Swagger UI
depau May 4, 2021
e17c858
docs(swagger): Add @swagger definitions for WebServer.js
depau May 4, 2021
d54ae7a
docs(swagger): Add @swagger definitions for robot router
depau May 4, 2021
c79a291
docs(swagger): Add swagger definitions for capabilities router
depau May 4, 2021
d5ed40d
docs(swagger): Add swagger definitions for BasicControlCapability
depau May 4, 2021
50757c6
docs(swagger): Add swagger definitions for PresetSelectionCapability
depau May 4, 2021
f85324a
docs(swagger): Add swagger definitions for WifiConfigurationCapability
depau May 4, 2021
fdc6cea
fix(swagger): Only log actual error messages
depau May 4, 2021
44b3251
docs(swagger): Add state property for WiFiConfigurationCapability
depau May 4, 2021
5e4d52f
docs(swagger): Add swagger definitions for ZoneCleaningCapability
depau May 4, 2021
aa2630c
docs(swagger): Add initial swagger.json to make the CI not fail
depau May 4, 2021
e8cf775
docs(swagger): Add swagger definitions for MapSegmentationCapability
depau May 4, 2021
306f190
docs(swagger): Add swagger definitions for ManualControlCapability
depau May 4, 2021
5e4def9
docs(swagger): Add swagger definitions for DoNotDisturbCapability
depau May 4, 2021
4f5c6a4
docs(swagger): Add base schema for StateAttribute
depau May 4, 2021
6387d0e
docs(swagger): Add swagger definitions for ConsumableMonitoringCapabi…
depau May 4, 2021
f98f077
docs(swagger): Add swagger definitions for LocateCapability
depau May 4, 2021
5125589
docs(swagger): Add swagger definitions for GoToLocationCapability
depau May 4, 2021
848c4e9
docs(swagger): Add swagger definitions for CarpetModeControlCapability
depau May 4, 2021
b5edcef
docs(swagger): Add swagger definitions for CombinedVirtualRestriction…
depau May 4, 2021
d95847b
docs(swagger): Add swagger definitions for MapResetCapability
depau May 4, 2021
7405713
docs(swagger): Add swagger definitions for MapSegmentEditCapability
depau May 4, 2021
e3850e8
docs(swagger): Add swagger definitions for MapSegmentRenameCapability
depau May 4, 2021
cd8431c
docs(swagger): Add swagger definitions for MapSnapshotCapability
depau May 4, 2021
60a6007
docs(swagger): Add swagger definitions for PersistentMapControlCapabi…
depau May 4, 2021
eab027f
docs(swagger): Add swagger definitions for SensorCalibrationCapability
depau May 4, 2021
7f03cf3
docs(swagger): Add swagger definitions for SpeakerTestCapability
depau May 4, 2021
b20b3c3
docs(swagger): Add swagger definitions for SpeakerVolumeControlCapabi…
depau May 4, 2021
72971a9
docs(swagger): Add swagger definitions for VoicePackManagementCapability
depau May 4, 2021
e005f53
docs(swagger): Fix syntax issue for optional path params
depau May 4, 2021
b2a1c22
docs(swagger): Rename SizeDTO to CoordinateDTO
depau May 4, 2021
24ca614
docs(swagger): Remove swagger.json
depau May 4, 2021
28ff086
docs(swagger): Generate Swagger as part of all builds
depau May 4, 2021
02f4e73
fix(ci): Build swagger before ts-check
depau May 4, 2021
53315c3
docs(swagger): Add description for CombinedVirtualRestrictionsCapability
depau May 4, 2021
418d98f
docs(swagger): Fix issues spotted by the Swagger editor
depau May 4, 2021
44678e4
docs(swagger): Allow providing HTTP basic auth
depau May 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"eol-last": ["error", "always"],
"jsdoc/check-alignment": "error",
"jsdoc/check-param-names": "error",
"jsdoc/check-tag-names": "error",
"jsdoc/check-tag-names": ["error", { "definedTags": ["swagger"] }],
"jsdoc/check-types": "error",
"jsdoc/implements-on-classes": "error",
"jsdoc/newline-after-description": "error",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@

# IntelliJ Idea project files
/.idea/

# Swagger docs
/lib/res/swagger.json
47 changes: 47 additions & 0 deletions lib/entities/core/ValetudoWifiConfiguration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
const SerializableEntity = require("../SerializableEntity");

/**
* @swagger
* components:
* schemas:
* ValetudoWifiConfiguration:
* type: object
* properties:
* ssid:
* type: string
* description: "Wireless network name"
* credentials:
* type: object
* properties:
* type:
* type: string
* typeSpecificSettings:
* type: object
* description: "Settings depending on type, for example WPA preshared key"
* details:
* type: object
* properties:
* state:
* type: string
* enum:
* - connected
* - not_connected
* - unknown
* downspeed:
* type: number
* upspeed:
* type: number
* signal:
* type: number
* ips:
* type: array
* description: "IP addresses"
* items:
* type: string
* frequency:
* type: string
* enum:
* - 2.4ghz
* - 5ghz
* metaData:
* type: object
*
*/

// noinspection JSCheckFunctionSignatures
class ValetudoWifiConfiguration extends SerializableEntity {
Expand Down
23 changes: 23 additions & 0 deletions lib/entities/core/ValetudoZone.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
const SerializableEntity = require("../SerializableEntity");

/**
* @swagger
* components:
* schemas:
* ValetudoZone:
* type: object
* properties:
* iterations:
* type: number
* points:
* type: object
* properties:
* pA:
* $ref: "#/components/schemas/SizeDTO"
* pB:
* $ref: "#/components/schemas/SizeDTO"
* pC:
* $ref: "#/components/schemas/SizeDTO"
* pD:
* $ref: "#/components/schemas/SizeDTO"
* metaData:
* type: object
*/

// noinspection JSCheckFunctionSignatures
class ValetudoZone extends SerializableEntity {
Expand Down
19 changes: 18 additions & 1 deletion lib/entities/core/ValetudoZonePreset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
const SerializableEntity = require("../SerializableEntity");
const uuid = require("uuid");


/**
* @swagger
* components:
* schemas:
* ValetudoZonePreset:
* type: object
* properties:
* name:
* type: string
* id:
* type: string
* metaData:
* type: object
* zones:
* type: array
* items:
* $ref: "#/components/schemas/ValetudoZone"
*/
// noinspection JSCheckFunctionSignatures
class ValetudoZonePreset extends SerializableEntity {
/**
Expand Down
22 changes: 22 additions & 0 deletions lib/entities/map/ValetudoMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ const ValetudoMapSegment = require("../core/ValetudoMapSegment");
* The origin is found on the top-left corner
*
*/
// TODO: add Swagger JSON schemas for children
/**
* @swagger
* components:
* schemas:
* ValetudoMap:
* type: object
* properties:
* size:
* $ref: "#/components/schemas/SizeDTO"
* pixelSize:
* type: integer
* layers:
* type: array
* entities:
* type: array
* metaData:
* type: object
* properties:
* version:
* type: number
*/
class ValetudoMap extends SerializableEntity { //TODO: Current, Historic, Etc.
/**
*
Expand Down
1 change: 1 addition & 0 deletions lib/res/swagger.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions lib/webserver/CapabilitiesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ class CapabilitiesRouter {


initRoutes() {
/**
* @swagger
* /api/v2/robot/capabilities:
* get:
* tags:
* - robot
* summary: Get robot supported capabilities
* responses:
* 200:
* description: Ok
* content:
* application/json:
* schema:
* type: array
* items:
* type: string
* description: "Capability class name"
*/
this.router.get("/", (req, res) => {
res.json(Object.values(this.robot.capabilities).map(c => c.getType()));
});
Expand Down
140 changes: 138 additions & 2 deletions lib/webserver/RobotRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ class RobotRouter {


initRoutes() {
/**
* @swagger
* /api/v2/robot:
* get:
* tags:
* - robot
* summary: Get robot info
* responses:
* 200:
* description: Ok
* content:
* application/json:
* schema:
* type: object
* properties:
* manufacturer:
* type: string
* modelName:
* type: string
* implementation:
* type: string
* description: "Valetudo robot implementation in use"
*/
this.router.get("/", (req, res) => {
res.json({
manufacturer: this.robot.getManufacturer(),
Expand All @@ -32,6 +55,26 @@ class RobotRouter {
});
});

/**
* @swagger
* /api/v2/robot/state:
* get:
* tags:
* - robot
* summary: Get robot state
* description: |
* Retrieve the robot state.
*
* Note! If the map is available, trying this out on Swagger will likely **use lots of RAM and hang your
* browser tab.**
* responses:
* 200:
* description: Ok
* content:
* application/json:
* schema:
* type: object
*/
this.router.get("/state", async (req, res) => {
try {
const polledState = await this.robot.pollState();
Expand All @@ -42,6 +85,23 @@ class RobotRouter {
}
});


// TODO: add Swagger JSON schemas for state attributes
/**
* @swagger
* /api/v2/robot/state/attributes:
* get:
* tags:
* - robot
* summary: Get robot state attributes
* responses:
* 200:
* description: Ok
* content:
* application/json:
* schema:
* type: object
*/
this.router.get("/state/attributes", async (req, res) => {
try {
const polledState = await this.robot.pollState();
Expand All @@ -52,6 +112,26 @@ class RobotRouter {
}
});

/**
* @swagger
* /api/v2/robot/state/map:
* get:
* tags:
* - robot
* summary: Get robot map
* description: |
* Retrieve the robot map.
*
* Note! If the map is available, trying this out on Swagger will likely **use lots of RAM and hang your
* browser tab.**
* responses:
* 200:
* description: Ok
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/ValetudoMap"
*/
this.router.get("/state/map", async (req, res) => {
try {
const polledState = await this.robot.pollState();
Expand All @@ -62,8 +142,6 @@ class RobotRouter {
}
});



this.router.use("/capabilities/", new CapabilitiesRouter({
robot: this.robot,
enableDebugCapability: this.enableDebugCapability
Expand All @@ -89,6 +167,25 @@ class RobotRouter {
this.sseHubs.map.event(ValetudoRobot.EVENTS.MapUpdated, this.robot.state.map);
});

/**
* @swagger
* /api/v2/robot/state/sse:
* get:
* tags:
* - robot
* summary: Get robot state (SSE events)
* description: |
* Retrieve the robot state.
*
* Note! This endpoint provides SSE events. Swagger does not support it.
* responses:
* 200:
* description: Ok
* content:
* text/event-stream:
* schema:
* type: object
*/
this.router.get(
"/state/sse",
sseHub({hub: this.sseHubs.state, flushAfterWrite: true}),
Expand All @@ -97,6 +194,25 @@ class RobotRouter {
}
);

/**
* @swagger
* /api/v2/robot/state/attributes/sse:
* get:
* tags:
* - robot
* summary: Get robot state attributes (SSE events)
* description: |
* Retrieve the robot state attributes.
*
* Note! This endpoint provides SSE events. Swagger does not support it.
* responses:
* 200:
* description: Ok
* content:
* text/event-stream:
* schema:
* type: object
*/
this.router.get(
"/state/attributes/sse",
sseHub({hub: this.sseHubs.attributes, flushAfterWrite: true}),
Expand All @@ -105,6 +221,26 @@ class RobotRouter {
}
);


/**
* @swagger
* /api/v2/robot/state/map/sse:
* get:
* tags:
* - robot
* summary: Get robot map (SSE events)
* description: |
* Retrieve the robot map
*
* Note! This endpoint provides SSE events. Swagger does not support it.
* responses:
* 200:
* description: Ok
* content:
* text/event-stream:
* schema:
* $ref: "#/components/schemas/ValetudoMap"
*/
this.router.get(
"/state/map/sse",
sseHub({hub: this.sseHubs.map, flushAfterWrite: true}),
Expand Down
Loading