-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generic arrays generate successfully
- Loading branch information
1 parent
1cd0b53
commit 327ea07
Showing
5 changed files
with
267 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/swaggo/swag/testdata/generics_arrays/web" | ||
) | ||
|
||
// @Summary List Posts | ||
// @Description Get All of the Posts | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} web.GenericListResponse[web.Post] | ||
// @Success 222 {object} web.GenericListResponseMulti[web.Post, web.Post] | ||
// @Router /posts [get] | ||
func GetPosts(w http.ResponseWriter, r *http.Request) { | ||
_ = web.GenericListResponse[web.Post]{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/swaggo/swag/testdata/generics_basic/api" | ||
) | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample server Petstore server. | ||
// @host localhost:4000 | ||
// @basePath /api | ||
func main() { | ||
http.HandleFunc("/posts/", api.GetPost) | ||
http.ListenAndServe(":8080", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package web | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// GenericListResponse[T] | ||
// @Description Some Generic List Response | ||
type GenericListResponse[T any] struct { | ||
// Items from the list response | ||
Items []T | ||
// Status of some other stuff | ||
Status string | ||
} | ||
|
||
// GenericListResponseMulti[T, X] | ||
// @Description this contains a few things | ||
type GenericListResponseMulti[T any, X any] struct { | ||
// ItemsOne is the first thing | ||
ItemsOne []T | ||
// ItemsTwo is the second thing | ||
ItemsTwo []X | ||
|
||
// Status of the things | ||
Status string | ||
} | ||
|
||
type Post struct { | ||
ID int `json:"id" example:"1" format:"int64"` | ||
// Post name | ||
Name string `json:"name" example:"poti"` | ||
// Post data | ||
Data struct { | ||
// Post tag | ||
Tag []string `json:"name"` | ||
} `json:"data"` | ||
} | ||
|
||
// APIError | ||
// @Description API error | ||
// @Description with information about it | ||
// Other some summary | ||
type APIError struct { | ||
// Error an Api error | ||
Error string // Error this is Line comment | ||
// Error `number` tick comment | ||
ErrorNo int64 | ||
ErrorCtx string // Error `context` tick comment | ||
CreatedAt time.Time // Error time | ||
} |