update swagger descriptions

This commit is contained in:
noemie 2023-04-24 16:53:10 +02:00
parent be4545e603
commit 8ee64aa49f
11 changed files with 916 additions and 230 deletions

BIN
.README.md.swp Normal file

Binary file not shown.

7
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}

View File

@ -6,6 +6,10 @@ Some special tables can be used for defining database access restrictions based
> export GOPRIVATE=forge.redroom.link > export GOPRIVATE=forge.redroom.link
before doing go mod tidy. before doing go mod tidy.
Installing bee command
----------------------
> go get github.com/beego/bee/v2
Running in debug mode Running in debug mode
--------------------- ---------------------
> bee run -downdoc=true -gendoc=true > bee run -downdoc=true -gendoc=true

View File

@ -1,6 +1,7 @@
package controllers package controllers
import ( import (
"net/http"
"os" "os"
"forge.redroom.link/yves/sqldb" "forge.redroom.link/yves/sqldb"
@ -13,17 +14,18 @@ type SchemaController struct {
beego.Controller beego.Controller
} }
// @Title GetTable // @Title GetTablesList
// @Description get list table // @Description Get database tables list
// @Success 200 {string} success ! // @Success 200 {string} success !
// @Failure 403 no table // @Failure 500 query error
// @router / [get] // @router / [get]
func (s *SchemaController) GetTable() { func (s *SchemaController) GetTablesList() {
db := sqldb.Open(os.Getenv("driverdb"), os.Getenv("paramsdb")) db := sqldb.Open(os.Getenv("driverdb"), os.Getenv("paramsdb"))
data, err := db.ListTables() data, err := db.ListTables()
if err != nil { if err != nil {
log.Error().Msg(err.Error()) log.Error().Msg(err.Error())
s.Data["json"] = map[string]string{"error": err.Error()} s.Data["json"] = map[string]string{"error": err.Error()}
s.Ctx.Output.SetStatus(http.StatusInternalServerError)
} }
s.Data["json"] = data s.Data["json"] = data
s.ServeJSON() s.ServeJSON()
@ -32,10 +34,10 @@ func (s *SchemaController) GetTable() {
} }
// @Title GetSchema // @Title GetSchema
// @Description get table schema // @Description Get table schema
// @Param table path string true "Name of the table" // @Param table path string true "Name of the table"
// @Success 200 success ! // @Success 200 success !
// @Failure 403 no table // @Failure 204 no table
// @router /:table [get] // @router /:table [get]
func (s *SchemaController) GetSchema() { func (s *SchemaController) GetSchema() {
table := s.GetString(":table") table := s.GetString(":table")
@ -44,6 +46,7 @@ func (s *SchemaController) GetSchema() {
if err != nil { if err != nil {
log.Error().Msg(err.Error()) log.Error().Msg(err.Error())
s.Data["json"] = map[string]string{"error": err.Error()} s.Data["json"] = map[string]string{"error": err.Error()}
s.Ctx.Output.SetStatus(http.StatusNoContent)
} }
s.Data["json"] = data s.Data["json"] = data
s.ServeJSON() s.ServeJSON()

View File

@ -185,7 +185,7 @@ func (t *TableController) GetAllTableColumnRestriction() {
// @Param table path string true "Name of the table" // @Param table path string true "Name of the table"
// @Param columns path string true "Name of the columns (separate with a comma)" // @Param columns path string true "Name of the columns (separate with a comma)"
// @Param restriction path string true "SQL restriction" // @Param restriction path string true "SQL restriction"
// @param sortkeys path string true "column name" // @Param sortkeys path string true "Order by: columns names (separate with a comma)"
// @Success 200 {string} success ! // @Success 200 {string} success !
// @Failure 403 no table // @Failure 403 no table
// @router /:table/:columns/:restriction/:sortkeys [get] // @router /:table/:columns/:restriction/:sortkeys [get]
@ -210,8 +210,8 @@ func (t *TableController) GetAllTableColumnRestrictionSortkeys() {
// @Param table path string true "Name of the table" // @Param table path string true "Name of the table"
// @Param columns path string true "Name of the columns (separate with a comma)" // @Param columns path string true "Name of the columns (separate with a comma)"
// @Param restriction path string true "SQL restriction" // @Param restriction path string true "SQL restriction"
// @param sortkeys path string true "column name" // @Param sortkeys path string true "Order by: columns names (separate with a comma)"
// @param dir path string true "asc or desc" // @Param dir path string true "asc or desc"
// @Success 200 {string} success ! // @Success 200 {string} success !
// @Failure 403 no table // @Failure 403 no table
// @router /:table/:columns/:restriction/:sortkeys/:dir [get] // @router /:table/:columns/:restriction/:sortkeys/:dir [get]

54
go.mod
View File

@ -2,24 +2,46 @@ module sqldb-ws
go 1.16 go 1.16
require github.com/beego/beego/v2 v2.0.2 require github.com/beego/beego/v2 v2.0.7
require ( require (
forge.redroom.link/yves/sqldb v0.0.0-20220520131204-4e17758e157e forge.redroom.link/yves/sqldb v0.0.0-20230130111657-cf652439b461
github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/apache/thrift v0.13.0 // indirect
github.com/lib/pq v1.10.6 github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a // indirect
github.com/matthewhartstonge/argon2 v0.2.1 github.com/aws/aws-lambda-go v1.13.3 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec // indirect
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect
github.com/hashicorp/go.net v0.0.1 // indirect
github.com/lib/pq v1.10.7
github.com/lightstep/lightstep-tracer-go v0.18.1 // indirect
github.com/matthewhartstonge/argon2 v0.3.2
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/gox v0.4.0 // indirect
github.com/mitchellh/iochan v1.0.0 // indirect
github.com/nats-io/jwt v0.3.2 // indirect
github.com/oklog/oklog v0.3.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/opentracing/basictracer-go v1.0.0 // indirect
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5 // indirect
github.com/pact-foundation/pact-go v1.0.4 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/performancecopilot/speed v3.0.0+incompatible // indirect
github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.34.0 // indirect github.com/prometheus/common v0.39.0 // indirect
github.com/rs/zerolog v1.26.1 github.com/prometheus/procfs v0.9.0 // indirect
github.com/rs/zerolog v1.29.0
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da // indirect
github.com/smartystreets/goconvey v1.6.4 github.com/smartystreets/goconvey v1.6.4
github.com/spf13/cast v1.5.0 // indirect github.com/spf13/viper v1.15.0
github.com/spf13/viper v1.11.0 github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271 // indirect
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 // indirect go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 // indirect
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee // indirect
golang.org/x/sys v0.0.0-20220519141025-dcacdad47464 // indirect golang.org/x/crypto v0.5.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0 // indirect
) )

751
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@ func init() {
beego.GlobalControllerRouter["sqldb-ws/controllers:SchemaController"] = append(beego.GlobalControllerRouter["sqldb-ws/controllers:SchemaController"], beego.GlobalControllerRouter["sqldb-ws/controllers:SchemaController"] = append(beego.GlobalControllerRouter["sqldb-ws/controllers:SchemaController"],
beego.ControllerComments{ beego.ControllerComments{
Method: "GetTable", Method: "GetTablesList",
Router: "/", Router: "/",
AllowHTTPMethods: []string{"get"}, AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(), MethodParams: param.Make(),

View File

@ -7,7 +7,7 @@ import (
func CheckSelect(dbuser_id string, table *string, columns *string, restriction *string) { func CheckSelect(dbuser_id string, table *string, columns *string, restriction *string) {
//fmt.Println(dbuser_id, fmt.Sprintf("%v", table), fmt.Sprintf("%v", columns), fmt.Sprintf("%v", restriction)) fmt.Println(dbuser_id, fmt.Sprintf("%v", table), fmt.Sprintf("%v", columns), fmt.Sprintf("%v", restriction))
} }
func removeLastChar(s string) string { func removeLastChar(s string) string {

View File

@ -2,7 +2,7 @@
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"title": "beego Test API", "title": "beego Test API",
"description": "beego has a very cool tools to autogenerate documents for your API", "description": "beego has a very cool tools to autogenerate documents for your API\n",
"version": "1.0.0", "version": "1.0.0",
"termsOfService": "http://beego.me/", "termsOfService": "http://beego.me/",
"contact": { "contact": {
@ -20,7 +20,7 @@
"tags": [ "tags": [
"l" "l"
], ],
"description": "Add user", "description": "Add user\n\u003cbr\u003e",
"operationId": "LoginController.AddUser", "operationId": "LoginController.AddUser",
"parameters": [ "parameters": [
{ {
@ -53,7 +53,7 @@
"tags": [ "tags": [
"l" "l"
], ],
"description": "User login", "description": "User login\n\u003cbr\u003e",
"operationId": "LoginController.Login", "operationId": "LoginController.Login",
"parameters": [ "parameters": [
{ {
@ -84,7 +84,7 @@
"tags": [ "tags": [
"l" "l"
], ],
"description": "Logs user", "description": "Logs user\n\u003cbr\u003e",
"operationId": "LoginController.Logout", "operationId": "LoginController.Logout",
"responses": { "responses": {
"200": { "200": {
@ -101,14 +101,14 @@
"tags": [ "tags": [
"s" "s"
], ],
"description": "get list table", "description": "Get database tables list\n\u003cbr\u003e",
"operationId": "SchemaController.GetTable", "operationId": "SchemaController.GetTablesList",
"responses": { "responses": {
"200": { "200": {
"description": "{string} success !" "description": "{string} success !"
}, },
"403": { "500": {
"description": "no table" "description": "query error"
} }
} }
} }
@ -118,7 +118,7 @@
"tags": [ "tags": [
"s" "s"
], ],
"description": "get table schema", "description": "Get table schema\n\u003cbr\u003e",
"operationId": "SchemaController.GetSchema", "operationId": "SchemaController.GetSchema",
"parameters": [ "parameters": [
{ {
@ -133,7 +133,7 @@
"200": { "200": {
"description": "success !" "description": "success !"
}, },
"403": { "204": {
"description": "no table" "description": "no table"
} }
} }
@ -144,7 +144,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "get all Datas", "description": "get all Datas\n\u003cbr\u003e",
"operationId": "TableController.GetAllTable", "operationId": "TableController.GetAllTable",
"parameters": [ "parameters": [
{ {
@ -168,7 +168,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "put data in table", "description": "put data in table\n\u003cbr\u003e",
"operationId": "TableController.Put data in table", "operationId": "TableController.Put data in table",
"parameters": [ "parameters": [
{ {
@ -201,7 +201,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "get all Datas", "description": "get all Datas\n\u003cbr\u003e",
"operationId": "TableController.TablePost", "operationId": "TableController.TablePost",
"parameters": [ "parameters": [
{ {
@ -234,7 +234,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "delete the data in table", "description": "delete the data in table\n\u003cbr\u003e",
"operationId": "TableController.Delete", "operationId": "TableController.Delete",
"parameters": [ "parameters": [
{ {
@ -268,7 +268,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "get all Datas", "description": "get all Datas\n\u003cbr\u003e",
"operationId": "TableController.GetAllTableColumn", "operationId": "TableController.GetAllTableColumn",
"parameters": [ "parameters": [
{ {
@ -301,7 +301,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "get all Datas", "description": "get all Datas\n\u003cbr\u003e",
"operationId": "TableController.GetAllTableColumnRestriction", "operationId": "TableController.GetAllTableColumnRestriction",
"parameters": [ "parameters": [
{ {
@ -341,7 +341,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "get all Datas", "description": "get all Datas\n\u003cbr\u003e",
"operationId": "TableController.GetAllTableColumnRestrictionSortkeys", "operationId": "TableController.GetAllTableColumnRestrictionSortkeys",
"parameters": [ "parameters": [
{ {
@ -381,7 +381,7 @@
"tags": [ "tags": [
"t" "t"
], ],
"description": "get all Datas", "description": "get all Datas\n\u003cbr\u003e",
"operationId": "TableController.GetAllTableColumnRestrictionSortkeysDir", "operationId": "TableController.GetAllTableColumnRestrictionSortkeysDir",
"parameters": [ "parameters": [
{ {

View File

@ -1,7 +1,8 @@
swagger: "2.0" swagger: "2.0"
info: info:
title: beego Test API title: beego Test API
description: beego has a very cool tools to autogenerate documents for your API description: |
beego has a very cool tools to autogenerate documents for your API
version: 1.0.0 version: 1.0.0
termsOfService: http://beego.me/ termsOfService: http://beego.me/
contact: contact:
@ -15,7 +16,9 @@ paths:
post: post:
tags: tags:
- l - l
description: Add user description: |-
Add user
<br>
operationId: LoginController.AddUser operationId: LoginController.AddUser
parameters: parameters:
- in: query - in: query
@ -37,7 +40,9 @@ paths:
post: post:
tags: tags:
- l - l
description: User login description: |-
User login
<br>
operationId: LoginController.Login operationId: LoginController.Login
parameters: parameters:
- in: body - in: body
@ -57,7 +62,9 @@ paths:
post: post:
tags: tags:
- l - l
description: Logs user description: |-
Logs user
<br>
operationId: LoginController.Logout operationId: LoginController.Logout
responses: responses:
"200": "200":
@ -68,18 +75,22 @@ paths:
get: get:
tags: tags:
- s - s
description: get list table description: |-
operationId: SchemaController.GetTable Get database tables list
<br>
operationId: SchemaController.GetTablesList
responses: responses:
"200": "200":
description: '{string} success !' description: '{string} success !'
"403": "500":
description: no table description: query error
/s/{table}: /s/{table}:
get: get:
tags: tags:
- s - s
description: get table schema description: |-
Get table schema
<br>
operationId: SchemaController.GetSchema operationId: SchemaController.GetSchema
parameters: parameters:
- in: path - in: path
@ -90,13 +101,15 @@ paths:
responses: responses:
"200": "200":
description: success ! description: success !
"403": "204":
description: no table description: no table
/t/{table}: /t/{table}:
get: get:
tags: tags:
- t - t
description: get all Datas description: |-
get all Datas
<br>
operationId: TableController.GetAllTable operationId: TableController.GetAllTable
parameters: parameters:
- in: path - in: path
@ -112,7 +125,9 @@ paths:
put: put:
tags: tags:
- t - t
description: put data in table description: |-
put data in table
<br>
operationId: TableController.Put data in table operationId: TableController.Put data in table
parameters: parameters:
- in: path - in: path
@ -134,7 +149,9 @@ paths:
post: post:
tags: tags:
- t - t
description: get all Datas description: |-
get all Datas
<br>
operationId: TableController.TablePost operationId: TableController.TablePost
parameters: parameters:
- in: path - in: path
@ -156,7 +173,9 @@ paths:
delete: delete:
tags: tags:
- t - t
description: delete the data in table description: |-
delete the data in table
<br>
operationId: TableController.Delete operationId: TableController.Delete
parameters: parameters:
- in: path - in: path
@ -178,7 +197,9 @@ paths:
get: get:
tags: tags:
- t - t
description: get all Datas description: |-
get all Datas
<br>
operationId: TableController.GetAllTableColumn operationId: TableController.GetAllTableColumn
parameters: parameters:
- in: path - in: path
@ -200,7 +221,9 @@ paths:
get: get:
tags: tags:
- t - t
description: get all Datas description: |-
get all Datas
<br>
operationId: TableController.GetAllTableColumnRestriction operationId: TableController.GetAllTableColumnRestriction
parameters: parameters:
- in: path - in: path
@ -227,7 +250,9 @@ paths:
get: get:
tags: tags:
- t - t
description: get all Datas description: |-
get all Datas
<br>
operationId: TableController.GetAllTableColumnRestrictionSortkeys operationId: TableController.GetAllTableColumnRestrictionSortkeys
parameters: parameters:
- in: path - in: path
@ -254,7 +279,9 @@ paths:
get: get:
tags: tags:
- t - t
description: get all Datas description: |-
get all Datas
<br>
operationId: TableController.GetAllTableColumnRestrictionSortkeysDir operationId: TableController.GetAllTableColumnRestrictionSortkeysDir
parameters: parameters:
- in: path - in: path