-
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
Support extending config schemas #59083
Comments
Pinging @elastic/kibana-platform (Team:Platform) |
elasticsearch: schema.object({
...configSchema,
somethingNew: schema.string()
}) would be ideal, however The second proposal seems more realistic, by adding the elasticsearch: configSchema.extends({logFetchCount: schema.number()}) |
There could be |
elasticsearch: schema.object({
...configSchema.getRaw(),
somethingNew: schema.string()
}) would then work. Notable difference with My other concern is regarding TS typing, but I think ObjectType<P extends Props = any> extends Type<ObjectResultType<P>>
getRaw(): P (or maybe ObjectResultType<P>) would 'simply' work. |
Would it be possible to change the |
@chrisronline that would require some additional work. Not sure we have capacity at the moment. Could you simply copy ES config schema locally for a time being? I'm also wondering why we cannot place |
@restrry Yes I can do that.
We could do this, but I wasn't sure of the effort involved with supporting the override. |
#67357 addresses the initial request, by adding a Going further than that, like allowing to edit or create a new schema with altered options, is going to be difficult to implement properly and totally: We could start by adding a const origin = schema.object({
initial: schema.string(),
}, options);
const extended = schema.object(initial.getRaw(), { ...initial.getOptions(), ...additionalOptions }) However the two approaches I tried got some severe limitations: Adding on the root classThe root kibana/packages/kbn-config-schema/src/types/type.ts Lines 24 to 27 in c4ddd00
This would work to change the defaultValue for example, but not any option defined by the superclass, such as kibana/packages/kbn-config-schema/src/types/object_type.ts Lines 60 to 61 in 442b6d7
Adding to the child classWe could also add the There are a few issue with this: 1/ currently, the kibana/packages/kbn-config-schema/src/index.ts Lines 77 to 83 in c4ddd00
Meaning that function string(options?: StringOptions): Type<string> {
return new StringType(options);
} would become function string(options?: StringOptions): StringType {
return new StringType(options);
} Structured / Complex types issuesHowever, the non-basic, structured types such as const schema = schema.oneOf([schema.string(), schema.number()]);
schema.getOptions() // what should I return?? properly allowing to 'extend' structured types would require adding specific composition API to each of them. For example for const oneOfSchema = schema.oneOf([schema.string(), schema.number()]);
oneOfSchema.getTypes()// would return [instanceof Type<string>, instanceof Type<number>]
// could be used like
schema.oneOf([...oneOfSchema.getTypes(), schema.someOtherType()]); However once again, the Meaning that the nested types would not be properly typed: const oneOfSchema = schema.oneOf([schema.string(), schema.number()]);
oneOfSchema.getTypes()[0].getOptions() // error: property `getOptions` is not defined on type `Type<string>` Adding a second generic type to
|
I created #68067 as an alternative implementing I agree that the Tell me what you think |
I feel that going with |
As discussed with @joshdover and @pgayvallet, it'd be nice to extend a previously defined config schema.
More specifically, given an existing config schema, we should be able to do:
or
The text was updated successfully, but these errors were encountered: