Collapse redundant anyOf/oneOf array unions in OAS query params#260585
Collapse redundant anyOf/oneOf array unions in OAS query params#260585TinaHeiligers merged 4 commits intoelastic:mainfrom
Conversation
|
/ci |
|
Pinging @elastic/kibana-core (Team:Core) |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
jloleysens
left a comment
There was a problem hiding this comment.
Nice work @TinaHeiligers !
📝 WalkthroughWalkthroughThis change introduces schema simplification for OpenAPI query parameters. A new ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/collapse_array_union.ts (1)
36-45: Minor edge case:$refin array items bypasses type validation.When
arrayBranch.itemsis a$ref, the type-match check is skipped and collapsing proceeds. If this pattern occurs, the collapsed schema might misrepresent the original union. Likely not an issue given the documented query-param patterns, but worth noting if the helper is reused elsewhere.Optional: bail out when items is a ref
if (arrayBranch.items && !isRef(arrayBranch.items)) { const items = arrayBranch.items as Record<string, unknown>; if (items.type !== scalarBranch.type) return schema; + } else if (arrayBranch.items && isRef(arrayBranch.items)) { + return schema; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/collapse_array_union.ts` around lines 36 - 45, The collapse currently skips type validation when arrayBranch.items is a $ref, which can produce an incorrect collapsed schema; update the logic in collapse_array_union (around arrayBranch/items handling) to explicitly bail out when isRef(arrayBranch.items) is true (i.e., return the original schema) instead of continuing the collapse, so arrays with $ref items are not merged with scalarBranch; ensure you check isRef(arrayBranch.items) before creating/inferencing items and before comparing items.type with scalarBranch.type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@src/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/collapse_array_union.ts`:
- Around line 36-45: The collapse currently skips type validation when
arrayBranch.items is a $ref, which can produce an incorrect collapsed schema;
update the logic in collapse_array_union (around arrayBranch/items handling) to
explicitly bail out when isRef(arrayBranch.items) is true (i.e., return the
original schema) instead of continuing the collapse, so arrays with $ref items
are not merged with scalarBranch; ensure you check isRef(arrayBranch.items)
before creating/inferencing items and before comparing items.type with
scalarBranch.type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 891d00a9-079e-4fc5-b4c6-42501964e394
📒 Files selected for processing (9)
oas_docs/output/kibana.serverless.yamloas_docs/output/kibana.yamlsrc/platform/packages/shared/kbn-router-to-openapispec/README.mdsrc/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/collapse_array_union.test.tssrc/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/collapse_array_union.tssrc/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/kbn_config_schema/lib.test.tssrc/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/kbn_config_schema/lib.tssrc/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/zod/lib.test.tssrc/platform/packages/shared/kbn-router-to-openapispec/src/oas_converter/zod/lib.ts
…heck * commit '6f040b29a5220ce12886a9731f656613e50aff06': (34 commits) [Entity Analytics] Add entity resolution UI to service flyout (elastic#260504) [Dashboard] Fix setState in embeddables (elastic#260082) [EDR Workflows] Unskip FTR tests that failed due to transient Fleet service unavailability (elastic#260519) [Observability:Streams] Fix query streams error handling test (elastic#260777) [Alerting v2] Dispatcher grouping modes, throttle strategies, and matcher autosuggestion (elastic#260249) [Dashboard] State extraction as a consistent override (elastic#259839) [Alerting v2] [Rule authoring] Fix rule name validation and error visibility in create/edit flow (elastic#260337) [Fix] re-introduce sln breadcrumbs to unified rules (elastic#260289) [Security Solution][Endpoint] Updated kibana docs to include `xpack.securitySolution.maxEndpointScriptFileSize` as configurable in cloud (elastic#260568) [Alerting v2] updated the alerting-v2-constants package with artifacts constants, fix to the runbook max characters (elastic#260342) [Automatic Import V2] Provide user tooltips (elastic#260725) [One Workflow] Deduplicate step types by base type in workflow list (elastic#260763) [Security Solution] Execution results UI: Enable the feature flag (elastic#260711) [Metrics][Discover] internal/search/esql_async returns 200 but METRICS_INFO responds with error (elastic#260746) Collapse redundant anyOf/oneOf array unions in OAS query params (elastic#260585) [Unified rules] Hide stack rules from global search (elastic#260088) [Agent Builder] Sidebar navigation updates (elastic#260728) [* As Code] Use PUT for upserts (elastic#260318) Update EUI to v114.0.0 (elastic#259497) [Entity Resolution] Add contextual-security-apps as co-owner of resolution paths (elastic#260659) ... # Conflicts: # src/platform/plugins/shared/dashboard/public/index.ts
…tic#260585) Collapses redundant `anyOf`/`oneOf` unions on query parameters in the OAS output. Co-Authored-By: Claude Opus 4.6
…tic#260585) Collapses redundant `anyOf`/`oneOf` unions on query parameters in the OAS output. Co-Authored-By: Claude Opus 4.6
Summary
Collapses redundant
anyOf/oneOfunions on query parameters in the OAS output.Parameters defined as
schema.oneOf([string, arrayOf(string)])orz.union([string, z.array(string)])now produce{type: 'array', items: {type: 'string'}}instead of a two-branch union wrapper.OAS 3.0 query params with
style: formalready handle single-or-multiple values natively, so the union was redundant.Relates to #228077
Details
collapseArrayUnion()post-processor inkbn-router-to-openapispec, applied inconvertObjectMembersToParameterObjects()for both kbn-config-schema and zod pathsmaxItems,enum,nullable, anddescriptionmaintenance_window/_find,streams/{streamName}/attachments,synthetics/monitors,workflows/.../executions, 3 fleet params)include_authorized_purposeson Spaces is excluded — different pattern (5-branch degenerateanyOf)I ran the elasticstack-terraform-provider codegen pipeline (transform → codegen → compile) against this branch's OAS output. Once this PR merges and Renovate bumps the schema in the TF provider, these 4 transforms in
transform_schema.gocan be removed:fixGetSyntheticsMonitorsParams—x-go-typeannotation onuseLogicalAndForfixGetMaintenanceWindowFindParams—x-go-typeannotation onstatusfixGetStreamsAttachmentTypesParams—x-go-typeannotation onattachmentTypesfixGetWorkflowsExecutionsParams—x-go-typeannotations onstatusesandexecutionTypesHow to test this
Run the package tests:
All 220 tests should pass, including the 17 new ones (13 unit tests for
collapseArrayUnion, 2 kbn-config-schema integration tests, 2 zod integration tests).Verify OAS snapshot changes by inspecting the diff on
oas_docs/output/kibana.yaml. Every change should be ananyOf/oneOfwrapper replaced by a plain array schema. No other params should be affected. Spot-check a few, for example:maintenance_window/_findstatusparambefore:
anyOf: [enum string, array[enum]]after:
{type: array, items: {type: string, enum: [...]}}streams/{streamName}/attachmentstagsparambefore
anyOf: [string, array[string]]after
{type: array, items: {type: string}}workflows/.../executionsstatusesparambefore:
anyOf: [enum string, array[enum] + maxItems:9]after:
{type: array, items: ..., maxItems: 9}Checklist
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesIdentify risks
This is a low-risk change scoped to OAS output only — no runtime behavior changes, no API contract changes, no data model changes.
Co-Authored-By: Claude Opus 4.6