added alternative swagger @failure
This commit is contained in:
parent
0e372a4e51
commit
315527ee72
|
@ -3,6 +3,10 @@
|
|||
|
||||
A simple Go-powered REST API kata.
|
||||
|
||||
## HTTP Server
|
||||
|
||||
- KISS: Use built-in `http` package. https://gin-gonic.com/ looks cooler but also adds dozens of dependencies 😮 No need for a "fully-featured" web framework.
|
||||
|
||||
## Swagger
|
||||
|
||||
- Exposed at `http://localhost:8080/docs`
|
||||
|
|
23
docs/docs.go
23
docs/docs.go
|
@ -38,6 +38,29 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pokemon/{name}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "Find a specific Pokemon by name",
|
||||
"operationId": "get-specific-pokemon",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/pokemon.Pokemon"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
|
|
|
@ -32,6 +32,29 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pokemon/{name}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "Find a specific Pokemon by name",
|
||||
"operationId": "get-specific-pokemon",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/pokemon.Pokemon"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "error",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
|
|
|
@ -48,4 +48,19 @@ paths:
|
|||
schema:
|
||||
$ref: '#/definitions/pokemon.Pokemon'
|
||||
summary: get all Pokemon
|
||||
/pokemon/{name}:
|
||||
get:
|
||||
operationId: get-specific-pokemon
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/pokemon.Pokemon'
|
||||
"500":
|
||||
description: error
|
||||
schema:
|
||||
type: string
|
||||
summary: Find a specific Pokemon by name
|
||||
swagger: "2.0"
|
||||
|
|
|
@ -7,6 +7,12 @@ import (
|
|||
"pokedex/rest"
|
||||
)
|
||||
|
||||
// @Summary Find a specific Pokemon by name
|
||||
// @ID get-specific-pokemon
|
||||
// @Produce json
|
||||
// @Success 200 {object} Pokemon
|
||||
// @failure 500 {string} string "error"
|
||||
// @Router /pokemon/{name} [get]
|
||||
func HandleFindSingle(db *gorm.DB, rw http.ResponseWriter, req *http.Request) {
|
||||
repo := NewRepo(db)
|
||||
name := req.PathValue("name")
|
||||
|
|
Loading…
Reference in New Issue