json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

Allow unicode characters in type name

Open zhangciwu opened this issue 5 years ago • 7 comments

https://github.com/bcherny/json-schema-to-typescript/blob/d898361ff973d3746ea695f1efce75c975061c6f/src/utils.ts#L164

The member of type name is restricted to only english letters (and some symbol) Typescript now allows unicode characters (doc link)

So, modify this function to allow unicode characters in type name, or as an option?

zhangciwu avatar Mar 04 '20 10:03 zhangciwu

My scenario: title value is in full chinese, so the result typename is blank, and error happens:

SyntaxError: Declaration or statement expected. (8:1)
   6 | */
   7 | 
>  8 | export type  = string
     | ^

(Maybe another bug to fix: do not generate blank type name)

zhangciwu avatar Mar 04 '20 10:03 zhangciwu

A minimium schema would cause this error:

    {
            "type": "object",
            "title": "呵呵",
            "properties": {
                "some_key": {
                    "type": "string",
                    "title": "哈哈"
                }
            }
        }

zhangciwu avatar Mar 04 '20 10:03 zhangciwu

Sounds good to me! Want to put up a Pull Request?

bcherny avatar Mar 08 '20 19:03 bcherny

Fix the blank name bug in #280

Allow unicode is a little complicated, would be later

zhangciwu avatar Mar 10 '20 03:03 zhangciwu

Thanks for the fix, but I think supporting Unicode (as you suggested) could be a better way to do it. What issues are you running into?

bcherny avatar Mar 10 '20 06:03 bcherny

Got a doc: Valid JavaScript variable names in ES2015 Maybe using this code provided in this page to judge a string is a valid identifier is comprehensive, but it's not packed into npm, and while I found some packs:

https://github.com/purplecabbage/valid-identifier https://github.com/YerkoPalma/is-valid-identifier https://github.com/SteveWestbrook/is-valid-var-name

First download for most times, but seems not active; others are not widely adopted (npm downloads) A little hard to choose

zhangciwu avatar Mar 10 '20 08:03 zhangciwu

I am working on this.

I wanted to confirm that this project targets ES5. I'm considering using Unicode aware regex, but it appears to be only supported from ES2015.

If using ES5, I found https://github.com/mathiasbynens/regexpu.

Additionally, are there any concerns about backwards compatibility or previously generated names?

iansw246 avatar Jul 14 '23 20:07 iansw246