Skip to content

Multiple json content types in a single requestBody or response lead to duplicate types and client interface functions #1127

Description

@jlengelsen
openapi: 3.0.1
info:
  title: api
  version: "0.1.0"
paths:
  /whatever:
    post:
      operationId: CreateWhatever
      requestBody:
        content:
          application/json-patch+json:
            schema:
              $ref: "#/components/schemas/Whatever"
          application/json:
            schema:
              $ref: "#/components/schemas/Whatever"
          text/json:
            schema:
              $ref: "#/components/schemas/Whatever"
          application/*+json:
            schema:
              $ref: "#/components/schemas/Whatever"
      responses:
        201:
          description: Whatever created
          content:
            text/plain:
              schema:
                $ref: "#/components/schemas/Whatever"
            application/json:
              schema:
                $ref: "#/components/schemas/Whatever"
            text/json:
              schema:
                $ref: "#/components/schemas/Whatever"
components:
  schemas:
    Whatever:
      type: object
      properties:
        someProperty:
          type: string

Generated Client Boilerplate:

// CreateWhateverJSONRequestBody defines body for CreateWhatever for application/*+json ContentType.
type CreateWhateverJSONRequestBody = Whatever

// CreateWhateverJSONRequestBody defines body for CreateWhatever for application/json ContentType.
type CreateWhateverJSONRequestBody = Whatever

// CreateWhateverJSONRequestBody defines body for CreateWhatever for application/json-patch+json ContentType.
type CreateWhateverJSONRequestBody = Whatever

...

// The interface specification for the client above.
type ClientInterface interface {
	// CreateWhatever request with any body
	CreateWhateverWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	CreateWhatever(ctx context.Context, body CreateWhateverJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	CreateWhatever(ctx context.Context, body CreateWhateverJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	CreateWhatever(ctx context.Context, body CreateWhateverJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

...

// ClientWithResponsesInterface is the interface specification for the client with responses above.
type ClientWithResponsesInterface interface {
	// CreateWhatever request with any body
	CreateWhateverWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateWhateverResponse, error)

	CreateWhateverWithResponse(ctx context.Context, body CreateWhateverJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateWhateverResponse, error)

	CreateWhateverWithResponse(ctx context.Context, body CreateWhateverJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateWhateverResponse, error)

	CreateWhateverWithResponse(ctx context.Context, body CreateWhateverJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateWhateverResponse, error)
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions