evestera / json_typegen

Tools and libraries to create types for Rust, Kotlin, TypeScript and Python from JSON samples
https://typegen.vestera.as
Apache License 2.0
273 stars 26 forks source link

[typescript]: key that contain white-space or quote was not quoted #10

Closed DrSensor closed 5 years ago

DrSensor commented 5 years ago

Awesome works! Thank you for creating this crates.

I notice this false behavior which only happen in typescript:

{
  "states": {
    "alphaGo": {
      "on": {
        "": "betaRust"
      }
    },
    "nightl'y update": {
      "on": {
        "every 4 weeks": "channel:beta"
      }
    },
    "b": {
      "on": {
        "ON": "initial D",
        "FALSE_ALARM": "c"
      }
    }
  }
}
interface Root {
    states: States;
}
interface States {
    alphaGo: AlphaGo;
    nightl'y update: NightlYUpdate;
    b: B;
}
interface AlphaGo {
    on: On;
}
interface On {
    "": string;
}
interface NightlYUpdate {
    on: On2;
}
interface On2 {
    every 4 weeks: string;
}
interface B {
    on: On3;
}
interface On3 {
    ON: string;
    FALSE_ALARM: string;
}

The empty string key parsed correctly but some keys that have white-space or quote were not surrounded with double-quote. At least the interface name is correct 🤔

evestera commented 5 years ago

Ah, seems to be a simple oversight on my part when adding a regex, checking if a string contains a valid identifier rather than if it is a valid identifier. Thanks for the bug report. I should get a fixed version released pretty soon.

evestera commented 5 years ago

Made a release with the fix included now.