Closed JackLeeHal closed 4 years ago
I've not entirely sure what the issue is. Let's discuss with some examples.
The following OpenAPI spec (containing optional and required string parameters):
Produces the following Sysl:
# sysl import --app-name PetStore -i petstore.yaml -o petstore.sysl
PetStore "Petstore":
@version = "1.0.0"
@description =:
| No description.
/pets:
GET ?strReq=string&strOpt=string?:
| No description.
return error <: Error
!type Error:
code <: int32:
@json_tag = "code"
message <: string:
@json_tag = "message"
Which has it's optional and required query parameters parsed by the following block of code:
req.StrReq = restlib.GetQueryParam(r, "strReq")
var StrOptParam string
var convErr error
StrOptParam = restlib.GetQueryParam(r, "strOpt")
req.StrOpt, convErr = convert.StringToStringPtr(ctx, StrOptParam)
if convErr != nil {
common.HandleError(ctx, w, common.BadRequestError, "Invalid request", convErr, s.genCallback.MapError)
return
}
Can you describe what the issue is using this example?
I had a look into this issue and discovered that the bug is only because we were using an old version of the transform (the latest version already has this issue fixed). However I did notice that you aren't checking for an empty string like you do for all the other kinds of parameters. I think you should change this code:
${reqQueryParams where .@item('type')('primitive')?.s:"" = "STRING" >> \{'name': (s: name), ...}
$`req.${go.name(name)} = restlib.GetQueryParam(r, "${name}")`
::\i:\n}
To:
${reqQueryParams where .@item('type')('primitive')?.s:"" = "STRING" >> \{'name': (s: name), ...}
$`req.${go.name(name)} = restlib.GetQueryParam(r, "${name}")
if req.${go.name(name)} == "" {
common.HandleError(ctx, w, common.BadRequestError, "${name} query length is zero", nil, s.genCallback.MapError)
return
}`
::\i:\n}
Thanks. Your approach is heading in the right direction but doesn't differentiate between missing and empty parameters. I'll prioritise and get this assigned.
The code already does similar for all the required header params.
Right, it's caused by our transform out of date, so close this issue.
Please do not post any internal, closed source snippets on this public issue tracker!
Description
When string param in URL is required, generated code will contain error because it will be parsed by: https://github.com/anz-bank/sysl-go/blob/master/convert/convert.go#L67
Automatically to a pointer, but it's a
string
type not*string
Steps to Reproduce
Expected behavior
no error in the generated code
Actual behavior
error in the generated code
Your Environment
Our solution
change arrai transform from: https://github.com/anz-bank/sysl-go/blob/master/codegen/arrai/auto/svc_handler.arrai#L159-L171
To:
The generated code will change from:
To: