Skip to content

Keep referenced body fields when a request body schema adds sibling properties - #5440

Merged
jlowin merged 5 commits into
mainfrom
fix/openapi-body-ref-siblings
Oct 4, 2026
Merged

jlowin merged 5 commits into
mainfrom
fix/openapi-body-ref-siblings

Conversation

@jlowin

@jlowin jlowin commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

A request body schema written as a $ref with sibling properties (valid in OpenAPI 3.1) now exposes the referenced schema's properties and required fields together with the sibling properties, and sends all of them in the request body. When both define the same property name, the two schemas are combined with allOf. The merge applies only when the referenced schema is a plain object it can represent fully (including a discriminator with its mapped subtypes); any other target keeps the $ref and is exposed as a single body argument. Bodies that are a plain $ref are unchanged.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T15:57:17.314239Z 0af5694 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. openapi Related to OpenAPI integration, parsing, or code generation features. labels Oct 4, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1220d5e4e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +430 to +432
has_ref_with_properties = "$ref" in body_schema and isinstance(
body_schema.get("properties"), dict
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Convert references inside sibling properties

When a sibling property itself references another component, _replace_ref_with_defs() converts the top-level $ref and skips traversing its sibling properties; this new branch then promotes that untouched #/components/schemas/Child pointer while the emitted schema contains definitions only under $defs. The default dereference middleware cannot resolve that pointer and returns the schema unchanged, so OpenAPI 3.1 tools using nested sibling references advertise a dangling input-schema reference. Normalize the sibling property schemas before removing the top-level $ref.

AGENTS.md reference: AGENTS.md:L184-L186

Useful? React with 👍 / 👎.

Comment on lines +426 to +428
# Handle allOf at the top level by merging all schemas. A $ref that
# sits beside its own properties is merged the same way, with the
# sibling properties taking precedence over the referenced ones.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve conjunction for overlapping referenced properties

In OpenAPI 3.1, keywords adjacent to $ref apply in addition to the referenced schema; they do not override it. For example, a referenced name: string plus sibling name: integer is unsatisfiable, but this merge advertises name as an integer and sends a value the upstream schema must reject. Preserve both constraints, such as by composing colliding property schemas, rather than assigning precedence to the sibling.

AGENTS.md reference: AGENTS.md:L180-L182

Useful? React with 👍 / 👎.

…to overlapping fields

Co-authored-by: Claude <noreply@anthropic.com>
@jlowin

jlowin commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 97f6dc7294

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Remove the allOf since we've merged it
# Remove the allOf and $ref since we've merged them
body_schema.pop("allOf", None)
body_schema.pop("$ref", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve discriminators from referenced body schemas

When an OpenAPI 3.1 request body adds sibling properties to a $ref whose target carries a discriminator, this merge copies only the target's properties and required fields before removing the reference. Consequently, _flatten_discriminator_subtypes() never sees the referenced discriminator, so mapped subtype fields such as meowVolume disappear from the MCP tool schema and cannot be forwarded by the request director. Carry the referenced discriminator into body_schema, or flatten the resolved target before dropping the reference.

AGENTS.md reference: AGENTS.md:L184-L186

Useful? React with 👍 / 👎.

@jlowin

jlowin commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66f9358b31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Remove the allOf since we've merged it
# Remove the allOf and $ref since we've merged them
body_schema.pop("allOf", None)
body_schema.pop("$ref", None)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep $ref when allOf was not fully merged

When an OpenAPI 3.1 request body contains both a top-level $ref and allOf, and the referenced schema has no object properties—for example, a referenced string refined with minLength—has_all_of enters this block, but the merger copies only properties and required. Removing both $ref and allOf then leaves the whole-body argument without the referenced type or constraints, whereas the previous code retained the $ref; only discard the reference after the complete referenced schema has been preserved.

AGENTS.md reference: AGENTS.md:L184-L186

Useful? React with 👍 / 👎.

@jlowin

jlowin commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 380df5e1da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +273 to +275
and schema.get("type", "object") == "object"
and "enum" not in schema
and "const" not in schema

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve composed constraints before dropping the reference

Although the earlier primitive/allOf case is now guarded, this helper still classifies a referenced type: object containing oneOf or anyOf as losslessly mergeable. For a body such as $ref: Base plus sibling properties, where Base requires variant-specific fields through oneOf, the merge copies only top-level properties/required and then removes the reference; the variant fields are absent from both the tool schema and parameter map, so no conforming payload can be forwarded. Treat unmerged composition keywords as non-mergeable or preserve/flatten their complete constraints before removing $ref.

AGENTS.md reference: AGENTS.md:L184-L186

Useful? React with 👍 / 👎.

@jlowin

jlowin commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0af5694cb5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

merged_props.update(sub_schema["properties"])
for prop_name, prop_schema in sub_schema.get("properties", {}).items():
if (
not has_all_of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve overlap conjunction when allOf is present

When a $ref body also has any top-level allOf, this condition disables composition for every overlapping property, including overlaps between the referenced schema and sibling properties. For example, a referenced name: string plus sibling name: integer and an annotation-only allOf: [{"description": "..."}] emits only the integer schema instead of the unsatisfiable conjunction, so the tool accepts a request the upstream schema rejects. Fresh evidence in this revision is the new not has_all_of guard, which bypasses the earlier overlap fix whenever this otherwise unrelated keyword is present; compose differing property schemas regardless of whether the body also contains allOf.

AGENTS.md reference: AGENTS.md:L180-L182

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining this one. It needs a body that combines a top-level $ref, sibling properties that contradict the referenced schema, and an allOf on the same object. The allOf path keeps its existing last-wins property merging, which an existing test documents. Overlaps between the referenced schema and sibling properties are composed whenever no allOf is present, which covers the realistic case.

@jlowin
jlowin merged commit 0ac49de into main Oct 4, 2026
28 of 30 checks passed
@jlowin
jlowin deleted the fix/openapi-body-ref-siblings branch October 4, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. openapi Related to OpenAPI integration, parsing, or code generation features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants