Skip to content

Commit bab7aac

Browse files
docs: add PT and EN examples for Go generic types (#1697)
1 parent 2b5852a commit bab7aac

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie
4444
- [How to use security annotations](#how-to-use-security-annotations)
4545
- [Add a description for enum items](#add-a-description-for-enum-items)
4646
- [Generate only specific docs file types](#generate-only-specific-docs-file-types)
47+
- [How to use Go generic types](#how-to-use-generics)
4748
- [About the Project](#about-the-project)
4849

4950
## Getting started
@@ -909,6 +910,19 @@ By default `swag` command generates Swagger specification in three different fil
909910
910911
If you would like to limit a set of file types which should be generated you can use `--outputTypes` (short `-ot`) flag. Default value is `go,json,yaml` - output types separated with comma. To limit output only to `go` and `yaml` files, you would write `go,yaml`. With complete command that would be `swag init --outputTypes go,yaml`.
911912
913+
### How to use Generics
914+
915+
```go
916+
// @Success 200 {object} web.GenericNestedResponse[types.Post]
917+
// @Success 204 {object} web.GenericNestedResponse[types.Post, Types.AnotherOne]
918+
// @Success 201 {object} web.GenericNestedResponse[web.GenericInnerType[types.Post]]
919+
func GetPosts(w http.ResponseWriter, r *http.Request) {
920+
_ = web.GenericNestedResponse[types.Post]{}
921+
}
922+
```
923+
See [this file](https://github.com/swaggo/swag/blob/master/testdata/generics_nested/api/api.go) for more details
924+
and other examples.
925+
912926
### Change the default Go Template action delimiters
913927
[#980](https://github.com/swaggo/swag/issues/980)
914928
[#1177](https://github.com/swaggo/swag/issues/1177)

README_pt.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Swag converte anotações Go para Documentação Swagger 2.0. Criámos uma varie
4343
- [Como utilizar as anotações de segurança](#como-utilizar-as-anotações-de-segurança)
4444
- [Adicionar uma descrição para enumerar artigos](#add-a-description-for-enum-items)
4545
- [Gerar apenas tipos de ficheiros de documentos específicos](#generate-only-specific-docs-file-file-types)
46+
- [Como usar tipos genéricos](#como-usar-tipos-genéricos)
4647
- [Sobre o projecto](#sobre-o-projecto)
4748

4849
## Começando
@@ -905,6 +906,18 @@ Por defeito, o comando `swag` gera especificação Swagger em três tipos difere
905906
906907
Se desejar limitar um conjunto de tipos de ficheiros que devem ser gerados pode utilizar a bandeira `--outputTypes` (short `-ot`). O valor por defeito é `go,json,yaml` - tipos de saída separados por vírgula. Para limitar a saída apenas a ficheiros `go` e `yaml`, escrever-se-ia `go,yaml'. Com comando completo que seria `swag init --outputTypes go,yaml`.
907908
909+
### Como usar tipos genéricos
910+
911+
```go
912+
// @Success 200 {object} web.GenericNestedResponse[types.Post]
913+
// @Success 204 {object} web.GenericNestedResponse[types.Post, Types.AnotherOne]
914+
// @Success 201 {object} web.GenericNestedResponse[web.GenericInnerType[types.Post]]
915+
func GetPosts(w http.ResponseWriter, r *http.Request) {
916+
_ = web.GenericNestedResponse[types.Post]{}
917+
}
918+
```
919+
Para mais detalhes e outros exemplos, veja [esse arquivo](https://github.com/swaggo/swag/blob/master/testdata/generics_nested/api/api.go)
920+
908921
### Alterar os delimitadores de acção padrão Go Template
909922
[#980](https://github.com/swaggo/swag/issues/980)
910923
[#1177](https://github.com/swaggo/swag/issues/1177)

0 commit comments

Comments
 (0)