Improve unknown-key validation error message in @kbn/config-schema#258633
Conversation
The `object.unknown` error from `@kbn/config-schema` previously returned
"definition for this key is missing", which is not actionable. This
changes it to "Additional properties are not allowed ('<key>' was
unexpected)", following OpenAPI-style messaging and including the
unexpected property name. This helps API consumers (e.g. Dashboards-as-
Code workflows) quickly identify which field to remove from their
request payloads.
Made-with: Cursor
|
Pinging @elastic/kibana-core (Team:Core) |
1 similar comment
|
Pinging @elastic/kibana-core (Team:Core) |
💚 Build Succeeded
Metrics [docs]Async chunks
|
rylnd
left a comment
There was a problem hiding this comment.
Detection engine (test) change LGTM! 👍
| } | ||
|
|
||
| protected handleError(type: string, { reason, value }: Record<string, any>) { | ||
| protected handleError(type: string, { reason, value, child }: Record<string, any>) { |
There was a problem hiding this comment.
can we please ensure the OAS generation isn't effected by this change.
I don't see how it could, but better to confirm than be surprised later.
There was a problem hiding this comment.
Looked into this, the OAS generation uses schema conversion (kbn-router-to-openapispec) and does not call handleError; this only affects runtime validation errors.
Additionally I had cursor run the OAS generation script locally for both serverless and traditional (via node scripts/capture_oas_snapshot ... with the same include path list CI uses) and it succeeded.
jeramysoucy
left a comment
There was a problem hiding this comment.
Kibana security changes LGTM
…ra/kibana into dashboard_align_attachment_to_api * 'dashboard_align_attachment_to_api' of github.com:mbondyra/kibana: (45 commits) [OTel Tracing] HTTP instrumentation (elastic#258663) Replace deprecated EUI icons in files owned by @elastic/ml-ui (elastic#255624) [Codeowners] add missing codeowners for security_solution_api_integration tests (elastic#259223) [CI] fix bad imports that came from a merge-race (elastic#259383) Add `.claude/worktrees/` to `.gitignore` (elastic#259192) Improve unknown-key validation error message in @kbn/config-schema (elastic#258633) [ML] Update Security ML jobs to use entity analytics fields for host and user fields (elastic#255339) [Table sweep] Update table columns responsiveness in Index Management and Dashboards (elastic#259340) skip failing test suite (elastic#258790) skip failing test suite (elastic#259261) chore: util to clean cached images (elastic#259335) [Entity Store] Use last_seen for automated resolution watermark (elastic#258574) [One Workflow] Fix flaky alert trigger Scout test by removing order-dependent assertions (elastic#259299) Skip serverless Discover request counts tests for MKI (elastic#259333) [Security Solution] render header title in new document flyout in Security Solution and Discover (elastic#258166) [Agent Builder] register inference endpoint feature (elastic#259259) [Agent Builder] Skills Command Menu - Add descriptions and scope options to agent (elastic#258964) [Streams][Streamlang][API] Fully use meta({id}) to reuse schema partials in OAS output (elastic#259275) fix(files_example): add tableCaption to EuiInMemoryTable for a11y (elastic#258289) [Entity Store] Adding list endpoint with query filter (elastic#258320) ...
…lastic#258633) resolves [issue](elastic#249196) ## Summary Improves the `@kbn/config-schema` `object.unknown` validation error message from the unclear `"definition for this key is missing"` to a more actionable `"Additional properties are not allowed ('<key>' was unexpected)"`, following OpenAPI-style messaging. ### Problem - When `schema.object()` with `unknowns: 'forbid'` (the default) encounters an unexpected property, the error `"definition for this key is missing"` is technically correct but not actionable. - It does not tell callers that the failure is due to additional properties being disallowed, nor does it name the offending key in the message body. - This is especially confusing in API workflows (e.g. Dashboards-as-Code) where users copy GET response payloads into POST/PUT requests and receive cryptic validation errors for response-only fields like `meta`. ### Solution - Updated `handleError` in `ObjectType` to return `"Additional properties are not allowed ('<key>' was unexpected)"` for the `object.unknown` Joi error code, using Joi's `child` context to include the unexpected property name. - Updated 46 test files across the repository that asserted the old error string to match the new message format. - All 893 affected Jest tests pass. `node scripts/check_changes.ts` passes (lint + formatting). Made with [Cursor](https://cursor.com)
resolves issue
Summary
Improves the
@kbn/config-schemaobject.unknownvalidation error message from the unclear"definition for this key is missing"to a more actionable"Additional properties are not allowed ('<key>' was unexpected)", following OpenAPI-style messaging.Problem
schema.object()withunknowns: 'forbid'(the default) encounters an unexpected property, the error"definition for this key is missing"is technically correct but not actionable.meta.Solution
handleErrorinObjectTypeto return"Additional properties are not allowed ('<key>' was unexpected)"for theobject.unknownJoi error code, using Joi'schildcontext to include the unexpected property name.node scripts/check_changes.tspasses (lint + formatting).Made with Cursor