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

'try it out' with post method can't gain correct curl statement #105

Open
praisethejack opened this issue Apr 16, 2020 · 1 comment
Open

Comments

@praisethejack
Copy link

praisethejack commented Apr 16, 2020

'try it out' with post method can't gain correct curl statement.
Here's what happened to me:
This is the comment in strategy.go

// @router /strategy [post]
// @Security ApiKeyAuth
// @description create strategy
// @accept json
// @param who query APICreateStrategyInput true "123"
// @produce json
// @Header 200 {string} Apitoken "{"name":"admin","sig":"729fc1337a2b11eab3ae0252cdae8f6c"}"
// @success 200 {object} f.Strategy ""
func CreateStrategy(c *gin.Context) {
...
}

And this is the yaml created by command 'swag init'

paths:
/strategy:
get:
consumes:
- multipart/form-data
description: get strategy list
parameters:
- description: tidtid
in: query
name: tid
required: true
type: string
produces:
- application/json
responses:
"200":
description: '{"msg": "who are you"}'
schema:
$ref: '#/definitions/string'
"400":
description: '{"msg": "who are you"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: get strategy list
tags:
- Strategy
post:
consumes:
- application/json
description: create strategy
parameters:
- description: descMetric
in: query
name: metric
required: true
type: string
- in: query
name: tags
type: string
- in: query
name: max_step
required: true
type: integer
- in: query
name: op
required: true
type: string
- in: query
name: right_value
required: true
type: string
- in: query
name: note
type: string
- in: query
name: tpl_id
required: true
type: integer
- in: query
name: priority
type: integer
- in: query
name: func
required: true
type: string
- in: query
name: run_begin
type: string
- in: query
name: run_end
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/f.Strategy'
"400":
description: '{"error":"token key is not set","status":2}'
schema:
type: string
"401":
description: '{"error":"token key is not set","status":2}'
schema:
type: string
"500":
description: '{"msg": ""}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: Create a strategy
tags:
- Strategy
securityDefinitions:
ApiKeyAuth:
in: header
name: Apitoken
type: apiKey
swagger: "2.0"

However, swagger ui shows:

curl -X POST "http://127.0.0.1:8080/api/v1/strategy?metric=1&tags=1&max_step=1&op=1&right_value=1&note=1&tpl_id=1&priority=1&func=1&run_begin=1&run_end=1" -H "accept: application/json" -H "Apitoken: {"name":"root","sig":"729fc1337a2b11eab3ae0252cdae8f6c"}"
`

Above is clearly wrong.
I was expecting it should be:

curl -X POST "http://127.0.0.1:8080/api/v1/strategy" -H "accept: application/json" -H "Apitoken: {"name":"root","sig":"729fc1337a2b11eab3ae0252cdae8f6c"}" -H "Content-Type: application/json" -d '{"tags": "1","right_value": "1","note": "1","run_begin": "1","tpl_id": 1,"metric": "1","max_step":
1,"priority": 1,"func": "1","op": "1","run_end": "1"}'

@ubogdan
Copy link
Contributor

ubogdan commented Aug 11, 2021

The params were defined as in: query, which means they are query params, not part of the payload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants