nirvana
nirvana copied to clipboard
Auto parameter string default value without double quotation make api docs generating failed
Is this a BUG REPORT or FEATURE REQUEST?:
/kind bug
What happened:
nirvana api
starting failed with logging:
FATAL 0321-12:50:40.034+08 api.go:61 | json: error calling MarshalJSON for type spec.Swagger: json: error calling MarshalJSON for type *spec.Paths: json: error calling MarshalJSON for type spec.PathItem: json: error calling MarshalJSON for type *spec.Operation: json: error calling MarshalJSON for type spec.OperationProps: json: error calling MarshalJSON for type spec.Parameter: json: error calling MarshalJSON for type *swagger.rawJSON: invalid character 'w' looking for beginning of value
What you expected to happen:
nirvana api
can work correctly.
How to reproduce it (as minimally and precisely as possible):
Define a struct which relating to Auto parameter, set string default value without double quotation:
type Option struct {
Hello string `source:"Query,hello,default=world"`
}
Anything else we need to know?:
If set default value with double quotation, then nirvana api
can work, but bussiness function will be getting addition double quotation from that option.
type Option struct {
Hello string `source:"Query,hello,default=\"world\""`
}
Additionally, how to support not basic type correctly, e.g.
type Option struct {
Hello string `source:"Query,hello,default=\"world\""`
Timeout time.Duration `source:"Query,timeout,default=10s"`
Perm os.FileMode `source:"Query,perm,default=0755"`
}
For non-basic types, you can register custom converters by service.RegisterConverter()
.
But it does not work with api docs generating by resgister converter.
Wei Guo [email protected]于2019年3月21日 周四下午7:09写道:
For non-basic types, you can register custom converters by service.RegisterConverter().
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/caicloud/nirvana/issues/272#issuecomment-475189313, or mute the thread https://github.com/notifications/unsubscribe-auth/AJBTwUbtHiLl4mP6pZVrq864MYgMM9uUks5vY2hYgaJpZM4cAuV1 .
The marjor issue is normal parameter default value coming from json decoding which will including double quotation for string type or base string type, but for auto parameter default value coming from tag default raw value. Taizeng Wu [email protected]于2019年3月21日 周四下午7:13写道:
But it does not work with api docs generating by resgister converter.
Wei Guo [email protected]于2019年3月21日 周四下午7:09写道:
For non-basic types, you can register custom converters by service.RegisterConverter().
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/caicloud/nirvana/issues/272#issuecomment-475189313, or mute the thread https://github.com/notifications/unsubscribe-auth/AJBTwUbtHiLl4mP6pZVrq864MYgMM9uUks5vY2hYgaJpZM4cAuV1 .
It's a problem. I have not found an effective way to make them work together.