lerenn/asyncapi-codegen

Generation issue for OneOf fields

Opened this issue · 0 comments

Allo !

I noticed a generation issue affecting OneOf fields:

When generating this:

components:
  messages:
    Test:
      description: test message
      payload:
        oneOf:
          - $ref: '#/components/schemas/Something'
          - $ref: '#/components/schemas/SomethingElse'
  schemas:
    Something:
      type: object
      required:
        - str1
        - str2
      properties:
        str1:
          type: string
        str2:
          type: string

    SomethingElse:
      type: object
      properties:
        str3:
          type: integer

Generates:

// TestMessagePayload is a schema from the AsyncAPI specification required in messages
type TestMessagePayload struct {
	Str1 string `json:"str1" validate:"required"`
	Str2 string `json:"str2" validate:"required"`
	Str3 *int64 `json:"str3,omitempty"`
}

// TestMessage is the message expected for 'TestMessage' channel.
// NOTE: test message
type TestMessage struct {
	// Payload will be inserted in the message payload
	Payload TestMessagePayload
}

Expected:

// TestMessagePayloadOneOf is a schema from the AsyncAPI specification required in messages
type TestMessagePayloadOneOf struct {
	SomethingPayload
	SomethingElsePayload
}

type SomethingPayload struct {
	Str1 string `json:"str1" validate:"required"`
	Str2 string `json:"str2" validate:"required"`
}

type SomethingElsePayload struct {
	Str3 *int64 `json:"str3,omitempty"`
}

// TestMessage is the message expected for 'TestMessage' channel.
// NOTE: test message
type TestMessage struct {
	// Payload will be inserted in the message payload
	Payload TestMessagePayload
}

It seems like we are skipping one object during the generation of oneof messages.
Thanks