Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generation issue for OneOf fields #258

Open
TheSadlig opened this issue Sep 19, 2024 · 0 comments
Open

Generation issue for OneOf fields #258

TheSadlig opened this issue Sep 19, 2024 · 0 comments

Comments

@TheSadlig
Copy link
Contributor

TheSadlig commented Sep 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant