Skip to content

Using generated union type as response returning empty json  #970

@idleway

Description

@idleway

I have request that returning in response type Event defined like:

    event:
      oneOf:
        - $ref: '#/components/schemas/eventTypeOnetimeEditableField'
        - $ref: '#/components/schemas/eventTypeRepeatableEditableField'

Generated types are:

type Event struct {
	union json.RawMessage
}
func (t Event) MarshalJSON() ([]byte, error) {
	b, err := t.union.MarshalJSON()
	return b, err
}

type PostDescribeEventById200JSONResponse Event

The problem is PostDescribeEventById200JSONResponse on json marshalling returning empty json "{}". This happens because PostDescribeEventById200JSONResponse is not using MarshalJSON() of underlying struct Event.

Using type alias instead of underlying type solving my problem:

type PostDescribeEventById200JSONResponse = Event

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions