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

feat: add 'x-visibility' extension property to OpenAPI spec #1896

Merged
merged 1 commit into from
Oct 24, 2018

Conversation

hacksparrow
Copy link
Contributor

@hacksparrow hacksparrow commented Oct 22, 2018

Add x-visibility extension property to OpenAPI spec.

Addresses #1874.

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

@hacksparrow hacksparrow self-assigned this Oct 22, 2018
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Great start, let's polish the details now.

if (!paths[route.path]) {
paths[route.path] = {};
}
if (!route.spec['x-internal']) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use reverse logic + early return to make the code easier to follow and less nested.

if (route.spec['x-internal']) continue;

function greet() {}
function meet() {}
server.route(
new Route(
Copy link
Member

Choose a reason for hiding this comment

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

Let's use the recently introduced sugar API instead of calling new Route.

server.route('get', '/greet', {'x-internal': true, /*...*/}, greet);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VSC is complaining No overload expects 4 arguments, but overloads do exist that expect either 1 or 6 arguments..

Did you mean something like this?

server.route('get', '/greet', spec, MyController, factory, 'greet');

We'll have to create MyController and factory, in that case. It adds more to the test code.

Copy link
Member

Choose a reason for hiding this comment

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

I opened a pull request to fix that problem, see #1898

@@ -202,7 +208,7 @@ export interface RouteEntry {
/**
* OpenAPI operation spec
*/
readonly spec: OperationObject;
readonly spec: LB4OperationObject;
Copy link
Member

Choose a reason for hiding this comment

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

This change is not strictly necessary because OperationObject type already supports arbitrary extension (additional properties). Having said that, I see how LB4OperationObject can be useful because it allows IDEs like VisualStudio Code to offer auto-completion and also the compiler can check that developers don't assign a non-boolean value to this extension by a mistake.

So, if we want to keep LB4OperationObject, then please find other places in our public API that are accepting OperationObject and change them accordingly. Few examples to get you started:

  • @operation decorator and verb-based shortcuts like @get
  • server.route() method
  • Route and ControllerRoute classes (and their constructors)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's keep it and update the references.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing OperationObject with LB4OperationObject in all instances is not easy, let's not do it in this PR. So, for not let's keep it as such. Reverting to readonly spec: OperationObject.

if (!paths[route.path]) {
paths[route.path] = {};
}

Copy link
Member

Choose a reason for hiding this comment

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

please preserve this empty line - it serves as a visual delimiter

paths[route.path][route.verb] = route.spec;
}

Copy link
Member

Choose a reason for hiding this comment

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

please preserve this empty line - it serves as a visual delimiter to make the code easier to read (skim through)

greet,
),
);
server.route(new Route('get', '/meet', {responses: {}, spec: {}}, meet));
Copy link
Member

Choose a reason for hiding this comment

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

Please replace server.route(new Route(...)) to server.route(...), see #1898

@@ -156,13 +156,12 @@ export class RoutingTable {
const paths: PathObject = {};

for (const route of this._router.list()) {
if (route.spec['x-internal']) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think x-internal reflects the purpose very well. Do we want to hide the route from OpenAPI spec or completely disable the route? I see a few options here:

  • private (hidden from the spec and reports 404 error for the route)
  • unlisted (hidden from the spec, but the route is still accessible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We just want to hide the route from OpenAPI spec, so unlisted is what we want.

What purpose could a route that's hidden from the spec and 404s, serve?

@bajtos, thoughts on @raymondfeng's suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

We want to hide the route from the generated OpenAPI spec, but still be available via the REST API for clients that know the route. Example use cases:

  • a health endpoint used for DevOps monitoring
  • an internal endpoint used by API Explorer to load dynamic configuration for a static-only front-end (we do this in LB 3.x now)
  • a catch-all route to serve static files - see fix: optimize serving static files #1848

Personally, I prefer x-hidden: true or x-documented: false most.

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Besides the alternative names offered in my comment in the discussion above, I guess I can live with x-unlisted or even x-internal too, although I find them less descriptive than my proposals.

The rest of the patch looks good to me.

@hacksparrow
Copy link
Contributor Author

So @raymondfeng what about x-hidden: true or x-documented: false?

@raymondfeng
Copy link
Contributor

Maybe something like x-visibility: unlisted or x-visibility: undocumented? This way, we can extend the values in the future.

@bajtos
Copy link
Member

bajtos commented Oct 23, 2018

Let's go with x-visibility: undocumented then 👍

Add `x-visibility` extension property to OpenAPI spec.
@hacksparrow hacksparrow changed the title feat: add 'x-internal' extension property to OpenAPI spec feat: add 'x-visibility' extension property to OpenAPI spec Oct 24, 2018
@hacksparrow hacksparrow merged commit 5634e18 into master Oct 24, 2018
@hacksparrow hacksparrow deleted the fix/#1874 branch October 24, 2018 05:49
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.

3 participants