Skip to content

[COR2-1443] Stop repeating a parent's fields in each subtype it lists - #22

Closed
brucesw wants to merge 1 commit into
masterfrom
bruce/cor2-1443-dedupe-inherited-schema
Closed

brucesw wants to merge 1 commit into
masterfrom
bruce/cor2-1443-dedupe-inherited-schema

Conversation

@brucesw

@brucesw brucesw commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

TL;DR: resolve_refs inlines every $ref, and for the parent/subtype cycles springdoc emits it copies the parent's fields into every subtype, even when the subtype sits in that parent's own oneOf/anyOf, where those fields already apply. This drops the copy in that position only. Against the current Cortex API spec, createOrUpdateWorkflow's definition goes from 13,967 to 10,327 tokens (−26%) and the whole tool listing from 63,950 to 59,151 (−7.5%), and the schemas accept and reject the same inputs.

Linear: COR2-1443

Detail, written by Claude

Problem

A polymorphic type reaches the resolver as a cycle: the parent lists its subtypes in oneOf, and each subtype is allOf: [{$ref: parent}, {own fields}]. #14 cut that cycle by re-expanding the parent once, without its subtypes, inside each subtype.

That is right when a subtype is referenced on its own. Inside the parent's list it is repetition: the workflow action parent carries a 17-value type enum, so the enum appears 18 times in one tool definition, and the 12 user-input field types repeat their parent the same way.

Change

When a subtype is expanded as a direct member of a schema's oneOf/anyOf, the allOf entry that refers back to that same schema is left out. If that was the only entry, allOf goes too.

Everything else is unchanged:

  • a subtype referenced directly keeps the parent's fields;
  • a subtype listed by a property or by some other schema keeps them;
  • other allOf entries, including a second parent, are kept.

Numbers

Tokens are tiktoken o200k_base over the compact JSON of tools/list, built with this repo's route mapper and customizer.

Tool Before After
createOrUpdateWorkflow 13,967 10,327
createPlugin 1,602 1,259
updatePlugin 1,586 1,243
patchPlugin 1,576 1,233
runWorkflow 559 429
All 152 tools 63,950 59,151

No other tool's definition changes. None of the 28 tools built from the swagger.json bundled in this repo changes either, because it has no polymorphic request bodies.

Why the schemas are equivalent

The parent's own keywords still apply to the schema that holds the list, so a branch that restated them added no constraint. Two checks back that up:

  • Each of the five changed input schemas was validated (Draft 2020-12) against 4,000 random instances, valid and invalid, under the old and new schema: 20,000 instances, 3,472 valid, no disagreement.
  • An independent walk of the resolved spec found 750 removals, each one identical to the enclosing schema minus its oneOf/anyOf/discriminator.

Two limits on that claim, neither present in the spec today:

  • A subtype using unevaluatedProperties: false would start rejecting the parent's properties, since they are no longer evaluated inside the branch.
  • Where the old copy had been truncated by the cycle placeholder, old and new can differ; the new result is the more accurate one.

Not verified

  • No MCP client was tested. A branch is no longer self-contained: it relies on the properties and required beside the list, which is standard JSON Schema but worth knowing for clients that flatten anyOf.
  • Nothing was run against a live server; tests and lint ran locally (pytest 42 passed, ruff check src tests clean).

Left out

Each affected branch now has a one-entry allOf that could be merged into the branch for a further saving. That needs a key-merge rule, so it is not in this PR.

🤖 Generated with Claude Code

resolve_refs copied a polymorphic parent's fields into every subtype, even inside that parent's own oneOf/anyOf, where they already apply. Drop the copy there; a subtype reached any other way keeps it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@brucesw brucesw closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant