chore(joi): upgrade package (#186547)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Alejandro Fernández Haro 2024-06-21 18:56:57 +02:00 committed by GitHub
parent 82391f75e7
commit 114b58290d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 147 additions and 23 deletions

View file

@ -1055,7 +1055,7 @@
"io-ts": "^2.0.5",
"ipaddr.js": "2.0.0",
"isbinaryfile": "4.0.2",
"joi": "^17.7.1",
"joi": "^17.13.3",
"joi-to-json": "^4.3.0",
"jquery": "^3.5.0",
"js-levenshtein": "^1.1.6",

View file

@ -99,7 +99,7 @@ describe('maybe + object', () => {
test('meta', () => {
const maybeString = schema.maybe(schema.string());
const result = maybeString.getSchema().describe().metas[0];
const result = maybeString.getSchema().describe().metas?.[0];
expect(result).toEqual({ [META_FIELD_X_OAS_OPTIONAL]: true });
});

View file

@ -354,6 +354,125 @@ test('unknowns = `ignore` affects only own keys', () => {
).toThrowErrorMatchingInlineSnapshot(`"[foo.baz]: definition for this key is missing"`);
});
describe('nested unknows', () => {
test('allow unknown keys when unknowns = `allow`', () => {
const type = schema.object({
myObj: schema.object({ foo: schema.string({ defaultValue: 'test' }) }, { unknowns: 'allow' }),
});
expect(
type.validate({
myObj: {
bar: 'baz',
},
})
).toEqual({
myObj: {
foo: 'test',
bar: 'baz',
},
});
});
test('unknowns = `allow` affects only own keys', () => {
const type = schema.object({
myObj: schema.object({ foo: schema.object({ bar: schema.string() }) }, { unknowns: 'allow' }),
});
expect(() =>
type.validate({
myObj: {
foo: {
bar: 'bar',
baz: 'baz',
},
},
})
).toThrowErrorMatchingInlineSnapshot(`"[myObj.foo.baz]: definition for this key is missing"`);
});
test('does not allow unknown keys when unknowns = `forbid`', () => {
const type = schema.object({
myObj: schema.object(
{ foo: schema.string({ defaultValue: 'test' }) },
{ unknowns: 'forbid' }
),
});
expect(() =>
type.validate({
myObj: {
bar: 'baz',
},
})
).toThrowErrorMatchingInlineSnapshot(`"[myObj.bar]: definition for this key is missing"`);
});
test('allow and remove unknown keys when unknowns = `ignore`', () => {
const type = schema.object({
myObj: schema.object(
{ foo: schema.string({ defaultValue: 'test' }) },
{ unknowns: 'ignore' }
),
});
expect(
type.validate({
myObj: {
bar: 'baz',
},
})
).toEqual({
myObj: {
foo: 'test',
},
});
});
test('unknowns = `ignore` affects only own keys', () => {
const type = schema.object({
myObj: schema.object(
{ foo: schema.object({ bar: schema.string() }) },
{ unknowns: 'ignore' }
),
});
expect(() =>
type.validate({
myObj: {
foo: {
bar: 'bar',
baz: 'baz',
},
},
})
).toThrowErrorMatchingInlineSnapshot(`"[myObj.foo.baz]: definition for this key is missing"`);
});
test('parent `allow`, child `ignore` should be honored', () => {
const type = schema.object(
{
myObj: schema.object(
{ foo: schema.string({ defaultValue: 'test' }) },
{ unknowns: 'ignore' }
),
},
{ unknowns: 'allow' }
);
expect(
type.validate({
myObj: {
bar: 'baz',
},
})
).toEqual({
myObj: {
foo: 'test',
},
});
});
});
test('handles optional properties', () => {
const type = schema.object({
required: schema.string(),

View file

@ -96,9 +96,14 @@ export class ObjectType<P extends Props = any> extends Type<ObjectResultType<P>>
.keys(schemaKeys)
.default()
.optional()
.unknown(unknowns === 'allow')
.options({ stripUnknown: { objects: unknowns === 'ignore' } });
// We need to specify the `.unknown` property only when we want to override the default `forbid`
// or it will break `stripUnknown` functionality.
if (unknowns === 'allow') {
schema = schema.unknown(unknowns === 'allow');
}
if (options.meta?.id) {
schema = schema.id(options.meta.id);
}

View file

@ -169,7 +169,7 @@ describe('#defaultValue', () => {
test('meta', () => {
const string = schema.string({ minLength: 1, maxLength: 3 });
const [meta1, meta2] = string.getSchema().describe().metas;
const [meta1, meta2] = string.getSchema().describe().metas ?? [];
expect(meta1).toEqual({
[META_FIELD_X_OAS_MIN_LENGTH]: 1,
});

View file

@ -2679,10 +2679,10 @@
"@hapi/hoek" "9.x.x"
"@hapi/validate" "1.x.x"
"@hapi/hoek@9.x.x", "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.0.4", "@hapi/hoek@^9.2.1":
version "9.2.1"
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.2.1.tgz#9551142a1980503752536b5050fd99f4a7f13b17"
integrity sha512-gfta+H8aziZsm8pZa0vj04KO6biEiisppNgA1kbJvFrrWu9Vm7eaUEy76DIxsuTaWvti5fkJVhllWc6ZTE+Mdw==
"@hapi/hoek@9.x.x", "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.0.4", "@hapi/hoek@^9.2.1", "@hapi/hoek@^9.3.0":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb"
integrity sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==
"@hapi/inert@^6.0.4":
version "6.0.4"
@ -2790,10 +2790,10 @@
resolved "https://registry.yarnpkg.com/@hapi/teamwork/-/teamwork-5.1.1.tgz#4d2ba3cac19118a36c44bf49a3a47674de52e4e4"
integrity sha512-1oPx9AE5TIv+V6Ih54RP9lTZBso3rP8j4Xhb6iSVwPXtAM+sDopl5TFMv5Paw73UnpZJ9gjcrTE1BXrWt9eQrg==
"@hapi/topo@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.0.0.tgz#c19af8577fa393a06e9c77b60995af959be721e7"
integrity sha512-tFJlT47db0kMqVm3H4nQYgn6Pwg10GTZHb1pwmSiv1K4ks6drQOtfEF5ZnPjkvC+y4/bUPHK+bc87QvLcL+WMw==
"@hapi/topo@^5.0.0", "@hapi/topo@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.1.0.tgz#dc448e332c6c6e37a4dc02fd84ba8d44b9afb012"
integrity sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==
dependencies:
"@hapi/hoek" "^9.0.0"
@ -8197,10 +8197,10 @@
agentkeepalive "^4.1.3"
lodash "^4.17.21"
"@sideway/address@^4.1.3":
version "4.1.4"
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.4.tgz#03dccebc6ea47fdc226f7d3d1ad512955d4783f0"
integrity sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw==
"@sideway/address@^4.1.5":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.5.tgz#4bc149a0076623ced99ca8208ba780d65a99b9d5"
integrity sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==
dependencies:
"@hapi/hoek" "^9.0.0"
@ -21251,14 +21251,14 @@ joi-to-json@^4.3.0:
lodash "^4.17.21"
semver-compare "^1.0.0"
joi@^17.3.0, joi@^17.7.1:
version "17.7.1"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.7.1.tgz#854fc85c7fa3cfc47c91124d30bffdbb58e06cec"
integrity sha512-teoLhIvWE298R6AeJywcjR4sX2hHjB3/xJX4qPjg+gTg+c0mzUDsziYlqPmLomq9gVsfaMcgPaGc7VxtD/9StA==
joi@^17.13.3, joi@^17.3.0:
version "17.13.3"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.13.3.tgz#0f5cc1169c999b30d344366d384b12d92558bcec"
integrity sha512-otDA4ldcIx+ZXsKHWmp0YizCweVRZG96J10b0FevjfuncLO1oX59THoAmHkNubYJ+9gWsYsp5k8v4ib6oDv1fA==
dependencies:
"@hapi/hoek" "^9.0.0"
"@hapi/topo" "^5.0.0"
"@sideway/address" "^4.1.3"
"@hapi/hoek" "^9.3.0"
"@hapi/topo" "^5.1.0"
"@sideway/address" "^4.1.5"
"@sideway/formula" "^3.0.1"
"@sideway/pinpoint" "^2.0.0"