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

Introduce generate option to customize output #23

Merged
merged 8 commits into from
May 17, 2024

Conversation

darronschall
Copy link
Contributor

@darronschall darronschall commented May 17, 2024

Closes #17

Add support for a new option on the protoc command line: --twirp_ruby_opt=generate=<service|client|both>. This option customizes whether the plugin generates twirp services, clients, or both. Defaults to both when omitted to preserve backwards compatibility.

  • generate=service - only generate ::Twirp::Service subclass(es).
  • generate=client - only generate ::Twirp::Client subclass(es).
  • generate=both - generate both services and clients. This is the default option to preserve
    backwards compatibility.

Default the value to `:both` for backwards compatibility. Constraint the value to one of `:service`, `:client`, or `:both` and add spec to cover validation.
Note the differentiation here in client generation based on whether or not a service was also generated. When we have a service class, the client class can simply use the `client_for` DSL. Otherwise, we have to build the client from the service descriptor proto.
The complex example exercises more scenarios and will serve us better moving forward. Given that it also demonstrates correct namespace handling of imported types, the "import_type_retention" example was redundant.
There's some repeated code between "when specifying the `skip-empty` option" and when specifying the `skip-empty` and `generate=both` options" that we could do a better job of not repeating ourselves...
// 2. Using imported types for request and response types
// 3. Services proto in a completely different package
//
// This file does _not_ demonstrate best practices.
Copy link
Member

Choose a reason for hiding this comment

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

🤣

@darronschall darronschall merged commit c20aa52 into main May 17, 2024
1 check passed
@darronschall darronschall deleted the introduce-generate-option branch May 17, 2024 15:45
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.

Introduce option to customize generation (only services, only clients, or both)
2 participants