-
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.
feat: permit error (and any) interface definition (#1212)
- Loading branch information
Showing
10 changed files
with
216 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
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,23 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
. "github.com/swaggo/swag/testdata/error/errors" | ||
_ "github.com/swaggo/swag/testdata/error/web" | ||
) | ||
|
||
// Upload do something | ||
// @Summary Upload file | ||
// @Description Upload file | ||
// @ID file.upload | ||
// @Accept multipart/form-data | ||
// @Produce json | ||
// @Param file formData file true "this is a test file" | ||
// @Success 200 {string} string "ok" | ||
// @Failure 400 {object} web.CrossErrors "Abort !!" | ||
// @Router /file/upload [post] | ||
func Upload(w http.ResponseWriter, r *http.Request) { | ||
//write your code | ||
_ = Errors{} | ||
} |
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,14 @@ | ||
package errors | ||
|
||
// CustomInterface some interface | ||
type CustomInterface interface { | ||
Error() string | ||
} | ||
|
||
// Errors errors and interfaces | ||
type Errors struct { | ||
Error error | ||
ErrorInterface CustomInterface | ||
Interface interface{} | ||
Any any | ||
} |
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,69 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "This is a sample server Petstore server.", | ||
"title": "Swagger Example API", | ||
"termsOfService": "http://swagger.io/terms/", | ||
"contact": { | ||
"name": "API Support", | ||
"url": "http://www.swagger.io/support", | ||
"email": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html" | ||
}, | ||
"version": "1.0" | ||
}, | ||
"host": "petstore.swagger.io", | ||
"basePath": "/v2", | ||
"paths": { | ||
"/file/upload": { | ||
"post": { | ||
"description": "Upload file", | ||
"consumes": [ | ||
"multipart/form-data" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"summary": "Upload file", | ||
"operationId": "file.upload", | ||
"parameters": [ | ||
{ | ||
"type": "file", | ||
"description": "this is a test file", | ||
"name": "file", | ||
"in": "formData", | ||
"required": true | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "ok", | ||
"schema": { | ||
"type": "string" | ||
} | ||
}, | ||
"400": { | ||
"description": "Abort !!", | ||
"schema": { | ||
"$ref": "#/definitions/web.CrossErrors" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"web.CrossErrors": { | ||
"type": "object", | ||
"properties": { | ||
"any": {}, | ||
"error": {}, | ||
"errorInterface": {}, | ||
"interface": {} | ||
} | ||
} | ||
} | ||
} |
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,27 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/swaggo/swag/testdata/error/api" | ||
) | ||
|
||
// @title Swagger Example API | ||
// @version 1.0 | ||
// @description This is a sample server Petstore server. | ||
// @termsOfService http://swagger.io/terms/ | ||
|
||
// @contact.name API Support | ||
// @contact.url http://www.swagger.io/support | ||
// @contact.email [email protected] | ||
|
||
// @license.name Apache 2.0 | ||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html | ||
|
||
// @host petstore.swagger.io | ||
// @BasePath /v2 | ||
|
||
func main() { | ||
http.HandleFunc("/testapi/upload", api.Upload) | ||
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,7 @@ | ||
package web | ||
|
||
import ( | ||
"github.com/swaggo/swag/testdata/error/errors" | ||
) | ||
|
||
type CrossErrors errors.Errors |