Skip to content
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

[config-schema] error when using custom validation function with oneOf / UnionType #64906

Open
pgayvallet opened this issue Apr 30, 2020 · 1 comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Configuration Settings in kibana.yml Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@pgayvallet
Copy link
Contributor

pgayvallet commented Apr 30, 2020

This test:

import { schema } from '..';

describe('foo', () => {
  it('bar', () => {
    const s = schema.oneOf([schema.string(), schema.number()], {
      validate: value => {
        return undefined;
      },
    });
    s.validate('a string');
  });
});

currently fails with:

TypeError: schema.custom is not a function
at new Type (packages/kbn-config-schema/src/types/type.ts:61:23)
at new UnionType (packages/kbn-config-schema/src/types/union_type.ts:29:5)
at Object.oneOf (packages/kbn-config-schema/src/index.ts:179:10)

seems to be caused by something around

if (options.validate) {
schema = schema.custom(options.validate);
}

UnionType is based on joi's alternatives type: AlternativesSchema which extends AnySchema.

However after a closer look, this custom definition is not in joi's package, but in our custom joi definition file:

interface AnySchema {
custom(validator: (value: any) => string | void): this;
}

so it's very likely that custom is not actually present on all joi implementations of AnySchema and that our definition is wrong.

Maybe other types are also affected by this bug.

@pgayvallet pgayvallet added bug Fixes for quality problems that affect the customer experience Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform labels Apr 30, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Configuration Settings in kibana.yml Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

3 participants