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

Ques: Is there a reason to force the operationId to camelcase #591

Open
abhishekdev opened this issue Feb 28, 2024 · 5 comments
Open

Ques: Is there a reason to force the operationId to camelcase #591

abhishekdev opened this issue Feb 28, 2024 · 5 comments
Labels
question Further information is requested

Comments

@abhishekdev
Copy link

abhishekdev commented Feb 28, 2024

Question

Is there a reason to force the operationID to camelcase?

Current Behavior
e.g. A operation ID like EvaluateUserIAM will get generated as evaluateUserIam

Expected behavior
Based on the spec guide (reffered below) I guess if an operation ID is found on the schema it should not be mutated.

The openID spec mentions that the operation ID is case sensitive, however since the generator is mutating the operation name to be camelcase it causes confusion for consuming clients.

Screenshot 2024-02-28 at 5 33 09 PM

Source Reference

export function getOperationIdentifier(id?: string) {
if (!id) return;
if (id.match(/[^\w\s]/)) return;
id = _.camelCase(id);
if (cg.isValidIdentifier(id)) return id;
}

@Xiphe
Copy link
Collaborator

Xiphe commented Feb 29, 2024

I tend to say: Probably no specific reason.

For me this makes sense though as Commonly in javascript/typescript functions and methods start with a lower case and only classes and types use uppercase.

@Xiphe Xiphe added the question Further information is requested label Feb 29, 2024
@abhishekdev
Copy link
Author

abhishekdev commented Feb 29, 2024

Thanks for sharing your thoughts @Xiphe.

It seems there is already a graceful fallback built into the logic to check for invalid JS/TS characters (i.e. regex + isValidIdentifier check). Given these checks are in place, should JS code convention override the spec at this code generation layer though?

As long as valid code is generated, I guess the API naming spec (=> source of truth) should be given precedence which might be using its own contextual naming convention. Thoughts?

e.g. Even if the the API name is evaluateUserIAM, the current naming would force it to evaluateUserIam. creating a cognitive load for the users consuming the same API over different platforms (via different code generators).

PS: My personal opinion would be to not use acronyms/abbreviations like such in camelcase strings to help with readability. But convention like this is a challenge to enforce for API's one does not control and the OpenAPI specs defining the field as case-sensitive

@Xiphe
Copy link
Collaborator

Xiphe commented Feb 29, 2024

I get your point and principally agree.

Please bare in mind that when we change this, it will potentially have wide-ranging impacts. It would potentially cause a lot of breaking changes for the clients generated. I'd therefore move this behind a feature flag to opt-into rather then change default behavior.

With this in mind, personally I find the additional cognitive load negligible as such I'm not sure If the additional complexity on this system is worth it.

I'd still be open to learn if others would also be interested in having this behavior. Might also be a good case for the Plugin System that @fimion is currently championing. (For this se should maybe add a naming related hook)

@fimion
Copy link
Contributor

fimion commented Feb 29, 2024

Yeah, we could probably add a naming hook. We would need to specify the type of thing we are naming, but then you could handle it how you want to.

@abhishekdev
Copy link
Author

I agree! Changing this should definitely considered as a breaking change.

The ability to opt-in is a reasonable path forward.

The concept of the "plugin system" sounds very interesting. I'll take a look over the weekend and If I can contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants