Skip to content

Fix ParseSchemaV3 to handle allOf-wrapped $ref#584

Open
bryantbiggs wants to merge 1 commit intokubernetes:masterfrom
bryantbiggs:fix-v3-allof-ref-parsing
Open

Fix ParseSchemaV3 to handle allOf-wrapped $ref#584
bryantbiggs wants to merge 1 commit intokubernetes:masterfrom
bryantbiggs:fix-v3-allof-ref-parsing

Conversation

@bryantbiggs
Copy link
Copy Markdown
Contributor

Summary

  • Fix ParseSchemaV3 in document_v3.go to handle the allOf-wrapped $ref pattern
  • When a schema has no type but a single-element allOf containing a $ref, resolve it as a reference instead of falling through to Arbitrary

Context

In OpenAPI 3.0, sibling properties alongside $ref must be ignored per the spec. The compliant way to combine $ref with description/default is to wrap the $ref in a single-element allOf:

"metadata": {
  "allOf": [{"$ref": "#/components/schemas/ObjectMeta"}],
  "description": "Standard object's metadata.",
  "default": {}
}

kube-openapi's own builder (builder3/util.WrapRefs) produces this format, and Kubernetes >= 1.35 serves v3 specs using it. However, ParseSchemaV3 had zero handling for allOf — these schemas fell through to the default case and were returned as Arbitrary, losing the reference.

This matches the pattern already used in pkg/schemaconv/openapi.go:130-133.

Fixes #477
Unblocks #583

Test plan

  • New test TestV3AllOfRef — verifies both direct $ref and allOf-wrapped $ref resolve as proto.Reference
  • All 54 existing + new tests pass
  • go vet clean
  • CI verification

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 17, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bryantbiggs
Once this PR has been reviewed and has the lgtm label, please assign apelisse for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 17, 2026
Comment thread pkg/util/proto/document_v3.go Outdated
@Jefftree
Copy link
Copy Markdown
Member

Please fix the commit message. assuming it has to do with symbols being used.

When a schema has no type but a single-element allOf containing a
ref, resolve it as a reference instead of falling through to Arbitrary.
Build the Ref from the outer schema so sibling fields like description,
default, and extensions are preserved.
@bryantbiggs bryantbiggs force-pushed the fix-v3-allof-ref-parsing branch from 4dc8abd to bafd5e9 Compare March 18, 2026 20:27
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI V3 references parsed as *proto.Arbitrary instead of *proto.Ref

3 participants