Skip to content

Commit

Permalink
Add auto spec generation for swagger endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jpahm committed Oct 28, 2024
1 parent b5d2a92 commit 26a697f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
16 changes: 15 additions & 1 deletion api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,20 @@ const docTemplate = `{
}
}
}
},
"/swagger/index.html": {
"get": {
"description": "Returns the OpenAPI/swagger spec for the API",
"produces": [
"text/html"
],
"operationId": "swagger",
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -926,7 +940,7 @@ var SwaggerInfo = &swag.Spec{
Version: "0.1.0",
Host: "nebula-api-2lntm5dxoflqn.apigateway.nebula-api-368223.cloud.goog",
BasePath: "",
Schemes: []string{"http"},
Schemes: []string{"http", "https"},
Title: "nebula-api",
Description: "The public Nebula Labs API for access to pertinent UT Dallas data",
InfoInstanceName: "swagger",
Expand Down
17 changes: 16 additions & 1 deletion api/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"schemes": [
"http"
"http",
"https"
],
"swagger": "2.0",
"info": {
Expand Down Expand Up @@ -588,6 +589,20 @@
}
}
}
},
"/swagger/index.html": {
"get": {
"description": "Returns the OpenAPI/swagger spec for the API",
"produces": [
"text/html"
],
"operationId": "swagger",
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"definitions": {
Expand Down
10 changes: 10 additions & 0 deletions api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,18 @@ paths:
description: A section
schema:
$ref: '#/definitions/schema.Section'
/swagger/index.html:
get:
description: Returns the OpenAPI/swagger spec for the API
operationId: swagger
produces:
- text/html
responses:
"200":
description: OK
schemes:
- http
- https
security:
- api_key: []
securityDefinitions:
Expand Down
13 changes: 12 additions & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import (
ginSwagger "github.com/swaggo/gin-swagger"
)

// @Id swagger
// @Router /swagger/index.html [get]
// @Description Returns the OpenAPI/swagger spec for the API
// @Produce text/html
// @Success 200
func swagger_controller_placeholder() {}

// @title nebula-api
// @description The public Nebula Labs API for access to pertinent UT Dallas data
// @version 0.1.0
// @host nebula-api-2lntm5dxoflqn.apigateway.nebula-api-368223.cloud.goog
// @schemes http
// @schemes http https
// @x-google-backend {"address": "REDACTED"}
// @x-google-endpoints [{"name": "nebula-api-2lntm5dxoflqn.apigateway.nebula-api-368223.cloud.goog", "allowCors": true}]
// @x-google-management {"metrics": [{"name": "read-requests", "displayName": "Read Requests CUSTOM", "valueType": "INT64", "metricKind": "DELTA"}], "quota": {"limits": [{"name": "read-limit", "metric": "read-requests", "unit": "1/min/{project}", "values": {"STANDARD": 1000}}]}}
Expand All @@ -24,6 +31,10 @@ import (
// @name x-api-key
// @in header
func main() {

// To avoid unused error on swagger_controller_placeholder
swagger_controller_placeholder()

zerolog.SetGlobalLevel(zerolog.DebugLevel)

// Establish the connection to the database
Expand Down

0 comments on commit 26a697f

Please sign in to comment.