-
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
[NP] Allow custom validations in HTTP Routes apart from @kbn/config-schema #51919
Merged
Merged
Changes from 16 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
93cc5db
[NP] Allow custom validations in HTTP Routes apart from @kbn/config-s…
afharo 318f827
API docs
afharo 1b3088a
Merge branch 'master' into np-decouple-configSchema
elasticmachine f9ea319
Allow validate function in the route handler (run-code validation)
afharo d28e0aa
Prefix RouteXXX + Params and Body Validation Aliases
afharo 4fddfd1
Fix test broken by lodash
afharo 472a60f
Update API docs
afharo b2e06db
Add default types for simpler manual declaration
afharo 3996c2a
Add run-time validation of the RouteValidateSpec
afharo f5af513
Expose RouteValidationError instead of SchemaTypeError
afharo 8d02bbe
Merge branch 'master' into np-decouple-configSchema
elasticmachine 46c670f
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo db62d75
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo c949643
RouteValidator as a class to match config-schema interface
afharo 1b2165c
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo 336844e
Test for not-inline handler (need to check IRouter for #47047)
afharo bf71f8a
Add preValidation of the input for a safer custom validation
afharo ada74fe
Better types for RouteHandlers
afharo 97d4cdb
[NP] Move route validation to RouteValidator wrapper
afharo 4daabcb
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo 091125a
Use the class only internally but maintain the same API
afharo 9bb014a
[NP] Move route validation to RouteValidator wrapper
afharo dfdcccb
Merge branch 'master' into np-decouple-configSchema
elasticmachine b30e913
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo df9d33a
Fix types
afharo cccfe15
Ensure RouteValidator instance in KibanaRequest.from
afharo f99566d
Fix validator.tests (Buffer.from instead of new Buffer)
afharo d0ac3b9
Default precheck should allow null values
afharo be34522
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo 67bd356
Merge branch 'np-decouple-configSchema' of github.com:afharo/kibana i…
afharo 16ee910
Also allow undefined in preChecks
afharo 83b9da6
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo 6dc23dc
Merge branch 'master' into np-decouple-configSchema
elasticmachine 6a6b0ab
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo c10723a
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo 5c45228
MR feedback fixes
afharo fb0e6ad
Provide RouteValidationResolver to the validation function
afharo be46a67
Add functional tests
afharo ce57c16
Fix new functional tests
afharo 3b930f3
Merge branch 'master' of github.com:elastic/kibana into np-decouple-c…
afharo e394259
Fix validator additional test
afharo 1ece254
Fix test with new resolver
afharo 7d6ea02
Remove unused import
afharo c8c7939
Rename ValidationResolver to ValidationResultFactory and change the i…
afharo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
docs/development/core/server/kibana-plugin-server.routevalidatefunctionreturn.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidateFunctionReturn](./kibana-plugin-server.routevalidatefunctionreturn.md) | ||
|
||
## RouteValidateFunctionReturn type | ||
|
||
Allowed returned format of the custom validate function | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare type RouteValidateFunctionReturn<T> = { | ||
value: T; | ||
error?: never; | ||
} | { | ||
value?: never; | ||
error: RouteValidationError; | ||
}; | ||
``` |
21 changes: 21 additions & 0 deletions
21
...elopment/core/server/kibana-plugin-server.routevalidationerror._constructor_.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) > [(constructor)](./kibana-plugin-server.routevalidationerror._constructor_.md) | ||
|
||
## RouteValidationError.(constructor) | ||
|
||
Constructs a new instance of the `RouteValidationError` class | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
constructor(error: Error | string, path?: string[]); | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| error | <code>Error | string</code> | | | ||
| path | <code>string[]</code> | | | ||
|
20 changes: 20 additions & 0 deletions
20
docs/development/core/server/kibana-plugin-server.routevalidationerror.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidationError](./kibana-plugin-server.routevalidationerror.md) | ||
|
||
## RouteValidationError class | ||
|
||
Error to return when the validation is not successful. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare class RouteValidationError extends SchemaTypeError | ||
``` | ||
|
||
## Constructors | ||
|
||
| Constructor | Modifiers | Description | | ||
| --- | --- | --- | | ||
| [(constructor)(error, path)](./kibana-plugin-server.routevalidationerror._constructor_.md) | | Constructs a new instance of the <code>RouteValidationError</code> class | | ||
|
20 changes: 20 additions & 0 deletions
20
docs/development/core/server/kibana-plugin-server.routevalidator._constructor_.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidator](./kibana-plugin-server.routevalidator.md) > [(constructor)](./kibana-plugin-server.routevalidator._constructor_.md) | ||
|
||
## RouteValidator.(constructor) | ||
|
||
Constructs a new instance of the `RouteValidator` class | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
constructor(validationRule: (data: any) => RouteValidateFunctionReturn<T>); | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| validationRule | <code>(data: any) => RouteValidateFunctionReturn<T></code> | | | ||
|
26 changes: 26 additions & 0 deletions
26
docs/development/core/server/kibana-plugin-server.routevalidator.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidator](./kibana-plugin-server.routevalidator.md) | ||
|
||
## RouteValidator class | ||
|
||
Custom validator class. If @<!-- -->kbn/config-schema is not a valid option in your plugin, you can use this class to define your own validation logic. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare class RouteValidator<T> | ||
``` | ||
|
||
## Constructors | ||
|
||
| Constructor | Modifiers | Description | | ||
| --- | --- | --- | | ||
| [(constructor)(validationRule)](./kibana-plugin-server.routevalidator._constructor_.md) | | Constructs a new instance of the <code>RouteValidator</code> class | | ||
|
||
## Methods | ||
|
||
| Method | Modifiers | Description | | ||
| --- | --- | --- | | ||
| [validate(data, namespace)](./kibana-plugin-server.routevalidator.validate.md) | | | | ||
|
23 changes: 23 additions & 0 deletions
23
docs/development/core/server/kibana-plugin-server.routevalidator.validate.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [RouteValidator](./kibana-plugin-server.routevalidator.md) > [validate](./kibana-plugin-server.routevalidator.validate.md) | ||
|
||
## RouteValidator.validate() method | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
validate(data: any, namespace?: string): T; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| data | <code>any</code> | | | ||
| namespace | <code>string</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`T` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 a bit concerned with the amount of code that users have to write. If you want to declare a request handler separately it doesn't become simpler:
What do you think if we always require users to specify types explicitly? Something like:
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.
Thanks for pointing that out!
I've revisited the type inference and I think I can get to the more sensible point:
RequestHandler
is not (should not) be tied to the Config-Schema/RouteValidation types but to their outputs.TS compiles. Running tests locally and, if all good, I'll push the changes :)