Skip to content

Conversation

@gwicke
Copy link
Member

@gwicke gwicke commented Nov 21, 2016

So far we used the magic '' node (URL ending in slash) to attach
metadata like API specs. Since we used a regular path, requests for /
would match this metadata node, despite it not necessarily having any
handlers. As a result, handlers registered for a wildcard (ex:
{+path}) were never reached.

This patch avoids this interference by separating metadata out into a
separate 'meta' lookup level. At the node level, this is represented by
the use of the 'meta_' prefix. As a result, regular lookups for URLs
ending in a slash do not match metadata-only nodes any more, which means
that wildcard handlers can kick in as expected. Among other things, this
makes it possible to register wildcard handlers at the API root, such as
/{+path}.

@gwicke
Copy link
Member Author

gwicke commented Nov 21, 2016

/cc @wikimedia/services

gwicke added a commit to gwicke/hyperswitch that referenced this pull request Nov 21, 2016
wikimedia/swagger-router#52 introduces a
separation between metadata-only nodes & actual routes. This separation
avoids conflicts, like metadata-only nodes overriding wildcard matches.

This patch uses this separation in hyperswitch to store API root
information.

Depends on: wikimedia/swagger-router#52 /
swagger-router v0.5.5.
@Pchelolo
Copy link
Contributor

Hm... This seems VERY magical and at least needs some documentation. But overall, can we just revert the order of comparations to try matching {+rest} first and only if it's not there - match the metadata ''?

@gwicke
Copy link
Member Author

gwicke commented Nov 21, 2016

But overall, can we just revert the order of comparations to try matching {+rest} first and only if it's not there - match the metadata ''

I think we still want an explicit route at / to override the wildcard match, which is the curent precedence. It is also consistent with the precedence between other explicit nodes vs. a wildcard.

If we wanted to implement a handler-based fallback in swagger-router, we would need to inspect the node value. We currently have a separation of ownership between hyperswitch (owns value) and swagger-router, so we'd lose that.

@Pchelolo
Copy link
Contributor

Aha, ok, I didn't completely understand what was happening writing the previous comment. Indeed without this meta key we'll either be able to provide the spec or match the route with +, so ye, we can't get around this..

LGTM overall, but could you add some documentation about special handling of the meta key type?

So far we used the magic '' node (URL ending in slash) to attach
metadata like API specs. Since we used a regular path, requests for /
would match this metadata node, despite it not necessarily having any
handlers. As a result, handlers registered for a wildcard (ex:
`{+path}`) were never reached.

This patch avoids this interference by separating metadata out into a
separate 'meta' lookup level. At the node level, this is represented by
the use of the 'meta_' prefix. As a result, regular lookups for URLs
ending in a slash do not match metadata-only nodes any more, which means
that wildcard handlers can kick in as expected. Among other things, this
makes it possible to register wildcard handlers at the API root, such as
`/{+path}`.
@gwicke
Copy link
Member Author

gwicke commented Nov 21, 2016

@Pchelolo, I added doc comments to the setChild / getChild methods detailing the supported kinds of segments / keys.

@Pchelolo
Copy link
Contributor

Pchelolo commented Nov 21, 2016

@gwicke Sweet! Waiting for travis and merging

@Pchelolo Pchelolo merged commit 2d10c3e into wikimedia:master Nov 21, 2016
gwicke added a commit to gwicke/hyperswitch that referenced this pull request Nov 21, 2016
wikimedia/swagger-router#52 introduces a
separation between metadata-only nodes & actual routes. This separation
avoids conflicts, like metadata-only nodes overriding wildcard matches.

This patch uses this separation in hyperswitch to store API root
information.

Depends on: wikimedia/swagger-router#52 /
swagger-router v0.5.5.
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

Successfully merging this pull request may close these issues.

2 participants