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

Error on enum string contain single quote #18

Open
manhp-codeleap opened this issue Jan 19, 2022 · 1 comment
Open

Error on enum string contain single quote #18

manhp-codeleap opened this issue Jan 19, 2022 · 1 comment

Comments

@manhp-codeleap
Copy link

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
Copy link
Author

manhp-codeleap commented Jan 19, 2022

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),
  ...
};

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