-
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: support nested struct * Fix a problem: when a struct be defined in the file which the API exists, it can not be parsed. * Add test cases for nested struct
- Loading branch information
Showing
9 changed files
with
188 additions
and
2 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
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,22 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/swaggo/swag/testdata/nested2" | ||
) | ||
|
||
type Foo struct { | ||
Field1 string | ||
OutsideData *nested2.Body | ||
} | ||
|
||
// @Description get Foo | ||
// @ID get-foo | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} api.Foo | ||
// @Router /testapi/get-foo [get] | ||
func GetFoo(c *gin.Context) { | ||
//write your code | ||
var _ = Foo{} | ||
} |
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,5 @@ | ||
package common | ||
|
||
type Data struct { | ||
Value string `json:"message"` | ||
} |
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,57 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "This is a sample server", | ||
"title": "Swagger Example API", | ||
"termsOfService": "http://swagger.io/terms/", | ||
"contact": {}, | ||
"license": {}, | ||
"version": "1.0" | ||
}, | ||
"host": "petstore.swagger.io", | ||
"basePath": "/v2", | ||
"paths": { | ||
"/testapi/get-foo": { | ||
"get": { | ||
"description": "get Foo", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"operationId": "get-foo", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/api.Foo" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"api.Foo": { | ||
"type": "object", | ||
"properties": { | ||
"field1": { | ||
"type": "string" | ||
}, | ||
"outsideData": { | ||
"type": "object", | ||
"$ref": "#/definitions/nested2.Body" | ||
} | ||
} | ||
}, | ||
"nested2.Body": { | ||
"type": "object", | ||
"properties": { | ||
"value": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,20 @@ | ||
package composition | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/swaggo/swag/testdata/nested/api" | ||
) | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample server | ||
// @termsOfService http://swagger.io/terms/ | ||
|
||
// @host petstore.swagger.io | ||
// @BasePath /v2 | ||
|
||
func main() { | ||
r := gin.New() | ||
r.GET("/testapi/get-foo", api.GetFoo) | ||
r.Run() | ||
} |
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,5 @@ | ||
package nested2 | ||
|
||
type Body struct { | ||
Value string `json:"value"` | ||
} |