From 0b57f26688e6ff8268c1f15de6619b7e29e1392c Mon Sep 17 00:00:00 2001 From: Klagarge Date: Tue, 15 Apr 2025 00:26:05 +0200 Subject: [PATCH] docs(gateway): updated swagger doc Signed-off-by: Klagarge --- docker-compose.yml | 2 + gateway/src/Connection.go | 4 +- gateway/src/docs/docs.go | 185 +++++++++++++++++++++++++++++++++- gateway/src/docs/swagger.json | 185 +++++++++++++++++++++++++++++++++- gateway/src/docs/swagger.yaml | 124 ++++++++++++++++++++++- 5 files changed, 495 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5861150..b4f056c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,8 @@ services: image: registry.forge.hefr.ch/team-raclette/project-softweng/gateway:latest container_name: gateway restart: unless-stopped + ports: + - "8080:8080" environment: - INFLUXDB_TOKEN=$INFLUXDB_TOKEN - INFLUXDB_ORG=$INFLUXDB_ORG diff --git a/gateway/src/Connection.go b/gateway/src/Connection.go index 66ab1d4..251edc2 100644 --- a/gateway/src/Connection.go +++ b/gateway/src/Connection.go @@ -119,8 +119,8 @@ func (gh *Gateway) createMQTTGateway() error { // Get env variables and set default values if not set MQTT_URL, ok := os.LookupEnv("MQTT_URL") if !ok { - log.Error("MQTT_URL not set, using default value: tcp://mqtt.mse.kb28.ch:1883") - MQTT_URL = "tcp://mqtt.mse.kb28.ch:1883" + log.Error("MQTT_URL not set, using default value: mqtt://mqtt.mse.kb28.ch:1883") + MQTT_URL = "mqtt://mqtt.mse.kb28.ch:1883" } CLIENT_ID, ok := os.LookupEnv("CLIENT_ID") diff --git a/gateway/src/docs/docs.go b/gateway/src/docs/docs.go index a59ee16..7132925 100644 --- a/gateway/src/docs/docs.go +++ b/gateway/src/docs/docs.go @@ -14,7 +14,190 @@ const docTemplate = `{ }, "host": "{{.Host}}", "basePath": "{{.BasePath}}", - "paths": {}, + "paths": { + "/ping": { + "get": { + "description": "get ping response", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ping" + ], + "summary": "Ping test endpoint", + "responses": { + "200": { + "description": "pong", + "schema": { + "type": "string" + } + } + } + } + }, + "/raclette": { + "get": { + "security": [ + { + "BasicAuth": [] + } + ], + "description": "Request data from InfluxDB for a specific device in a room", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "request" + ], + "summary": "Request Influx data", + "parameters": [ + { + "type": "string", + "example": "Garage", + "description": "Room name", + "name": "room", + "in": "query", + "required": true + }, + { + "type": "string", + "example": "Door", + "description": "Device name", + "name": "device", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Returns a map of field names to their latest values.", + "schema": { + "$ref": "#/definitions/main.GarageDoorExample" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/gin.H" + } + } + } + }, + "post": { + "security": [ + { + "BasicAuth": [] + } + ], + "description": "Publish a command to a specific device in a room", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "commands" + ], + "summary": "Publish command", + "parameters": [ + { + "type": "string", + "example": "Garage", + "description": "Room name", + "name": "room", + "in": "query", + "required": true + }, + { + "type": "string", + "example": "Door", + "description": "Device name", + "name": "device", + "in": "query", + "required": true + }, + { + "description": "Command to publish", + "name": "command", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/main.Command" + } + } + ], + "responses": { + "200": { + "description": "status:ok", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/gin.H" + } + } + } + } + } + }, + "definitions": { + "gin.H": { + "type": "object", + "additionalProperties": {} + }, + "main.Command": { + "description": "Command structure for publishing", + "type": "object", + "required": [ + "command" + ], + "properties": { + "command": { + "type": "string", + "example": "UP" + } + } + }, + "main.GarageDoorExample": { + "description": "Example response for Garage Door status", + "type": "object", + "properties": { + "IsClosed": { + "description": "example: true", + "type": "boolean" + }, + "IsDownButtonPressed": { + "description": "example: false", + "type": "boolean" + }, + "IsIRSensor": { + "description": "example: false", + "type": "boolean" + }, + "IsOpen": { + "description": "example: false", + "type": "boolean" + }, + "IsUpButtonPressed": { + "description": "example: false", + "type": "boolean" + } + } + } + }, "securityDefinitions": { "BasicAuth": { "type": "basic" diff --git a/gateway/src/docs/swagger.json b/gateway/src/docs/swagger.json index daa2dbf..72ac85f 100644 --- a/gateway/src/docs/swagger.json +++ b/gateway/src/docs/swagger.json @@ -8,7 +8,190 @@ }, "host": "rest.mse.kb28.ch", "basePath": "/", - "paths": {}, + "paths": { + "/ping": { + "get": { + "description": "get ping response", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "ping" + ], + "summary": "Ping test endpoint", + "responses": { + "200": { + "description": "pong", + "schema": { + "type": "string" + } + } + } + } + }, + "/raclette": { + "get": { + "security": [ + { + "BasicAuth": [] + } + ], + "description": "Request data from InfluxDB for a specific device in a room", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "request" + ], + "summary": "Request Influx data", + "parameters": [ + { + "type": "string", + "example": "Garage", + "description": "Room name", + "name": "room", + "in": "query", + "required": true + }, + { + "type": "string", + "example": "Door", + "description": "Device name", + "name": "device", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Returns a map of field names to their latest values.", + "schema": { + "$ref": "#/definitions/main.GarageDoorExample" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/gin.H" + } + } + } + }, + "post": { + "security": [ + { + "BasicAuth": [] + } + ], + "description": "Publish a command to a specific device in a room", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "commands" + ], + "summary": "Publish command", + "parameters": [ + { + "type": "string", + "example": "Garage", + "description": "Room name", + "name": "room", + "in": "query", + "required": true + }, + { + "type": "string", + "example": "Door", + "description": "Device name", + "name": "device", + "in": "query", + "required": true + }, + { + "description": "Command to publish", + "name": "command", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/main.Command" + } + } + ], + "responses": { + "200": { + "description": "status:ok", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/gin.H" + } + } + } + } + } + }, + "definitions": { + "gin.H": { + "type": "object", + "additionalProperties": {} + }, + "main.Command": { + "description": "Command structure for publishing", + "type": "object", + "required": [ + "command" + ], + "properties": { + "command": { + "type": "string", + "example": "UP" + } + } + }, + "main.GarageDoorExample": { + "description": "Example response for Garage Door status", + "type": "object", + "properties": { + "IsClosed": { + "description": "example: true", + "type": "boolean" + }, + "IsDownButtonPressed": { + "description": "example: false", + "type": "boolean" + }, + "IsIRSensor": { + "description": "example: false", + "type": "boolean" + }, + "IsOpen": { + "description": "example: false", + "type": "boolean" + }, + "IsUpButtonPressed": { + "description": "example: false", + "type": "boolean" + } + } + } + }, "securityDefinitions": { "BasicAuth": { "type": "basic" diff --git a/gateway/src/docs/swagger.yaml b/gateway/src/docs/swagger.yaml index c50f85b..a26f015 100644 --- a/gateway/src/docs/swagger.yaml +++ b/gateway/src/docs/swagger.yaml @@ -1,11 +1,133 @@ basePath: / +definitions: + gin.H: + additionalProperties: {} + type: object + main.Command: + description: Command structure for publishing + properties: + command: + example: UP + type: string + required: + - command + type: object + main.GarageDoorExample: + description: Example response for Garage Door status + properties: + IsClosed: + description: 'example: true' + type: boolean + IsDownButtonPressed: + description: 'example: false' + type: boolean + IsIRSensor: + description: 'example: false' + type: boolean + IsOpen: + description: 'example: false' + type: boolean + IsUpButtonPressed: + description: 'example: false' + type: boolean + type: object host: rest.mse.kb28.ch info: contact: {} description: REST API for the SoftwEng course in MSE title: Swagger SoftwEng API version: "1.0" -paths: {} +paths: + /ping: + get: + consumes: + - application/json + description: get ping response + produces: + - application/json + responses: + "200": + description: pong + schema: + type: string + summary: Ping test endpoint + tags: + - ping + /raclette: + get: + consumes: + - application/json + description: Request data from InfluxDB for a specific device in a room + parameters: + - description: Room name + example: Garage + in: query + name: room + required: true + type: string + - description: Device name + example: Door + in: query + name: device + required: true + type: string + produces: + - application/json + responses: + "200": + description: Returns a map of field names to their latest values. + schema: + $ref: '#/definitions/main.GarageDoorExample' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/gin.H' + security: + - BasicAuth: [] + summary: Request Influx data + tags: + - request + post: + consumes: + - application/json + description: Publish a command to a specific device in a room + parameters: + - description: Room name + example: Garage + in: query + name: room + required: true + type: string + - description: Device name + example: Door + in: query + name: device + required: true + type: string + - description: Command to publish + in: body + name: command + required: true + schema: + $ref: '#/definitions/main.Command' + produces: + - application/json + responses: + "200": + description: status:ok + schema: + additionalProperties: + type: string + type: object + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/gin.H' + security: + - BasicAuth: [] + summary: Publish command + tags: + - commands securityDefinitions: BasicAuth: type: basic