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

TypeScript enum generation doesn't account for invalid characters (e.g: dashes) in field names #105

Closed
PeterJCLaw opened this issue Dec 19, 2024 · 2 comments

Comments

@PeterJCLaw
Copy link

PeterJCLaw commented Dec 19, 2024

If a choice field contains a dash (-) then the resulting enum's name also contains a dash, which then doesn't compile. This results in an error running RudderTyper.

The reproduce here is a choice field within an array type, though I assume this would apply to any choice field.

plan.json
{
	"createdAt": "2024-12-18T16:43:46.508Z",
	"creationType": "Data catalog",
	"id": "redacted",
	"name": "Peter Test",
	"rules": {
		"events": [
			{
				"description": "A dummy event intended to explore a wide variety of field types.",
				"eventType": "track",
				"name": "kitchen-sink",
				"rules": {
					"$defs": {
					},
					"$schema": "http://json-schema.org/draft-07/schema#",
					"description": "A dummy event intended to explore a wide variety of field types.",
					"properties": {
						"properties": {
							"additionalProperties": false,
							"properties": {
								"array-of-custom-type": {
									"items": {
										"additionalProperties": false,
										"properties": {
											"custom-type-enum-member": {
												"enum": [
													"ct-first",
													"ct-second"
												],
												"type": [
													"string"
												]
											},
											"custom-type-number-member": {
												"type": [
													"number"
												]
											},
											"custom-type-string-member": {
												"type": [
													"string"
												]
											}
										},
										"required": [
										],
										"type": [
											"object"
										]
									},
									"type": [
										"array"
									]
								}
							},
							"required": [
							],
							"type": "object"
						}
					},
					"type": "object"
				}
			}
		]
	},
	"updatedAt": "2024-12-18T16:43:46.508Z",
	"version": 4,
	"workspaceId": "redacted"
}
$ npx rudder-typer update 
  ✘ Error: An unexpected error occurred.
   → '{' expected. (44:19)
       42 | }
       43 |
     > 44 | export enum Custom-type-enum-member {
          |                   ^
       45 |     S_CT_FIRST = 'ct-first',
       46 |     S_CT_SECOND = 'ct-second',
       47 | }

  If you are unable to resolve this issue,open an issue on GitHub. Please include 
  that you are using version 1.3.1 of RudderTyper.

When addressing this it may be worth considering #104 at the same time.

@contributor-support
Copy link

Thanks for opening this issue! We'll get back to you shortly. If it is a bug, please make sure to add steps to reproduce the issue.

@PeterJCLaw PeterJCLaw changed the title TypeScript enum generation doesn't account for invalid characters in field names TypeScript enum generation doesn't account for invalid characters (e.g: dashes) in field names Dec 19, 2024
@akashrpo
Copy link

The fix is released in the PR #107 . Thanks for raising the issue.

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

2 participants