Skip to content

Support for enums #22

@patrickuhlmann

Description

@patrickuhlmann

Reason/Context

In the specification it is possible to define enums. These should map to a Java Enum.

Example:

          status:
            type: string
            enum:
              - RELEASED
              - NOT_RELEASED

Description

I prepared a small example based on your kafka example.

kafka-example.yml:

asyncapi: 2.3.0
info:
  title: Record Label Service
  version: 1.0.0
  description: This service is in charge of processing music
servers:
  production:
    url: 'my-kafka-hostname:9092'
    protocol: kafka-secure
    description: Production Instance 1
    security:
      - myScram: []
channels:
  song.released:
    publish:
      message:
        $ref: '#/components/messages/song'
    subscribe:
      message:
        $ref: '#/components/messages/song'
components:
  securitySchemes:
    myScram:
      type: scramSha512
  messages:
    song:
      payload:
        type: object
        properties:
          title:
            description: Title of a song
            type: string
          status:
            type: string
            enum:
              - RELEASED
              - NOT_RELEASED

When I execute:

ag kafka-example.yml @asyncapi/java-template -o ./output -p server=production

The file Song.java is generated but it contains the status as string. It should create a Status enum and use that one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions