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

Examples for enums with fields are wrapped in double and single quotes #723

Open
sam0r040 opened this issue Apr 26, 2024 · 0 comments
Open

Comments

@sam0r040
Copy link
Collaborator

sam0r040 commented Apr 26, 2024

FYI, I think I have a better understanding of the cause regarding enums being between ' " ... " ' .

  1. Let's consider this enum:
@Getter
@RequiredArgsConstructor
public enum MessageStatus {
    OK(200, "OK"),
    BAD_REQUEST(400, "Bad Request"),
    UNAUTHORIZED(401, "Unauthorized"),
    NOT_FOUND(404, "Not Found"),
    INTERNAL_SERVER_ERROR(500, "Internal Server Error");

    private final int value;
    private final String reasonPhrase;
}

generated yaml is:

    my.package.infra.remote_service_1.message.reply.MessageReply:
      type: object
      properties:
        errorMessage:
          type: string
        messageStatus:
          type: string
          enum:
            - OK
            - BAD_REQUEST
            - UNAUTHORIZED
            - NOT_FOUND
            - INTERNAL_SERVER_ERROR
        payload:
          $ref: '#/components/schemas/my.package.infra.remote_service_1.message.reply.Message'
      examples:
        - errorMessage: string
          messageStatus: OK
          payload:
 

No problem here: messageStatus: OK is correct, i.e., OK is NOT surrounded by single and double quote

  1. If I add the annotation @Schema(enumAsRef = true) on the MessageStatusclass, then the generated yaml is:
    my.package.infra.remote_service_1.message.reply.MessageReply:
      type: object
      properties:
        errorMessage:
          type: string
        messageStatus:
          $ref: '#/components/schemas/my.package.infra.remote_service_1.message.reply.MessageStatus'
        payload:
          $ref: '#/components/schemas/my.package.infra.remote_service_1.message.reply.Message'
      examples:
        - errorMessage: string
          messageStatus: '"OK"'
          payload:

So, having enum being Component, seems to 'trigger' the bug (I guess this is a bug...?),
i.e., turn

   messageStatus: OK

into

   messageStatus: '"OK"'

Which is NOT correct

  1. now, If I change @Schema(enumAsRef = true) to @Schema(enumAsRef = true, example = "OK")
    the generated yaml is now:
   my.package.infra.remote_service_1.message.reply.MessageReply:
     type: object
     properties:
       errorMessage:
         type: string
       messageStatus:
         $ref: '#/components/schemas/my.package.infra.remote_service_1.message.reply.MessageStatus'
       payload:
         $ref: '#/components/schemas/my.package.infra.remote_service_1.message.reply.Message'
     examples:
       - errorMessage: string
         messageStatus: OK
         payload:

So, exactly the same as before EXCEPT FOR messageStatus: OK which does not have the ' " ... " ' around the enum anymore.

I could not find this bug being reported in https://github.com/asyncapi/parser-js/issues?q=is%3Aissue+is%3Aopen+enum
I am not sure where / how to report this bug.

Can I kindly ask you to help me reporting this bug / initiate an inquiry ? I am not sure where I should send this info?
Feel free to copy pate / reference this comment where needed.

Thanks.

Pascal

Originally posted by @pdalfarr in #534 (comment)

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