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

For discussion: Support spec-level x-modules, and fix modules at API level #56

Merged
merged 7 commits into from
Aug 17, 2016

Conversation

gwicke
Copy link
Member

@gwicke gwicke commented Aug 12, 2016

  • Support x-modules at spec level (same level as paths). This allows modules
    to define top-level entry points, like /somepath. The alternative would be
    to support paths: { '': { 'x-modules': {...} } }, but imho that's uglier
    than x-modules at the path level. The swagger spec requires paths to start
    with '/' as well, so this would not be a valid swagger spec.
  • Preserve operations & some other scope data for API-level modules.
    Otherwise, modules at API level do not have access to their own operations.

Deterministically resolve conflicts & add specific keys before wildcards.

Without this patch, a path combination like

  /{something}/else
  /robots.txt

was not accepted, as v8 happens to preserve the order of object keys in this
case, and the wildcard would be added before the fixed value. This would cause
the router to enter the wildcard path when trying to add robots.txt.

With this patch, more specific paths (without wildcards) are built first,
equivalent to:

  /robots.txt
  /{something}/else
@gwicke gwicke changed the title WIP: Support spec-level x-modules, and fix modules at API level For discussion: Support spec-level x-modules, and fix modules at API level Aug 12, 2016
@gwicke
Copy link
Member Author

gwicke commented Aug 12, 2016

/cc @wikimedia/services, for discussion.

@coveralls
Copy link

coveralls commented Aug 12, 2016

Coverage Status

Coverage decreased (-0.9%) to 91.968% when pulling c419cb1 on gwicke:module_fixes into d684563 on wikimedia:master.

return P.each(Object.keys(paths), function(pathPattern) {
// while building the tree. Also sort(), so that fixed path segments sort
// before patterns (by virtue of `[a-zA-Z/] < '{'`).
return P.each(Object.keys(paths).sort(), function(pathPattern) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, let's sort a copy like we've discussed in the other PR?

@Pchelolo
Copy link
Contributor

I agree this is most like what needs to be done, I've been experimenting with the same stuff yesterday. Although, this code is some complex that I can't really say if this would have any weird implications or not, so I suggest testing RB and Change-Prop with this.

@@ -340,6 +340,7 @@ Router.prototype._registerMethods = function(node, pathspec, scope) {
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove empty line

@d00rman
Copy link
Contributor

d00rman commented Aug 15, 2016

This depends on #55, so let's settle that one first.

@coveralls
Copy link

coveralls commented Aug 15, 2016

Coverage Status

Coverage decreased (-0.9%) to 91.975% when pulling 7c59c73 on gwicke:module_fixes into d684563 on wikimedia:master.

@coveralls
Copy link

coveralls commented Aug 15, 2016

Coverage Status

Coverage decreased (-0.9%) to 91.975% when pulling 7c59c73 on gwicke:module_fixes into d684563 on wikimedia:master.

@gwicke
Copy link
Member Author

gwicke commented Aug 15, 2016

I undid the sorting, as it exposed some latent issues in how we handle path overlaps that weren't easy to fix. For now, we are relying on manually specifying end points in an order that avoids the bugs. I added a FIXME about this issue at the relevant location in the code.

@coveralls
Copy link

coveralls commented Aug 15, 2016

Coverage Status

Coverage decreased (-0.9%) to 91.975% when pulling f067332 on gwicke:module_fixes into d684563 on wikimedia:master.

- Support x-modules at spec level (same level as paths). This allows modules
  to define top-level entry points, like /somepath. The alternative would be
  to support paths: { '': { 'x-modules': {...} } }, but imho that's uglier
  than x-modules at the path level. The swagger spec requires paths to start
  with '/' as well, so this would not be a valid swagger spec.
- Preserve operations & some other scope data for API-level modules.
  Otherwise, modules at API level do not have access to their own operations.
We have some latent issues in the handling of overlapping paths (such as
/foo and /foo{/bar}) that aren't easy to resolve. For now, we are relying on
speccing entry points in just the right order to work around this.
This patch adds a small, private extension that lets us hide private entry
points from the docs by adding an `x-hidden` boolean property at the method
level. This is occasionally useful for "boilerplate" entry points like /robots.txt.

There are discussions about more advanced ACL-based doc hiding at
OAI/OpenAPI-Specification#433, but those haven't
lead anywhere yet. This is a simple solution that will work in the meantime.
@coveralls
Copy link

coveralls commented Aug 17, 2016

Coverage Status

Coverage decreased (-0.9%) to 91.975% when pulling f3fb45a on gwicke:module_fixes into d684563 on wikimedia:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 91.975% when pulling f3fb45a on gwicke:module_fixes into d684563 on wikimedia:master.

var xModules = spec['x-modules'];
if (xModules) {
loadPromise = loadPromise
.then(function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is weird here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 8cae18e.

@Pchelolo
Copy link
Contributor

One nit inlined, other that that GTG

@Pchelolo
Copy link
Contributor

Ok, I'm merging this!

@Pchelolo Pchelolo merged commit 354578d into wikimedia:master Aug 17, 2016
@coveralls
Copy link

coveralls commented Aug 17, 2016

Coverage Status

Coverage decreased (-0.9%) to 91.975% when pulling 2a34935 on gwicke:module_fixes into d684563 on wikimedia:master.

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.

4 participants