X Tutup
Skip to content

Issue with RequestBody types in generated code #43

@rewtraw

Description

@rewtraw

Currently experiencing an issue where the {operation}JSONRequestBody types are not being used within the generated client methods.

e.g.

// spec.yaml

paths:
  /:
    post:
      operationId: create
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/Data'

The generated API has the following types

// api.gen.go

type Data struct {
   ...
}

type createJSONBody []Data

type CreateJSONRequestBody createJSONBody

But, the client methods mistakenly use the createJSONBody type when they should use the CreateJSONRequestBody type.

The following is generated, and causes the client to error with cannot refer to unexported name api.createJSONBody

// api.gen.go

Create(ctx context.Context, body createJSONBody) (*http.Response, error)

...

func (c *Client) Create(ctx context.Context, body createJSONBody) (*createResponse, error) {
   ...
}

In my testing, manually changing this to CreateJSONRequestBody resolves the issue

// api.gen.go

type ClientInterface interface {
   Create(ctx context.Context, body CreateJSONRequestBody) (*http.Response, error)
}

...

func (c *Client) Create(ctx context.Context, body CreateJSONRequestBody) (*createResponse, error) {
   ...
}

This affects both the Client and ClientWithResponses methods.

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

      X Tutup