Skip to content

Name whole-file $ref union branches like inline ones - #2642

Draft
n-hiraha wants to merge 1 commit into
oapi-codegen:mainfrom
n-hiraha:fix/whole-file-ref-union-branch
Draft

n-hiraha wants to merge 1 commit into
oapi-codegen:mainfrom
n-hiraha:fix/whole-file-ref-union-branch

Conversation

@n-hiraha

Copy link
Copy Markdown

Fixes #2639.

A oneOf/anyOf branch that $refs a whole file has a non-empty Ref but names no Go type (#308), so generateUnionElement skipped naming it and the accessors came out as AsStruct {...}(). Checking !IsGoTypeReference(element.Ref) instead names it after its path, like an inline branch. Diagnosis and fix are from @BogdanYarotsky.

Added internal/test/references/external/whole_file_union with the four forms from the issue (response body, mixed anyOf, component schema, property). It fails to generate without the fix. make generate doesn't change any existing generated code, and go test ./... passes in all three modules.

A oneOf/anyOf branch that $refs a whole file names no Go type, so
generateUnionElement must name it after its path like an inline branch,
instead of using its inline struct as the accessor name.

Fixes oapi-codegen#2639.
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.

A oneOf/anyOf branch that is a whole-file $ref generates Go that doesn't parse

1 participant