Skip to content

Commit

Permalink
Resolves #102.
Browse files Browse the repository at this point in the history
  • Loading branch information
back2dos committed May 5, 2020
1 parent a6b1ed7 commit e9d8326
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/tink/web/macros/Arguments.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,25 @@ class Arguments {
case [true, None]:
ATCapture;
case [false, None]:
if(!optional) {
pos.error('`${stringifyArgAccess(access)}` is not used. Please specify its use with the @:params metadata or capture it in the route paths');
} else {
if(!optional)
tryQuery(paths, access, pos);
else
ATCapture;
}
}
}

static function tryQuery(paths:Paths, access:ArgAccess, pos:Position) {
var access = stringifyArgAccess(access);
for (p in paths)
if (!Lambda.exists(p.query, v -> switch v {
case PCapture(v): stringifyArgAccess(v) == access;
case PConst(_): false;
}))
p.pos.error('${p.expr.toString()} does not capture required parameter `$access`. Please specify its use with the @:params metadata or capture it.');

return ATCapture;
}

static function stringifyArgAccess(access:ArgAccess) {
return switch access {
case Plain(name): name;
Expand Down
6 changes: 5 additions & 1 deletion tests/Fake.hx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Fake {
@:post public function textual(body:String)
return body;

@:get('/queryParam?param=$value')
public function queryParam(value:String)
return { value: value };

@:produces('foo')
@:post public function streamingFoo(body:RealSource)
return body;
Expand Down Expand Up @@ -163,7 +167,7 @@ class Fake {

@:post public function post(body: { foo:String, bar: Int })
return body;

@:post public function optional(body: { foo:String, ?bar: Int })
return {bar:body.bar};

Expand Down
6 changes: 6 additions & 0 deletions tests/ProxyTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ class ProxyTest {
var r = new tink.web.proxy.Remote<Issue47>(null, null);
return asserts.done();
}

public function issue109()
return
proxy.queryParam('foobar').next(
recv -> assert(recv.value == 'foobar')
);
}

interface Issue79Base<T> {
Expand Down

0 comments on commit e9d8326

Please sign in to comment.