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

Default enum causes invalid typescript class #25

Open
rurutia opened this issue Feb 16, 2019 · 1 comment
Open

Default enum causes invalid typescript class #25

rurutia opened this issue Feb 16, 2019 · 1 comment

Comments

@rurutia
Copy link

rurutia commented Feb 16, 2019

Default enum value in schema is incorrectly compiled to variable name instead of string value
color.avsc

{
  "namespace": "com.michaelyu.test",
  "name": "color",
  "type": "record",
  "fields": [
    {
      "name": "colorType",
      "type": {
        "type": "enum",
        "name": "colorTypes",
        "symbols": [
          "red",
          "blue",
          "green"
        ]
      },
      "default": "red"
    }
  ]
}

color.ts snippet after compilation with error TS2304: Cannot find name 'red'

...
export class color extends BaseAvroRecord implements colorInterface {
...
    public colorType: colorTypes = red;
...

the actual implementation could be related to #26

@Raghav0318
Copy link

Raghav0318 commented Jun 6, 2019

I have the same issue. Is there a plan to fix this?

My schema:

{
"namespace": "ces.avro", "name": "DeskOrder", "type": "record",
"fields": [
{"name": "Id", "type": "long"},
{"name": "SecurityId", "type": "long", "default": 0},
{"name": "SecurityIDSource", "type": ["null", "string"], "default": null},
{"name": "Direction", "type": {"name": "DirectionEnum", "type": "enum", "symbols": ["NONE", "BUY", "SELL"]}, "default": "NONE"},
{"name": "ReleasedStatus", "type": {"name": "ReleasedStatusEnum", "type": "enum", "symbols": ["NONE", "HOLD", "ACTIVE", "DONE"]}, "default": "NONE"},
{"name": "StartBD", "type": "long", "default": 0, "doc": "epoch seconds"},
{"name": "StopBD", "type": "long", "default": 0, "doc": "epoch seconds"},
{"name": "FillStatus", "type": {"name": "FillStatusEnum", "type": "enum", "symbols": ["NONE", "PARTIAL", "FILLED"]}, "default": "NONE"},
{"name": "Currency", "type": ["null", "string"], "default": null},
{"name": "TotalParAmount", "type": "double", "default": 0.0},
{"name": "FilledParAmount", "type": "double", "default": 0.0},
{"name": "UnFilledParAmount", "type": "double", "default": 0.0}
]
}

The resulting code for the "Direction field is
public Direction: DirectionEnum = NONE;

instead of
public Direction: DirectionEnum = DirectionEnum.NONE;

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

2 participants