Unexported fields with anyOf in request parameters
Author: atyeCreated Sep 18, 2026Updated Sep 18, 2026
This could be similar to https://github.com/oapi-codegen/oapi-codegen/issues/1367 which has an associated and merged PR, but I am seeing this.
With this spec:
openapi: 3.1.0
info:
title: Reproduction Spec
version: 1.0.0
paths:
/test/{accept}:
post:
operationId: BugReproduction
parameters:
- name: accept
in: path
required: true
schema:
anyOf:
- type: boolean
- type: string
responses:
"200":
description: OKThe generated code has:
// BugReproductionParamsAccept0 defines parameters for BugReproduction.
type BugReproductionParamsAccept0 = bool
// BugReproductionParamsAccept1 defines parameters for BugReproduction.
type BugReproductionParamsAccept1 = string
// The interface specification for the client above.
type ClientInterface interface {
// BugReproduction performs a POST /test/{accept} (the `BugReproduction` operationId) request.
BugReproduction(ctx context.Context, accept struct {
union json.RawMessage
}, reqEditors ...RequestEditorFn) (*http.Response, error)
}
// BugReproduction performs a POST /test/{accept} (the `BugReproduction` operationId) request.
func (c *Client) BugReproduction(ctx context.Context, accept struct {
union json.RawMessage
}, reqEditors ...RequestEditorFn,
) (*http.Response, error) {
req, err := NewBugReproductionRequest(c.Server, accept)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}Types BugReproductionParamsAccept0 and BugReproductionParamsAccept1 are defined but not used. BugReproduction has a second argument that is an anonymous struct with an unexported field. If the generated code is in its own package, and thus being imported elsewhere which I would think is a common use case, there is no way to construct it.
Source: oapi-codegen/oapi-codegen