Add isConfigSchema typeguard and stop using instanceof Type checks in core#63821
Conversation
|
Pinging @elastic/kibana-platform (Team:Platform) |
3a26331 to
3c3e479
Compare
| router.get( | ||
| { | ||
| path: '/api/core_config_schema/foo', | ||
| validate: { | ||
| query: schema.object({ | ||
| foo: schema.string(), | ||
| bar: schema.number(), | ||
| }), | ||
| }, |
There was a problem hiding this comment.
Note: the presence/addition of this plugin is sufficient to test the fix, as all test suites in test/plugin_functional would fail with Expected a valid validation logic declared with '@kbn/config-schema' package or a RouteValidationFunction at key: [query]when the server loads the plugin. I will remove the plugin when we have other test plugins using route validation, probably in #63549 as it got one.
There was a problem hiding this comment.
Yea, I agree. I was wondering if I should remove it. I initially added it as the issue is not easily reproductible outside of the CI builds, but now that I got a green build, I can remove it if we think this is better. WDYT?
| import { Type } from '../types'; | ||
|
|
||
| export function isConfigSchema(obj: any): obj is Type<any> { | ||
| return obj ? obj.__isKbnConfigSchemaType === true : false; |
There was a problem hiding this comment.
I started with the ?. syntax, but it looks like the packages are not transpiled the same way src is, and I was getting CI failures with
return obj?.__isKbnConfigSchemaType === true;
^
SyntaxError: Unexpected token .
in karma tests...
| router.get( | ||
| { | ||
| path: '/api/core_config_schema/foo', | ||
| validate: { | ||
| query: schema.object({ | ||
| foo: schema.string(), | ||
| bar: schema.number(), | ||
| }), | ||
| }, |
| expect(isConfigSchema(schema.stream())).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for every primitive types', () => { |
There was a problem hiding this comment.
| it('returns false for every primitive types', () => { | |
| it('returns false for every javascript data type', () => { |
|
retest |
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / kibana-xpack-agent / X-Pack Detection Engine API Integration Tests.x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses·ts.detection engine api security and spaces enabled find_statuses should return a single rule status when a single rule is loaded from a find status with defaults addedStandard OutStack TraceHistory
To update your PR or re-run it, just comment with: |
…in core (elastic#63821) * add isConfigSchema type guard * replace instanceof checks with isConfigSchema * add dummy test plugin using a route with validation schema * remove `?.` prop access * remove test plugin * fix test description
Summary
Fix #61652
Add a isConfigSchema type guard to
kbn/config-schemaand replaceinstanceof Typechecks in core with it.Checklist