modelina icon indicating copy to clipboard operation
modelina copied to clipboard

Enum generate int values when should be double

Open jonaslagoni opened this issue 4 years ago • 5 comments

Describe the bug

Given the following schema

{
    "$id": "Root",
    "enum": [
        2,
        3
    ],
    "type": "number"
}

The generator will generate the following schema


import com.fasterxml.jackson.annotation.*;
public enum Root {
  NUMBER_2(2), NUMBER_3(3);

  private Double value;

  Root(Double value) {
    this.value = value;
  }
    
  @JsonValue
  public Double getValue() {
    return value;
  }

  @Override
  public String toString() {
    return String.valueOf(value);
  }

  @JsonCreator
  public static Root fromValue(Double value) {
    for (Root e : Root.values()) {
      if (e.value.equals(value)) {
        return e;
      }
    }
    throw new IllegalArgumentException("Unexpected value '" + value + "'");
  }
}

Which throws the following error, when compiled:

incompatible types: int cannot be converted to Double

Expected behavior

Expected the enum to be compiled successfully. So the enum generator has to check the type of the enum, to see if integer values should convert to double values, or the other way around.

jonaslagoni avatar Sep 23 '21 17:09 jonaslagoni

Related BlackBox tests that currently is being blacklisted - https://github.com/asyncapi/modelina/blob/3f14b6cc44eb10af4c74fbba9d8d12037ae66ad4/test/blackbox/blackbox.spec.ts#L54 https://github.com/asyncapi/modelina/blob/3f14b6cc44eb10af4c74fbba9d8d12037ae66ad4/test/blackbox/blackbox.spec.ts#L41

jonaslagoni avatar Oct 12 '21 09:10 jonaslagoni

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Feb 10 '22 00:02 github-actions[bot]

Still relevant, waiting on #530

jonaslagoni avatar Feb 10 '22 07:02 jonaslagoni

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Jun 14 '22 00:06 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] avatar Oct 13 '22 00:10 github-actions[bot]