From 732c0879d89dde8df85f435d43bdcd95a1ccc83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20Savc=C4=B1?= Date: Fri, 19 Aug 2022 23:50:10 +0300 Subject: [PATCH] doc: add function scoped struct declaration example (#1296) --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 944d244e9..d33f57c53 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 `.. `. + +```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