musement / types-generator

3 stars 1 forks source link

Error on enum string contain single quote #18

Open manhp-codeleap opened 2 years ago

manhp-codeleap commented 2 years ago

eg: if enum contain single quote in it's body => when pass to prettier => it should be error

From openApi: eg: enum : [ "this is normal", "but this's why cause error" # => this will cause error on parser ]

manhp-codeleap commented 2 years ago

I suggest something like this: (add safe surroundEnum) for : 3 generators


const safeSurroundEnum = (item: string): string => {
  if (item.indexOf("'") != -1) {
    return surround('"', '"')(item);
  }
  return surround("'", "'")(item);
};
export const typeScriptGenerator: Generator = {
...
  getTypeEnum: flow(map(safeSurroundEnum), getUnion),
  ...
};