-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[HTTP/OAS] Prepare router and versioned router for generating OAS #180275
[HTTP/OAS] Prepare router and versioned router for generating OAS #180275
Conversation
@@ -7,6 +7,8 @@ | |||
*/ | |||
|
|||
export { filterHeaders } from './src/headers'; | |||
export { versionHandlerResolvers } from './src/versioned_router'; |
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.
Not used in this PR, just exporting in preparation for future PR, happy to hold off on this change
method: 'post', | ||
path: '/', | ||
validationSchemas: { body: validation, query: validation, params: validation }, | ||
isVersioned: false, |
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.
Mainly making sure that the above two fields are included as expected, will be used by OAS generation script
@@ -228,7 +228,7 @@ export interface AddVersionOpts<P, Q, B> { | |||
* Validation for this version of a route | |||
* @public | |||
*/ | |||
validate: false | FullValidationConfig<P, Q, B>; | |||
validate: false | FullValidationConfig<P, Q, B> | (() => FullValidationConfig<P, Q, B>); // Provide a way to lazily load validation schemas |
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 will enable ResponseOps and other plugins to provide route schemas lazily. Useful for registries that only know schema shapes after setup/start time.
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'm surprised to not see associated code changes to support passing a function now. Unless I missed it or it already worked and just wasn't documented (but traditional routes don't support that AFAIK, so...)
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 have some new code in packages/core/http/core-http-router-server-internal/src/versioned_router/core_versioned_route.ts
to extract the validations.
But yeah, we should probably make IRouter symmetrical! Will update and add a couple of tests.
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.
Pushed some updates that contain tests and update Router
type and implementatio to support lazy validation
/ci |
/ci |
Pinging @elastic/kibana-core (Team:Core) |
One last try 😅 |
/ci |
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.
Looking good overall.
Just asked for a few clarifications before approval:
@@ -44,7 +40,7 @@ const createRequest = ( | |||
); | |||
|
|||
describe('Versioned route', () => { | |||
let router: IRouter; | |||
let router: Router; |
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.
Why do we need to use the concrete implementation's as type here now? It doesn't seem necessary for the change on expected arguments you did below.
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.
It's for CoreVersionedRoute to pass an additional argument "isVersioned" when registering a route.
handler: RequestHandler<P, Q, B, Context, Method>, | ||
internalOptions: { isVersioned: boolean } = { isVersioned: false } |
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.
So if I understand correctly, this new internalOptions
third parameter doesn't leak on the public interface because we only specify it on the implementation via this new InternalRegistrar
type on our method helpers than extends IRouter
, is that correct?
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.
Yes, exactly
packages/core/http/core-http-router-server-internal/src/versioned_router/mocks.ts
Outdated
Show resolved
Hide resolved
|
||
/** @internal */ | ||
export interface VersionedRouterArgs { | ||
router: IRouter; | ||
router: Router; |
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.
(thinking out loud) I get why we did that, I still can't avoid thinking it's a shame that we're now forced to use our concrete implementation directly here. Relation was pure before, it's no longer.
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 agree, it is a :shame: moment. One alternative is that we can make something like an InternalIRouter
interface to keep things more pure. Wdyt?
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.
Probably don't need to add a type InternalIRouter = PublicMethodOf<Router>
@@ -228,7 +228,7 @@ export interface AddVersionOpts<P, Q, B> { | |||
* Validation for this version of a route | |||
* @public | |||
*/ | |||
validate: false | FullValidationConfig<P, Q, B>; | |||
validate: false | FullValidationConfig<P, Q, B> | (() => FullValidationConfig<P, Q, B>); // Provide a way to lazily load validation schemas |
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'm surprised to not see associated code changes to support passing a function now. Unless I missed it or it already worked and just wasn't documented (but traditional routes don't support that AFAIK, so...)
Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services) |
@@ -198,7 +198,7 @@ export interface VersionedRouteResponseValidation { | |||
* Versioned route validation | |||
* @public | |||
*/ | |||
export interface FullValidationConfig<P, Q, B> { | |||
export interface VersionedRouteValidation<P, Q, B> { |
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.
Renamed for consistency, not necessary change for this PR
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Public APIs missing exports
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
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.
LGTM
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.
Synthetics changes look good
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.
Thank you @jloleysens
Summary
Part of #180056
Notes