FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cover remaining OpenAPI 3.1 union test positions by bendrucker · Pull Request #2530 · oapi-codegen/oapi-codegen · GitHub

Cover remaining OpenAPI 3.1 union test positions - #2530

Open
bendrucker wants to merge 2 commits into
oapi-codegen:mainfrom
bendrucker:multi-type-unions-test-coverage
Open

Cover remaining OpenAPI 3.1 union test positions#2530
bendrucker wants to merge 2 commits into
oapi-codegen:mainfrom
bendrucker:multi-type-unions-test-coverage

Conversation

bendrucker commented Aug 19, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Adds conformance tests for the multi-type union positions the #2522 review found missing.

A union in array-items position lowers to a []any alias and round-trips mixed member values. A union as a oneOf branch keeps the outer schema's union machinery with an any-typed accessor, so As... never fails and branch discrimination falls to the caller. A union-typed response header exercises the Types list that ClientWithResponses passes when binding declared headers, which had no test. The allOf position is skipped because #2526 already covers both member orderings.

Test-only. Repo-wide make generate changes nothing outside the two openapi31 suites.

The review of oapi-codegen#2522 asked for the untested union positions to be
committed. Three surfaces had no conformance coverage:

- array items: a named array component whose items are a union lowers to
  a []any alias and round-trips mixed member values
- a union as a oneOf branch: the outer schema keeps the standard union
  machinery with the branch accessor typed any, whose As... conversion
  can never fail, so branch discrimination falls to the caller
- response headers: ResponseHeaderDefinition.SchemaTypes() feeds the
  Types list the generated ClientWithResponses passes when binding
  declared response headers, previously exercised by no test

The allOf position is already pinned by the spec added in oapi-codegen#2526 (both
member orderings), so it is deliberately not duplicated here.
bendrucker requested a review from a team as a code owner August 19, 2026 02:38

greptile-apps Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR expands OpenAPI 3.1 multi-type union conformance coverage without changing generator implementation.

  • Adds array-item and oneOf-branch union fixtures and generated models.
  • Verifies union-typed response headers preserve member-order parsing through ClientWithResponses.
  • Documents the intentionally permissive behavior of an any-typed oneOf branch.

Confidence Score: 5/5

The test-only PR appears safe to merge, with no concrete correctness or generated-API failures identified.

The added specifications, generated fixtures, and tests consistently exercise the intended OpenAPI 3.1 union behavior, and the generated diffs contain no unrelated API drift.

Important Files Changed

Filename Overview
internal/test/openapi31/spec.yaml Adds representative array-item and oneOf-branch multi-type union schemas consistent with the generated fixtures.
internal/test/openapi31/openapi31_test.go Tests the intended []any lowering and explicitly pins the permissive oneOf branch-accessor behavior.
internal/test/openapi31/openapi31.gen.go Generated output contains the expected array alias and standard oneOf union machinery without unrelated drift.
internal/test/openapi31params/spec.yaml Declares an integer-or-string response header on the existing HTTP 200 response.
internal/test/openapi31params/openapi31params_test.go Exercises generated response-header parsing for both integer and string members through the real client/server path.
internal/test/openapi31params/openapi31params.gen.go Generated response parsing correctly passes the ordered schema types to the runtime styled-parameter binder.

Reviews (1): Last reviewed commit: "Cover remaining OpenAPI 3.1 union positi..." | Re-trigger Greptile

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL