diff --git a/docs/handling reserved keywords.md b/docs/handling reserved keywords.md new file mode 100644 index 0000000..eb2e12a --- /dev/null +++ b/docs/handling reserved keywords.md @@ -0,0 +1,55 @@ +# Handling reserved keywords + +JSON Schema have no restrictions on property names. However in programming languages, there often is reserved keywords that properties cannot be named. + +For example given the following JSON Schema: + +```json +{ + "$schema": "https://json-schema.org/draft/2020-12/idl-schema", + "name": "SomeTitle", + "type": "object", + "properties": { + "return": { + "type": "string" + } + } +} +``` + +The optimal output to something like TypeScript, would probably be the following: + +```ts +class SomeTitle { + return: string; +} +``` + +However, TypeScript don't allow such a property name, because it collide with the reserved keyword `return` used to return data from functions. + +## Solutions +There are no specific solutions that we enforce, it is up to the implementor. + +To make your life easier, here is the list of keywords that are reserved: +- [TypeScript](reserved%20keywords/typescript.md) +- [C#](reserved%20keywords/csharp.md) +- [javascript](reserved%20keywords/javascript.md) +- [java](reserved%20keywords/java.md) + +If the reserved keyword list your are looking for is not present, please provide a PR! + +### Adding something extra to the property name +One of the solutions is to pre- or post-fix some kind of word to the rendered property name. + +For example prefixing `reserved` to a property name. + +```ts +class SomeTitle { + reservedReturn: string; +} +``` + +This means you will end up with two names for the property. The one rendered, and the one needed for serializing the data model (because otherwise validating the serialized data wont validate correctly against the JSON Schema). + +### Throw an error +The easiest solution is to throw an error whenever they are encountered, and stopping the generation of models. \ No newline at end of file diff --git a/docs/reserved keywords/csharp.md b/docs/reserved keywords/csharp.md new file mode 100644 index 0000000..7af932c --- /dev/null +++ b/docs/reserved keywords/csharp.md @@ -0,0 +1,82 @@ +## Reserved keywords for Go +We do not guarantee this list of keywords are complete, however, if you find anything missing, please provide a PR! + +``` +abstract +as +base +bool +break +byte +case +catch +char +checked +class +const +continue +decimal +default +delegate +do +double +else +enum +event +explicit +extern +false +finally +fixed +float +for +foreach +goto +if +implicit +in +int +interface +internal +is +lock +long +namespace +new +null +object +operator +out +override +params +private +protected +public +readonly +ref +return +sbyte +sealed +short +sizeof +stackalloc +static +string +struct +switch +this +throw +true +try +typeof +uint +ulong +unchecked +unsafe +ushort +using +virtual +void +volatile +while +``` \ No newline at end of file diff --git a/docs/reserved keywords/java.md b/docs/reserved keywords/java.md new file mode 100644 index 0000000..7ca57bf --- /dev/null +++ b/docs/reserved keywords/java.md @@ -0,0 +1,54 @@ +## Reserved keywords for Java +We do not guarantee this list of keywords are complete, however, if you find anything missing, please provide a PR! + +``` +abstract +continue +for +new +switch assert +default +goto +package +synchronized +boolean +do +if +private +this +break +double +implements +protected +throw +byte +else +import +public +throws +case +enum +instanceof +return +transient +catch +extends +int +short +try +char +final +interface +static +void +class +finally +long +strictfp +volatile +const +float +native +super +while +``` \ No newline at end of file diff --git a/docs/reserved keywords/javascript.md b/docs/reserved keywords/javascript.md new file mode 100644 index 0000000..5b49fde --- /dev/null +++ b/docs/reserved keywords/javascript.md @@ -0,0 +1,208 @@ +## Reserved keywords for JavaScript +We do not guarantee this list of keywords are complete, however, if you find anything missing, please provide a PR! + +### Standard reserved keywords +``` +abstract +arguments +await +boolean +break +byte +case +catch +char +class +const +continue +debugger +default +delete +do +double +else +enum +eval +export +extends +false +final +finally +float +for +function +goto +if +implements +import +in +instanceof +int +interface +let +long +native +new +null +package +private +protected +public +return +short +static +super +switch +synchronized +this +throw +throws +transient +true +try +typeof +var +void +volatile +while +with +yield +``` +### Reserved for > ECMAScript 5/6 +``` +abstract +boolean +byte +char +double +final +float +goto +int +long +native +short +synchronized +throws +transient +volatile +``` +### Reserved built-in objects, properties and methods +``` +hasOwnProperty +Infinity +isFinite +isNaN +isPrototypeOf +length +Math +NaN +name +Number +Object +prototype +String +toString +undefined +valueOf +``` + +### Java reserved words +JavaScript is often used together with Java, in those cases, these words are reserved. + +``` +getClass +java +JavaArray +javaClass +JavaObject +JavaPackage +``` +### Other reserved words +``` +alert +all +anchor +anchors +area +assign +blur +button +checkbox +clearInterval +clearTimeout +clientInformation +close +closed +confirm +constructor +crypto +decodeURI +decodeURIComponent +defaultStatus +document +element +elements +embed +embeds +encodeURI +encodeURIComponent +escape +event +fileUpload +focus +form +forms +frame +innerHeight +innerWidth +layer +layers +link +location +mimeTypes +navigate +navigator +frames +frameRate +hidden +history +image +images +offscreenBuffering +open +opener +option +outerHeight +outerWidth +packages +pageXOffset +pageYOffset +parent +parseFloat +parseInt +password +pkcs11 +plugin +prompt +propertyIsEnum +radio +reset +screenX +screenY +scroll +secure +select +self +setInterval +setTimeout +status +submit +taint +text +textarea +top +unescape +untaint +window +``` \ No newline at end of file diff --git a/docs/reserved keywords/typescript.md b/docs/reserved keywords/typescript.md new file mode 100644 index 0000000..88d7267 --- /dev/null +++ b/docs/reserved keywords/typescript.md @@ -0,0 +1,82 @@ +## Reserved keywords for TypeScript +We do not guarantee this list of keywords are complete, however, if you find anything missing, please provide a PR! + +``` +abstract +as +base +bool +break +byte +case +catch +char +checked +class +const +continue +decimal +default +delegate +do +double +else +enum +event +explicit +extern +false +finally +fixed +float +for +foreach +goto +if +implicit +in +int +interface +internal +is +lock +long +namespace +new +null +object +operator +out +override +params +private +protected +public +readonly +ref +return +sbyte +sealed +short +sizeof +stackalloc +static +string +struct +switch +this +throw +true +try +typeof +uint +ulong +unchecked +unsafe +ushort +using +virtual +void +volatile +while +``` \ No newline at end of file