-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
There was a problem hiding this 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']) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
packages/rest/test/unit/rest.server/rest.server.open-api-spec.unit.ts
Outdated
Show resolved
Hide resolved
@@ -202,7 +208,7 @@ export interface RouteEntry { | |||
/** | |||
* OpenAPI operation spec | |||
*/ | |||
readonly spec: OperationObject; | |||
readonly spec: LB4OperationObject; |
There was a problem hiding this comment.
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()
methodRoute
andControllerRoute
classes (and their constructors)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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] = {}; | ||
} | ||
|
There was a problem hiding this comment.
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; | ||
} | ||
|
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
87ed8cc
to
1609efb
Compare
There was a problem hiding this 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.
So @raymondfeng what about |
Maybe something like |
Let's go with |
Add `x-visibility` extension property to OpenAPI spec.
1609efb
to
b9e34cd
Compare
Add
x-visibility
extension property to OpenAPI spec.Addresses #1874.
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated