Skip to content

requestBody with oneOf does not generate marshal/unmarshal union data #1620

@l0n3star

Description

@l0n3star

Minimal yaml:

openapi: 3.0.2
info:
  title: test API
servers:
  - url: 'https://api.server.com'
paths:
  '/command':
    get:
      summary: command summary
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/CommandRequest1'
                - $ref: '#/components/schemas/CommandRequest2'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CommandResponse'

components:
  schemas:
    CommandRequest1:
      type: object
      required:
        - id
      properties:
        id:
          type: string
    CommandRequest2:
      type: object
      required:
        - groupID
      properties:
        groupID:
          type: string
    CommandResponse:
      type: object
      required:
        - command
      properties:
        command:
          type: string

This is the generated go code:

package oapi

import (
	"encoding/json"
)

// CommandRequest1 defines model for CommandRequest1.
type CommandRequest1 struct {
	Id string `json:"id"`
}

// CommandRequest2 defines model for CommandRequest2.
type CommandRequest2 struct {
	GroupID string `json:"groupID"`
}

// CommandResponse defines model for CommandResponse.
type CommandResponse struct {
	Command string `json:"command"`
}

// GetCommandJSONBody defines parameters for GetCommand.
type GetCommandJSONBody struct {
	union json.RawMessage
}

// GetCommandJSONRequestBody defines body for GetCommand for application/json ContentType.
type GetCommandJSONRequestBody GetCommandJSONBody

There is GetCommandJSONBody struct with union data but no functions to use it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions