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

fix: fix swagger routes #13

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions config-templates/docker/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ webserver:
#keyFile: "/app/certs/key.pem"
swagger:
enable: false
https: false
address: "127.0.0.1:8081"
certFile: ""
keyFile: ""
logger:
level: "info"
development: false
Expand Down
6 changes: 1 addition & 5 deletions config-templates/minimal-inmemory/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ webserver:
#certFile: "/app/certs/cert.pem"
#keyFile: "/app/certs/key.pem"
swagger:
enable: false
https: false
address: "127.0.0.1:8081"
certFile: ""
keyFile: ""
enable: true
logger:
level: "info"
development: false
Expand Down
6 changes: 1 addition & 5 deletions config-templates/minimal-jsonfilestorage/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ webserver:
#certFile: "/app/certs/cert.pem"
#keyFile: "/app/certs/key.pem"
swagger:
enable: false
https: false
address: "127.0.0.1:8081"
certFile: ""
keyFile: ""
enable: true
logger:
level: "info"
development: false
Expand Down
4 changes: 0 additions & 4 deletions config-templates/secured-jsonfilestorage/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ webserver:
keyFile: "/app/certs/key.pem"
swagger:
enable: false
https: false
address: "127.0.0.1:8081"
certFile: ""
keyFile: ""
logger:
level: "info"
development: false
Expand Down
1 change: 1 addition & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ErrorJWTNotEnabled = 1202
const ErrorJWTRBACUnknownRole = 1210
const ErrorRBACInvalidRule = 1211
const ErrorRBACForbidden = 1212
const ErrorRBACNotEnabled = 1213
const ErrorAuthInternalError = 1220
const ErrorWrongCredentials = 1230

Expand Down
14 changes: 10 additions & 4 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/v1/account": {
"/api/v1/account/": {
"get": {
"description": "Get account details",
"consumes": [
Expand Down Expand Up @@ -218,7 +218,7 @@ const docTemplate = `{
}
}
},
"/api/v1/stream": {
"/api/v1/stream/": {
"post": {
"description": "Create a new stream",
"consumes": [
Expand Down Expand Up @@ -780,7 +780,7 @@ const docTemplate = `{
}
}
},
"/api/v1/streams": {
"/api/v1/streams/": {
"get": {
"description": "Get the list of all streams UUIDs",
"consumes": [
Expand Down Expand Up @@ -919,7 +919,7 @@ const docTemplate = `{
}
}
},
"/api/v1/users": {
"/api/v1/users/": {
"get": {
"description": "Get the list of users",
"consumes": [
Expand All @@ -939,6 +939,12 @@ const docTemplate = `{
"schema": {
"$ref": "#/definitions/web.JSONResultListUsers"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/github_com_nbigot_ministream_web_apierror.APIError"
}
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"host": "127.0.0.1:8080",
"basePath": "/",
"paths": {
"/api/v1/account": {
"/api/v1/account/": {
"get": {
"description": "Get account details",
"consumes": [
Expand Down Expand Up @@ -211,7 +211,7 @@
}
}
},
"/api/v1/stream": {
"/api/v1/stream/": {
"post": {
"description": "Create a new stream",
"consumes": [
Expand Down Expand Up @@ -773,7 +773,7 @@
}
}
},
"/api/v1/streams": {
"/api/v1/streams/": {
"get": {
"description": "Get the list of all streams UUIDs",
"consumes": [
Expand Down Expand Up @@ -912,7 +912,7 @@
}
}
},
"/api/v1/users": {
"/api/v1/users/": {
"get": {
"description": "Get the list of users",
"consumes": [
Expand All @@ -932,6 +932,12 @@
"schema": {
"$ref": "#/definitions/web.JSONResultListUsers"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/github_com_nbigot_ministream_web_apierror.APIError"
}
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ info:
title: MiniStream API
version: "1.0"
paths:
/api/v1/account:
/api/v1/account/:
get:
consumes:
- application/json
Expand Down Expand Up @@ -430,7 +430,7 @@ paths:
summary: Shutdown server
tags:
- Admin
/api/v1/stream:
/api/v1/stream/:
post:
consumes:
- application/json
Expand Down Expand Up @@ -814,7 +814,7 @@ paths:
summary: Rebuild the stream index
tags:
- Stream
/api/v1/streams:
/api/v1/streams/:
get:
consumes:
- application/json
Expand Down Expand Up @@ -907,7 +907,7 @@ paths:
summary: Logs user into the system
tags:
- User
/api/v1/users:
/api/v1/users/:
get:
consumes:
- application/json
Expand All @@ -920,6 +920,10 @@ paths:
description: successful operation
schema:
$ref: '#/definitions/web.JSONResultListUsers'
"400":
description: Bad Request
schema:
$ref: '#/definitions/github_com_nbigot_ministream_web_apierror.APIError'
summary: List users
tags:
- User
Expand Down
2 changes: 1 addition & 1 deletion web/apiaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type GetAccountHTTPJsonResult struct {
// @Produce json
// @Tags Account
// @success 200 {object} web.JSONResult{data=web.GetAccountHTTPJsonResult{}} "successful operation"
// @Router /api/v1/account [get]
// @Router /api/v1/account/ [get]
func (w *WebAPIServer) GetAccount(c *fiber.Ctx) error {
// hide field secretAPIKey
account := account.AccountMgr.GetAccount()
Expand Down
4 changes: 2 additions & 2 deletions web/apistream.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
// @Param jq query string false "string jq filter" example(".name == \"test 8\"")
// @Success 200 {array} types.StreamUUID "successful operation"
// @Failure 403 {object} apierror.APIError
// @Router /api/v1/streams [get]
// @Router /api/v1/streams/ [get]
func (w *WebAPIServer) ListStreams(c *fiber.Ctx) error {
var jq *gojq.Query
var err error
Expand Down Expand Up @@ -122,7 +122,7 @@ func (w *WebAPIServer) ListStreamsProperties(c *fiber.Ctx) error {
// @Tags Stream
// @Success 201 {array} types.StreamInfo
// @Success 400 {object} apierror.APIError
// @Router /api/v1/stream [post]
// @Router /api/v1/stream/ [post]
func (w *WebAPIServer) CreateStream(c *fiber.Ctx) error {
payload := struct {
Properties map[string]string `json:"properties" validate:"required,lte=32,dive,keys,gt=0,lte=64,endkeys,max=128,required"`
Expand Down
12 changes: 11 additions & 1 deletion web/apiuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ import (
// @Produce json
// @Tags User
// @Success 200 {object} web.JSONResultListUsers "successful operation"
// @Router /api/v1/users [get]
// @Success 400 {object} apierror.APIError
// @Router /api/v1/users/ [get]
func (w *WebAPIServer) ListUsers(c *fiber.Ctx) error {
if !w.appConfig.RBAC.Enable {
httpError := apierror.APIError{
Message: "bad Request",
Details: "RBAC is not enabled on server",
Code: constants.ErrorRBACNotEnabled,
HttpCode: fiber.StatusBadRequest,
}
return httpError.HTTPResponse(c)
}
return c.JSON(JSONResultListUsers{Code: fiber.StatusOK, Users: rbac.RbacMgr.Rbac.GetUserList()})
}

Expand Down
3 changes: 3 additions & 0 deletions web/webapiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/nbigot/ministream/auditlog"
"github.com/nbigot/ministream/config"
_ "github.com/nbigot/ministream/docs"
"github.com/nbigot/ministream/rbac"
"github.com/nbigot/ministream/service"
)
Expand Down Expand Up @@ -106,6 +107,8 @@ func (w *WebAPIServer) AddRoutes(app *fiber.App) {
}

if w.appConfig.WebServer.Swagger.Enable {
// example of url to swagger gui: "http://127.0.0.1:8080/docs/index.html"
// url to swagger json document: "http://127.0.0.1:8080/docs/doc.json"
// Create swagger routes group.
apiSwagger := app.Group("/docs")

Expand Down
Loading