Skip to content

Commit

Permalink
doc: add function scoped struct declaration example (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrYoda committed Aug 19, 2022
1 parent cf03796 commit 732c087
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Expand Up @@ -29,6 +29,7 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie
- [Examples](#examples)
- [Descriptions over multiple lines](#descriptions-over-multiple-lines)
- [User defined structure with an array type](#user-defined-structure-with-an-array-type)
- [Function scoped struct declaration](#function-scoped-struct-declaration)
- [Model composition in response](#model-composition-in-response)
- [Add a headers in response](#add-a-headers-in-response)
- [Use multiple path params](#use-multiple-path-params)
Expand Down Expand Up @@ -540,6 +541,30 @@ type Account struct {
}
```


### Function scoped struct declaration

You can declare your request response structs inside a function body.
You must have to follow the naming convention `<package-name>.<function-name>.<struct-name> `.

```go
package main

// @Param request body main.MyHandler.request true "query params"
// @Success 200 {object} main.MyHandler.response
// @Router /test [post]
func MyHandler() {
type request struct {
RequestField string
}

type response struct {
ResponseField string
}
}
```


### Model composition in response
```go
// JSONResult's data field will be overridden by the specific type proto.Order
Expand Down

0 comments on commit 732c087

Please sign in to comment.