Skip to content

Unexported fields with anyOf in request parameters #2560

Closed

Description

@atye

This could be similar to #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: OK

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions