Skip to content

feat(generated)!: stop generating service names with duplicate Servic… #105

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

Closed
wants to merge 1 commit into from

Conversation

arranf
Copy link
Contributor

@arranf arranf commented Jan 26, 2022

…e suffix

Fixes #104

Consider this PR a draft. I'll round out any edge cases.

@arranf arranf force-pushed the feature/service-generation branch from b3f0bee to 4bdf987 Compare January 26, 2022 18:14
@tatethurston
Copy link
Owner

tatethurston commented Jan 26, 2022

Awesome thanks for opening this. A few remaining steps:

Could you run yarn regen? This will update the examples and jest snap shot files.

I think you'll need to update the examples. yarn check:all should catch any sites that need to be updated.

Could you also update the examples in the README.md?

@arranf
Copy link
Contributor Author

arranf commented Jan 26, 2022

@tatethurston Will do and then I'll tag you again.

Comment on lines +713 to +718
function getServiceName(name: string): string {
return name.toLowerCase().endsWith("service")
? name.replace(new RegExp("(?:s)*service", "i"), "")
: name;
}

Copy link
Owner

@tatethurston tatethurston Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think google-protobuf always appends Service -- did you check to see if that is the case?

If that is true, we can drop the regex and do name.slice(0, name.lastIndexOf('Service'))

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I'm wrong about this -- I do add the service suffix. Instead of the above, we'll want to drop Service from here: https://github.com/tatethurston/TwirpScript/blob/main/src/autogenerate/index.ts#L421-L426

Copy link
Contributor Author

@arranf arranf Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I'm wrong about this -- I do add the service suffix. Instead of the above, we'll want to drop Service from here: https://github.com/tatethurston/TwirpScript/blob/main/src/autogenerate/index.ts#L421-L426

Yeah I spotted this area of the codebase and originally I had this inlined in a few places in that file but it seemed silly to repeatedly run the regex. Eventually I figured that setting the name in a way so that we can assume safely that it doesn't have Service inside it would be best.

Open to more thoughts on this though - I'm not as familiar with the codebase as you are and didn't spend too long playing around. Was mostly trying to validate this was a sane idea.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's delete the two references to Service from autogenerate so the service name ends up exactly as written in the generated code.

@tatethurston
Copy link
Owner

Implemented in #125

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

Successfully merging this pull request may close these issues.

Service Name Generation
2 participants