Describe the bug
Title's '*' is go file name
The swag version I'm using is 1.6.3.
To Reproduce
Steps to reproduce the behavior:
swag init
2019/09/30 11:23:44 Generate swagger docs....
2019/09/30 11:23:44 Generate general API Info, search dir:./
2019/09/30 11:23:44 ParseComment error in file .go :can not find schema type: ".json"
The annotation are as follows
// @Summary Summary
// @Tags Register
// @Accept x-www-form-urlencoded
// @Produce json
// @Param username formData string true "username"
// @Param mobile formData string true "mobile"
// @Param email formData string true "email"
// @Param platform formData string true "platform"
// @Success 0 {string} json "{"code":0,"data":{"result":"success"}}"
// @failure 412 {object} app.Error
// @Router /race/enroll [post]
Your swag version
e.g. 1.6.3
Your go version
go version go1.12.6 darwin/amd64
Same as me.
My annotation is // @Param auth body structname true "Auth"
And
This error occured
2019/10/01 01:01:51 Generate swagger docs....
2019/10/01 01:01:51 Generate general API Info, search dir:./
2019/10/01 01:01:51 ParseComment error in file routers/packagename/filename.go :can not find schema type: "packagename.body"
Your go version
go1.12.9 linux/amd64
Your swag version
1.6.3
(but same code works on 1.6.2)
Got the same issue, everything was working fine with 1.6.2.
Annotations:
// @Summary Get information
// @ID get-info
// @Description Exposes some information about itself
// @Tags info
// @Accept json
// @Produce json
// @Param X-Auth-Token header string true "X-Auth-Token"
// @Success 200 {string} json "{"version":"0.0.1"}"
// @Failure 401 {object} httputil.HTTPError
// @Router /info [get]
Error:
2019/10/07 13:53:26 ParseComment error in file info.go :can not find schema type: "main.json"
Go version:
go version go1.12.5 linux/amd64
According to API OPERATIONS the third parameter is "data type" which should be a go primitive or struct.
According to API OPERATIONS the third parameter is "data type" which should be a go primitive or struct.
But the annotations were working before the upgrade to version 1.6.3, is this a regression ?
https://github.com/swaggo/swag/issues/532#issuecomment-539461837
But the other exception is http mine-type.
So if you've ever used mine-type or mine_type alias, you have this problem.
I looked up the commit log, as if the last submit thought of mine-type alias as the struct, of the current package, so there would be this error that would prevent the document from being generated
@goldyfruit I have no clue what exactly it is, we need to investigate. But it looks like it came out from a PR that suppose to fix something somewhere.
please paste the swagger.json output of generated code with 1.6.2
// @Summary Get information
// @ID get-info
// @Description Exposes some information about itself
// @Tags info
// @Accept json
// @Produce json
// @Param X-Auth-Token header string true "X-Auth-Token"
// @Success 200 {string} json "{"version":"0.0.1"}"
// @Failure 401 {object} httputil.HTTPError
// @Router /info [get]
Also please provide the output of $ swag --version
Extracted json from provided doc.json
"/info": {
"get": {
"description": "Barem exposes some information about itself",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"info"
],
"summary": "Get information",
"operationId": "get-info",
"parameters": [
{
"type": "string",
"description": "X-Auth-Token",
"name": "X-Auth-Token",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "{\"configdrive-directory\":\"/var/lib/barem/configdrives\",\"version\":\"0.0.1\"}",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/httputil.HTTPError"
}
}
}
}
},
The swagger.json from 1.6.2:
I rolled back to 1.6.2 so the CLI version is:
swag version v1.6.2
My upgrade command to 1.6.3 is:
$ go get -u github.com/swaggo/swag/cmd/[email protected]
As you can see response schema type "JSON" has nothing to do with mime-type.
Please replace
// @Success 200 {string} json "{"version":"0.0.1"}"
with
// @Success 200 {string} string "{"version":"0.0.1"}"
and generate documentation again with swag 1.6.3
My upgrade command to 1.6.3 is:
env GO111MODULE=on go get -u github.com/swaggo/swag/cmd/[email protected]
@ubogdan You were right, changing the type to string solved the issue _(I had to fix few other mistakes)_.
Seems that 1.6.3 is stricter than the previous version.
Thanks for your help.
@ubogdan Thanks for you help.
This is indeed a problem caused by developers' lax requirements for types.
I'm sorry for trying to be compatible with 1.6.2.
Most helpful comment
As you can see response schema type "JSON" has nothing to do with mime-type.
Please replace
// @Success 200 {string} json "{"version":"0.0.1"}"with
// @Success 200 {string} string "{"version":"0.0.1"}"and generate documentation again with swag 1.6.3
My upgrade command to 1.6.3 is: