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

How can I customize my request body? #108

Open
bluntdel opened this issue May 6, 2020 · 4 comments
Open

How can I customize my request body? #108

bluntdel opened this issue May 6, 2020 · 4 comments

Comments

@bluntdel
Copy link

bluntdel commented May 6, 2020

Out request body format is application/json like that :
{"body":{"id":9},"header":{"token":"token","snTime":1588213292769,"sn":"78028ad247479b146012f49aaecd2ff3","from":"web"}}
The header is fixed.So I want to add these params to all my request.How can i realize it ?

@Shadowmaple
Copy link

If you insist on putting the 'header' in the body instead of the header, you could define models like these:

type BodyItem struct {
  ID uint `json:"id"`
}

type HeaderItem struct {
  Token string `json:"token"`
  SnTime uin64 `json:"snTime"`
  Sn string `json:"sn"`
  From string `json:"from"`
}

type RequestData struct {
  Body BodyItem `json:"body"`
  Header HeaderItem `json:"header"`
}

Then use @Param data body RequestData true "body data".

@bluntdel
Copy link
Author

Extractly I defined like yours. @Shadowmaple But I can't modify the request sent by swagger. How can I customize my request sent by swagger?

@qiangshui
Copy link

If you insist on putting the 'header' in the body instead of the header, you could define models like these:

type BodyItem struct {
  ID uint `json:"id"`
}

type HeaderItem struct {
  Token string `json:"token"`
  SnTime uin64 `json:"snTime"`
  Sn string `json:"sn"`
  From string `json:"from"`
}

type RequestData struct {
  Body BodyItem `json:"body"`
  Header HeaderItem `json:"header"`
}

Then use @Param data body RequestData true "body data".

Have to define a struct?

@Manas8803
Copy link

How to get default value in my ui like using comments :
{
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}

I want values to be filled by default rather than string that is displayed in "name" key.

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

4 participants