caicloud/nirvana

Auto parameter string default value without double quotation make api docs generating failed

wutz opened this issue · 4 comments

wutz commented

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"`
}
kdada commented

For non-basic types, you can register custom converters by service.RegisterConverter().

wutz commented
wutz commented
kdada commented

It's a problem. I have not found an effective way to make them work together.