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

Choice fields with hyphens result in dashes in enum values #92

Closed
PeterJCLaw opened this issue Dec 11, 2024 · 5 comments
Closed

Choice fields with hyphens result in dashes in enum values #92

PeterJCLaw opened this issue Dec 11, 2024 · 5 comments

Comments

@PeterJCLaw
Copy link

For example:

"shipping_method": {
	"enum": [
		"fedex",
		"dhl",
		"royal-mail",
		"carrier-pigeon"
	],
	"type": [
		"string"
	]
},

Results in:

/**
 * This client was automatically generated by RudderTyper. ** Do Not Edit **
 */
package com.rudderstack.ruddertyper.generated;


public enum ShippingMethod {

    S_FEDEX("fedex"),
    S_DHL("dhl"),
    S_ROYAL-MAIL("royal-mail"),
    S_CARRIER-PIGEON("carrier-pigeon");

    private final Object value;

    ShippingMethod(Object value) {
        this.value = value;
    }

    public Object getValue() {
        return value;
    }
}

This appears to affect at least the Java and TypeScript generators.

@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.

@TWiStErRob
Copy link

TWiStErRob commented Dec 11, 2024

This line is preparing the name (Java):

key = 'S_' + value.toString().trim().toUpperCase().replace(/ /g, '');

it only removes "space" as invalid characters, it should probably remove everything that's invalid according to

allowedIdentifierStartingChars: 'A-Za-z_',
allowedIdentifierChars: 'A-Za-z0-9_',

@PeterJCLaw
Copy link
Author

IMO it would be nice to replace any (string of) invalid characters with _ rather than dropping them entirely -- so we get like SOME_LONG_NAME from some-long-name rather than SOMELONGNAME, as the former is more readable. Appreciate that changing this for spaces might be breaking for existing consumers though.

@TWiStErRob
Copy link

Oh, yeah, definitely! Removal is hard to read, sorry.

@akashrpo
Copy link

This issue has been resolved in #94. Closing this now.

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

3 participants