Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.swaggo not replacing null.Int #1208

Open
smatric opened this issue May 17, 2022 · 6 comments
Open

.swaggo not replacing null.Int #1208

smatric opened this issue May 17, 2022 · 6 comments

Comments

@smatric
Copy link
Contributor

smatric commented May 17, 2022

I am unable to override null.Int in .swaggo file.

handler.go:

import "gopkg.in/guregu/null.v4"

type params struct {
	FStyleId       null.Int   `json:"f-styleId" form:"f-styleId" validate:"gte=0"`

I tried running swag init with any of the lines below in .swaggo and none of them worked (I also tried "integer" instead of "int"):

replace gopkg.in/guregu/null.v4@v4.0.0/null.Int int
replace gopkg.in/guregu/null.v4@v4.0.0.null.Int int
replace gopkg.in/guregu/null.v4/null.Int int
replace gopkg.in/guregu/null.v4.null.Int int
replace null.Int int

output:

swag init -g api.go --outputTypes "go,json" --overridesFile .swaggo
2022/05/17 13:55:00 Using overrides from .swaggo
2022/05/17 13:55:00 Generate swagger docs....
...
2022/05/17 13:55:00 ParseComment error in file .../api/handlers/wheels/handler.go :cannot find type definition: null.Int
make: *** [swag] Error 1

Swag version: 1.8.1
Go version: go1.17.5 darwin/arm64
OS: macOS 12.3.1

@victorien-a
Copy link

victorien-a commented May 18, 2022

Exactly the same issue for me. There is no way to specify a rule

@ubogdan
Copy link
Contributor

ubogdan commented Jun 18, 2022

We release #1209 in 1.8.4

@C0Nd3Mnd
Copy link

Not sure if I'm doing something wrong, but it still doesn't work for me with 1.8.4. Swagger still shows null.String like this in the example value:

{
  "title": {
    "string": "string",
    "valid": true
  },
}

What it should look like:

{
  "title": "string"
}

I tried all variations listed above in the .swaggo file:

replace null.String string
replace gopkg.in/guregu/null.v4/null.String string
replace gopkg.in/guregu/null.v4@v4.0.0/null.String string
replace gopkg.in/guregu/null.v4.null.String string
replace gopkg.in/guregu/null.v4@v4.0.0.null.String string

The struct looks like this (other fields omitted):

type Employee struct {
	Title          null.String `db:"title" json:"title"`
}

@smatric
Copy link
Contributor Author

smatric commented Jul 21, 2022

I updated the module to 1.8.4 and running the command didn't work either. I had to recompile the executable:

$ go get -u github.com/swaggo/swag/cmd/swag
$ go install github.com/swaggo/swag/cmd/swag@latest

Then running the following command worked for me:

swag init -g api.go --outputTypes "go,json" --overridesFile docs/.swaggo

My .swaggo file:

replace null.String string

(The first line in yours looks fine.)

My struct:

type params struct {
    Test          null.String `json:"test" form:"test" validate:"gte=-999,lte=999"`
    // other fields
}

@C0Nd3Mnd
Copy link

Interesting. I'll try this tomorrow! Thanks for sharing.

@C0Nd3Mnd
Copy link

Works just fine, thanks again.

Makes sense you have to update the CLI as well, oversight on my part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants