Skip to content

Commit

Permalink
feat: Add options to limit generation of encode and decode methods to…
Browse files Browse the repository at this point in the history
… only specific message types (#1085)

I created this PR as a possible to solution to the feature request
submitted in #1084.

I added integration tests for test coverage, and updated the
documentation to include the two new options.
  • Loading branch information
akrennmair authored Dec 3, 2024
1 parent bf304b2 commit c7372fa
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 49 deletions.
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ Generated code will be placed in the Gradle build directory.

This is useful if you want "only types".

- With `--ts_proto_opt=outputEncodeIncludeTypes=regex`, the `Message.encode` method will only be output for types whose name matches the provided regular expression.

This is useful if you want to limit `encode` methods to only select types.

- With `--ts_proto_opt=outputDecodeIncludeTypes=regex`, the `Message.decode` method will only be output for types whose name matches the provided regular expression.

This is useful if you want to limit `decode` methods to only select types.

- With `--ts_proto_opt=outputJsonMethods=false`, the `Message.fromJSON` and `Message.toJSON` methods for working with JSON-coded data will not be output.

This is also useful if you want "only types".
Expand Down
11 changes: 11 additions & 0 deletions integration/output-decode-include-types/encode.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

import "google/protobuf/wrappers.proto";

message EncodeWithDecodeMethod {
string encode = 1;
}

message EncodeDontGenerateDecodeMethod {
string encode_dont_generate_decode_method = 1;
}
49 changes: 49 additions & 0 deletions integration/output-decode-include-types/encode.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integration/output-decode-include-types/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
outputEncodeMethods=decode-only,outputPartialMethods=false,outputJsonMethods=false,nestJs=false,outputDecodeIncludeTypes=^EncodeWithDecodeMethod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
outputEncodeMethods=true,outputPartialMethods=false,outputJsonMethods=false,nestJs=false,outputEncodeIncludeTypes=^Request,outputDecodeIncludeTypes=^Response$
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

import "google/protobuf/wrappers.proto";

message Request {
string request_id = 1;

message Nested {
string more_data = 1;
}

Nested nested = 2;
}

message Response {
string response_id = 1;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions integration/output-encode-include-types/encode.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

import "google/protobuf/wrappers.proto";

message Encode {
string encode = 1;
}

message DontGenerateEncode {
string dont_generate_encode = 1;
}
28 changes: 28 additions & 0 deletions integration/output-encode-include-types/encode.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integration/output-encode-include-types/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
outputEncodeMethods=encode-only,outputPartialMethods=false,outputJsonMethods=false,nestJs=false,outputEncodeIncludeTypes=^Encode$
4 changes: 0 additions & 4 deletions integration/output-encode-only/encode.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions integration/output-encode-only/google/protobuf/wrappers.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c7372fa

Please sign in to comment.