Skip to content

Commit

Permalink
Provide openapi 3.0.1 documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Sep 11, 2024
2 parents 7d4957e + af99ca2 commit 763e3b1
Show file tree
Hide file tree
Showing 9 changed files with 8,826 additions and 7,778 deletions.
23 changes: 23 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ services:
retries: 3
start_period: 10s

# Swagger UI
swagger-ui:
image: swaggerapi/swagger-ui
container_name: swagger-ui
networks:
- external_network
ports:
- 1325:8080
volumes:
# cb-tumblebug swagger.yaml mount
- ./src/api/rest/docs/swagger.yaml:/swagger.yaml
environment:
# Options: https://github.com/swagger-api/swagger-ui/blob/37b8c1a8b67200dd425216ab8f97b725a429a5c0/docs/usage/configuration.md#docker
- SWAGGER_JSON=/swagger.yaml
logging:
# Disable logging
driver: "none"
healthcheck:
test: [ "CMD", "curl", "-f", "localhost", "1325"]
timeout: 5s
retries: 3
start_period: 3s

# # cb-tumblebug-etcd-conf
# cb-tumblebug-etcd-conf:
# image: alpine:latest
Expand Down
30 changes: 30 additions & 0 deletions scripts/misc/convert-swagger-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

SWAGGER_FILE="$(dirname "$0")/../../src/api/rest/docs/swagger.yaml"
SWAGGER_FILE_v3="$SWAGGER_FILE"

echo "Converting Swagger 2.0 to 3.0.1..."

if [ ! -f "$SWAGGER_FILE" ]; then
echo "Error: $SWAGGER_FILE does not exist at $SWAGGER_FILE."
exit 1
fi

# Converting tool: https://converter.swagger.io/#/Converter/convertByContent
curl -X 'POST' \
'https://converter.swagger.io/api/convert' \
-H 'accept: application/yaml' \
-H 'Content-Type: application/yaml' \
--data-binary @"$SWAGGER_FILE" \
-o "$SWAGGER_FILE_v3"

if [ $? -eq 0 ]; then
echo "Conversion complete. Updated $SWAGGER_FILE_v3"

echo "Adding security section to the swagger.yaml file..."
echo -e "\nsecurity:\n - BasicAuth: []\n - Bearer: []" >> "$SWAGGER_FILE_v3"
echo "Security section added successfully."

else
echo "Conversion failed."
fi
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ clean:

swag swagger:
~/go/bin/swag i -o ./api/rest/docs
../scripts/misc/convert-swagger-version.sh
67 changes: 66 additions & 1 deletion src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9505,6 +9505,62 @@ const docTemplate = `{
}
}
},
"/testStreamResponse": {
"post": {
"description": "Receives a number and streams the decrementing number every second until zero",
"consumes": [
"application/json"
],
"produces": [
"application/x-json-stream"
],
"tags": [
"[Test] Stream Response"
],
"summary": "Stream response of a number decrement",
"operationId": "PostTestStreamResponse",
"parameters": [
{
"description": "Number input",
"name": "number",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/common.NumberRequest"
}
}
],
"responses": {
"200": {
"description": "currentNumber",
"schema": {
"type": "object",
"additionalProperties": {
"type": "integer"
}
}
},
"400": {
"description": "Invalid input",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": {
"description": "Stream failed",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/util/net/design": {
"post": {
"description": "Design a hierarchical network configuration of a VPC network or multi-cloud network consisting of multiple VPC networks",
Expand Down Expand Up @@ -9671,6 +9727,15 @@ const docTemplate = `{
"common.JSONResult": {
"type": "object"
},
"common.NumberRequest": {
"type": "object",
"properties": {
"number": {
"type": "integer",
"example": 100
}
}
},
"common.RequestDetails": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -14483,7 +14548,7 @@ const docTemplate = `{
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "latest",
Host: "",
Host: "localhost:1323",
BasePath: "/tumblebug",
Schemes: []string{},
Title: "CB-Tumblebug REST API",
Expand Down
66 changes: 66 additions & 0 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"version": "latest"
},
"host": "localhost:1323",
"basePath": "/tumblebug",
"paths": {
"/auth/test": {
Expand Down Expand Up @@ -9498,6 +9499,62 @@
}
}
},
"/testStreamResponse": {
"post": {
"description": "Receives a number and streams the decrementing number every second until zero",
"consumes": [
"application/json"
],
"produces": [
"application/x-json-stream"
],
"tags": [
"[Test] Stream Response"
],
"summary": "Stream response of a number decrement",
"operationId": "PostTestStreamResponse",
"parameters": [
{
"description": "Number input",
"name": "number",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/common.NumberRequest"
}
}
],
"responses": {
"200": {
"description": "currentNumber",
"schema": {
"type": "object",
"additionalProperties": {
"type": "integer"
}
}
},
"400": {
"description": "Invalid input",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": {
"description": "Stream failed",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/util/net/design": {
"post": {
"description": "Design a hierarchical network configuration of a VPC network or multi-cloud network consisting of multiple VPC networks",
Expand Down Expand Up @@ -9664,6 +9721,15 @@
"common.JSONResult": {
"type": "object"
},
"common.NumberRequest": {
"type": "object",
"properties": {
"number": {
"type": "integer",
"example": 100
}
}
},
"common.RequestDetails": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 763e3b1

Please sign in to comment.