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

Can't use optionnal parameter in Router @:post #110

Open
ErikRikoo opened this issue Apr 28, 2020 · 1 comment
Open

Can't use optionnal parameter in Router @:post #110

ErikRikoo opened this issue Apr 28, 2020 · 1 comment

Comments

@ErikRikoo
Copy link

If I am using a @:post Root with optionnal parameter like:

@:post('/send-mail')
public function sendMail(body:{name:String, ?subject:String}):HttpStatusCode {
    trace(body);
    return OK;
}

I get on client side:

{
   code: 422
   data: {"error":"missing field "subject" at characters 0 - 14}
   message: "Unprocessable Entity"
}

When giving: {"name":"bar\"}

The issue is fixed if I am passing an empty string to it, so it seems that it is the optionnal parameter feature that is not working

@kevinresol
Copy link
Member

kevinresol commented Apr 28, 2020

Your case should be handled now. But we still need to work out the more complex case where the object wrapper itself is optional. This might possibly be forbidden except for keyword objects.

example (allow):

@:post
function(?body:{foo:String, ?bar:Int})

example (disallow):

@:post
@:params(obj.foo = query['foo'], obj.bar = body['bar'])
function(?obj:{foo:String, ?bar:Int})

with error like: argument "obj" cannot be optional because it contains multiple parameter sources

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

2 participants