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 some REST APIs methods from get to post #742

Merged
merged 2 commits into from
Sep 15, 2021
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
22 changes: 14 additions & 8 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag

package docs

import (
"bytes"
"encoding/json"
"strings"
"text/template"
Copy link
Member Author

@atg0831 atg0831 Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swagger docs를 업데이트 하는 과정에서 이 package가 자동으로 import 되고 기존의 "github.com/alecthomas/template" package가 빠졌습니다.
동시에 아래 코드에서 "text/template" package가 import 되면서 escape문이 추가 되었는데 이렇게 진행을 해도 괜찮을까요?

"description": "{{escape .Description}}",

"escape": func(v interface{}) string {
// escape tabs
str := strings.Replace(v.(string), "\t", "\t", -1)
// replace " with ", and if that results in \", replace that with \"
str = strings.Replace(str, """, "\"", -1)
return strings.Replace(str, "\\"", "\\\"", -1)
},

Copy link
Member

@jihoon-seo jihoon-seo Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atg0831 기여 감사합니다 😊

혹시 사용하고 계신 swag 버전을 알 수 있을까요? 😊
저는 확인해보니 v1.7.0 입니다.

❯ swag -v
swag version v1.7.0

현재 최신버전은 v1.7.1 이네요 😊
https://github.com/swaggo/swag/releases

v1.7.1 changelog 중에
"chore: alecthomas/template -> text/template" 가 있는 것으로 봐서
v1.7.1 을 사용중이신 것 같군요.. ㅎㅎ

저도 v1.7.1 로 업데이트하고 make swag 실행하니
이 PR과 동일해졌습니다.

이 PR대로 진행하면 될 것 같습니다. 😊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jihoon-seo
혹시,
wiki/API-Document-UpdateReadme Swagger API 문서 업데이트 필요 시 항목에 swag version 에 대한 명시가 필요할까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son 훔..
기여자가 앞으로 v1.7.1 이 아닌 v1.7.0 등을 사용하면
code pingpong이 계속 일어날 수 있기는 합니다.

명시를 하는 것도 좋을 것 같은데,
그러면 앞으로 swag 이 업데이트 될 때마다 저희도 (필요 시) 업데이트를 해야 하겠네요 😊

비슷한 이슈로 protoc 버전이 있습니다.

과거에 있었던 swag / protoc code pingpong 이슈를 생각하니, 버전 명시를 하는 것이 좋을 것 같다는 생각이 더 드네요 😊

Copy link
Member

@yunkon-kim yunkon-kim Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son @jihoon-seo
위에서 말씀하신 protoc 관련하여 어제 고생을 조금 한터라 😭 간단히 정리한 내용을 공유 드립니다 ☺️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jihoon-seo @seokho-son
네 제가 swag 최신 버전을 사용했고 Makefile을 이용해서 make swag을 했는데요,
그런데 지금 보니가 cb-tumblbug의 go.mod 파일에는 swag v1.7.0 으로 되어 있네요.
go.mod의 swag의 버전과 $GOPATH의 bin 디렉토리 안의 swag의 버전이 다른데 일치시켜야 하지 않을까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atg0831go.modswag 버전도 업데이트 해야겠네요 😊

  • 이 PR에서 업데이트를 해 주셔도 좋고,
  • 아니면 이 PR이 머지된 이후에 별도의 PR로 업데이트를 해도 좋을 것 같습니다. 😊

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jihoon-seo
이번 PR에서 말고 별도의 PR로 수정해서 올리도록 하겠습니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atg0831 이슈로 미리 올리고 작업 시작하시면 좋을 것 같습니다! ^^
이슈 올리실 때,
image
를 활용하는 방법도 있어요 ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seokho-son
팁 알려주셔서 감사합니다 ㅎㅎ 이슈 올려서 진행해볼게요


"github.com/alecthomas/template"
"github.com/swaggo/swag"
)

var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {
"name": "API Support",
Expand Down Expand Up @@ -385,7 +384,7 @@ var doc = `{
}
},
"/lookupImage": {
"get": {
"post": {
"description": "Lookup image",
"consumes": [
"application/json"
Expand Down Expand Up @@ -431,7 +430,7 @@ var doc = `{
}
},
"/lookupImages": {
"get": {
"post": {
"description": "Lookup image list",
"consumes": [
"application/json"
Expand Down Expand Up @@ -477,7 +476,7 @@ var doc = `{
}
},
"/lookupSpec": {
"get": {
"post": {
"description": "Lookup spec",
"consumes": [
"application/json"
Expand Down Expand Up @@ -523,7 +522,7 @@ var doc = `{
}
},
"/lookupSpecs": {
"get": {
"post": {
"description": "Lookup spec list",
"consumes": [
"application/json"
Expand Down Expand Up @@ -6403,6 +6402,13 @@ func (s *s) ReadDoc() string {
a, _ := json.Marshal(v)
return string(a)
},
"escape": func(v interface{}) string {
// escape tabs
str := strings.Replace(v.(string), "\t", "\\t", -1)
// replace " with \", and if that results in \\", replace that with \\\"
str = strings.Replace(str, "\"", "\\\"", -1)
return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
},
}).Parse(doc)
if err != nil {
return doc
Expand Down
8 changes: 4 additions & 4 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
}
},
"/lookupImage": {
"get": {
"post": {
"description": "Lookup image",
"consumes": [
"application/json"
Expand Down Expand Up @@ -416,7 +416,7 @@
}
},
"/lookupImages": {
"get": {
"post": {
"description": "Lookup image list",
"consumes": [
"application/json"
Expand Down Expand Up @@ -462,7 +462,7 @@
}
},
"/lookupSpec": {
"get": {
"post": {
"description": "Lookup spec",
"consumes": [
"application/json"
Expand Down Expand Up @@ -508,7 +508,7 @@
}
},
"/lookupSpecs": {
"get": {
"post": {
"description": "Lookup spec list",
"consumes": [
"application/json"
Expand Down
8 changes: 4 additions & 4 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ paths:
tags:
- '[Admin] Cloud environment management'
/lookupImage:
get:
post:
consumes:
- application/json
description: Lookup image
Expand Down Expand Up @@ -1781,7 +1781,7 @@ paths:
tags:
- '[Admin] Cloud environment management'
/lookupImages:
get:
post:
consumes:
- application/json
description: Lookup image list
Expand Down Expand Up @@ -1811,7 +1811,7 @@ paths:
tags:
- '[Admin] Cloud environment management'
/lookupSpec:
get:
post:
consumes:
- application/json
description: Lookup spec
Expand Down Expand Up @@ -1841,7 +1841,7 @@ paths:
tags:
- '[Admin] Cloud environment management'
/lookupSpecs:
get:
post:
consumes:
- application/json
description: Lookup spec list
Expand Down
4 changes: 2 additions & 2 deletions src/api/rest/server/mcir/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type RestLookupImageRequest struct {
// @Success 200 {object} mcir.SpiderImageInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /lookupImage [get]
// @Router /lookupImage [post]
func RestLookupImage(c echo.Context) error {

u := &RestLookupImageRequest{}
Expand Down Expand Up @@ -136,7 +136,7 @@ func RestLookupImage(c echo.Context) error {
// @Success 200 {object} mcir.SpiderImageList
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /lookupImages [get]
// @Router /lookupImages [post]
func RestLookupImageList(c echo.Context) error {

//type JsonTemplate struct {
Expand Down
4 changes: 2 additions & 2 deletions src/api/rest/server/mcir/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type RestLookupSpecRequest struct {
// @Success 200 {object} mcir.SpiderSpecInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /lookupSpec [get]
// @Router /lookupSpec [post]
func RestLookupSpec(c echo.Context) error {
u := &RestLookupSpecRequest{}
if err := c.Bind(u); err != nil {
Expand Down Expand Up @@ -154,7 +154,7 @@ func RestLookupSpec(c echo.Context) error {
// @Success 200 {object} mcir.SpiderSpecList
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /lookupSpecs [get]
// @Router /lookupSpecs [post]
func RestLookupSpecList(c echo.Context) error {

//type JsonTemplate struct {
Expand Down
8 changes: 4 additions & 4 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ func ApiServer() {
e.GET("/tumblebug/region", rest_common.RestGetRegionList)
e.GET("/tumblebug/region/:regionName", rest_common.RestGetRegion)

e.GET("/tumblebug/lookupSpecs", rest_mcir.RestLookupSpecList)
e.GET("/tumblebug/lookupSpec", rest_mcir.RestLookupSpec)
e.POST("/tumblebug/lookupSpecs", rest_mcir.RestLookupSpecList)
e.POST("/tumblebug/lookupSpec", rest_mcir.RestLookupSpec)

e.GET("/tumblebug/lookupImages", rest_mcir.RestLookupImageList)
e.GET("/tumblebug/lookupImage", rest_mcir.RestLookupImage)
e.POST("/tumblebug/lookupImages", rest_mcir.RestLookupImageList)
e.POST("/tumblebug/lookupImage", rest_mcir.RestLookupImage)

e.POST("/tumblebug/inspectResources", rest_common.RestInspectResources)

Expand Down
2 changes: 1 addition & 1 deletion src/testclient/scripts/6.image/lookupImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function CallTB() {
echo "- Lookup image in ${MCIRRegionName}"

resp=$(
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/lookupImage -H 'Content-Type: application/json' -d @- <<EOF
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/lookupImage -H 'Content-Type: application/json' -d @- <<EOF
{
"connectionName": "${CONN_CONFIG[$INDEX,$REGION]}",
"cspImageId": "${IMAGE_NAME[$INDEX,$REGION]}"
Expand Down
2 changes: 1 addition & 1 deletion src/testclient/scripts/6.image/lookupImageList.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function CallTB() {
echo "- Lookup images in ${MCIRRegionName}"

resp=$(
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/lookupImages -H 'Content-Type: application/json' -d @- <<EOF
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/lookupImages -H 'Content-Type: application/json' -d @- <<EOF
{
"connectionName": "${CONN_CONFIG[$INDEX,$REGION]}"
}
Expand Down
2 changes: 1 addition & 1 deletion src/testclient/scripts/7.spec/lookupSpec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function CallTB() {
echo "- Lookup spec in ${MCIRRegionName}"

resp=$(
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/lookupSpec -H 'Content-Type: application/json' -d @- <<EOF
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/lookupSpec -H 'Content-Type: application/json' -d @- <<EOF
{
"connectionName": "${CONN_CONFIG[$INDEX,$REGION]}",
"cspSpecName": "${SPEC_NAME[$INDEX,$REGION]}"
Expand Down
2 changes: 1 addition & 1 deletion src/testclient/scripts/7.spec/lookupSpecList.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function CallTB() {
echo "- Lookup specs in ${MCIRRegionName}"

resp=$(
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/lookupSpecs -H 'Content-Type: application/json' -d @- <<EOF
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/lookupSpecs -H 'Content-Type: application/json' -d @- <<EOF
{
"connectionName": "${CONN_CONFIG[$INDEX,$REGION]}"
}
Expand Down