[Fleet] Restore dropped OpenAPI fields by giving extends() schemas distinct meta.id#271812
Open
tobio wants to merge 1 commit into
Open
[Fleet] Restore dropped OpenAPI fields by giving extends() schemas distinct meta.id#271812tobio wants to merge 1 commit into
tobio wants to merge 1 commit into
Conversation
…stinct meta.id (elastic#271809) `ObjectType.extends()` inherits `meta.id` from the base when the caller does not pass a fresh one. The OAS generator's shared schemas registry is keyed by id and is last-write-wins across routes, so two distinct shapes sharing an id silently overwrite one another in the bundled spec. Two Fleet schemas hit this: - `DeletePackagePoliciesResponseBodySchema` extends `PackagePolicyStatusResponseSchema` without an own id; `UpgradePackagePoliciesResponseBodySchema` references the bare base under the same id and overwrote the extension's keys. - `CreateAgentlessPolicyRequestSchema.body` extends `SimplifiedCreatePackagePolicyRequestBodySchema` without an own id; the agentless body strips four fields, and that stripped shape was being emitted under the simplified-create component name. Give each extension a distinct `meta.id` so the components stop colliding, refresh the bundled spec, and add regression tests in `generate_oas.test.ts` documenting the collision behaviour and the workaround. Closes elastic#271809 Co-authored-by: Cursor <cursoragent@cursor.com>
4 tasks
Contributor
💚 Build Succeeded
Metrics [docs]
|
juliaElastic
approved these changes
Jun 1, 2026
|
Pinging @elastic/fleet (Team:Fleet) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #271809.
PR #270560 added
meta: { id }annotations to a number of Fleet@kbn/config-schemadefinitions so they would be extracted as named OpenAPI components. Three of the resulting components silently dropped fields that the same operations had exposed pre-PR (and which the route handlers still read):simplified_create_package_policy_requestPOST /api/fleet/package_policies(simplified branch),PUT /api/fleet/package_policies/{packagePolicyId}output_id,policy_id,policy_ids,supports_agentlesspackage_policy_status_responsePOST /api/fleet/package_policies/delete(response item)output_id,policy_id,policy_ids,packageupdate_package_policy_requestPUT /api/fleet/package_policies/{packagePolicyId}id(via the simplified branch in the request body'soneOf)Root cause
ObjectType.extends()merges options as{ ...this.options, ...newOptions }, so the extended schema inherits the base'smeta.idwhen the caller does not pass a fresh one. The OAS generator's shared-schemas registry (OasConverter.#sharedSchemas) is keyed by id and is last-write-wins across all routes in a single generation pass, so two distinct shapes sharing the same id overwrite each other in the bundled spec.Two places in Fleet hit this:
DeletePackagePoliciesResponseBodySchemaextendsPackagePolicyStatusResponseSchemawith no ownmeta.id.UpgradePackagePoliciesResponseBodySchemareferences the bare base under the same id and overwrote the extension's keys.CreateAgentlessPolicyRequestSchema.bodyextendsSimplifiedCreatePackagePolicyRequestBodySchemawith no ownmeta.id. The agentless body strips four fields (policy_id,policy_ids,supports_agentless,output_id), and that stripped shape was being emitted under thesimplified_create_package_policy_requestcomponent name.The third item (
update_package_policy_requestlosingid) is a downstream effect of the second: theidfield always lived onSimplifiedPackagePolicyBaseSchemaand was published via the simplified branch of the PUT body'soneOf. Fixing the agentless extension restores it automatically — no TS changes to the update body are needed (and the TS schema didn't actually regress: pre-PR,UpdatePackagePolicyRequestBodySchemalikewise didn't declareid).Changes
x-pack/platform/plugins/shared/fleet/server/types/rest_spec/package_policy.ts— giveDeletePackagePoliciesResponseBodySchema's extensionmeta: { id: 'delete_package_policies_response_item' }.x-pack/platform/plugins/shared/fleet/common/types/rest_spec/agentless_policy.ts— giveCreateAgentlessPolicyRequestSchema.body's extensionmeta: { id: 'create_agentless_policy_request' }.src/platform/packages/shared/kbn-router-to-openapispec/src/generate_oas.test.ts— add two regression tests underextends() without a fresh meta.id (issue #271809)that document the collision and verify the workaround.oas_docs/output/kibana.yaml/kibana.serverless.yaml— refresh the bundled spec.Both new components (
delete_package_policies_response_item,create_agentless_policy_request) are referenced from their respective operations; the previously colliding components (simplified_create_package_policy_request,package_policy_status_response) now correctly describe their own routes.This is the short-term Fleet-side fix from the investigation. A follow-up to add collision detection in
kbn-router-to-openapispec(so the build fails loudly on future occurrences instead of silently overwriting) and/or to change@kbn/config-schemasoextends()no longer inheritsmeta.idis tracked separately in #271809.Verification
Reproducing the issue's diff commands against the rebundled
oas_docs/output/kibana.yaml:Test plan
node scripts/jest src/platform/packages/shared/kbn-router-to-openapispec/src/generate_oas.test.ts— all 20 tests pass, including 2 new regression testsnode scripts/type_check --project src/platform/packages/shared/kbn-router-to-openapispec/tsconfig.jsonnode scripts/type_check --project x-pack/platform/plugins/shared/fleet/tsconfig.jsonnode scripts/eslinton all modified filesnode scripts/capture_oas_snapshot --include-path /api/fleet ...+cd oas_docs && make api-docs— bundled spec verified to contain restored fieldsRisks
Low. The change only adds
meta: { id: ... }arguments; runtime validation behaviour is unchanged. Two new component names appear in the OAS but no existing component name's shape changes adversely (and several have their lost fields restored). Downstream OpenAPI-driven clients (e.g. the Terraform provider for Elastic Stack) need to regenerate from the new spec, but this restores the previously published contract — they have been blocked since the offending PR landed.Release Notes
Restored the
output_id,policy_id,policy_ids,supports_agentless, andpackagefields on the affected Fleet OpenAPI components. The bulk-delete response and the simplified create/update package policy bodies are now documented correctly again.Made with Cursor