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

Clear oneofs correctly #6

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Generate
run: |
make clean
make format
make generate
make generate-check
- name: Test
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ check: test lint
test: $(codegen)
$(GO) test $(GO_TEST_FLAGS) ./...

.PHONY: format
format: $(BUF)
$(BUF) format -w

.PHONY: lint
lint: $(codegen) $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run
Expand Down
147 changes: 128 additions & 19 deletions gen/gofakeit/test/oneofs.pb.go

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

4 changes: 2 additions & 2 deletions gen/gofakeit/test/wkt.pb.go

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

16 changes: 12 additions & 4 deletions proto/gofakeit/example/user.proto
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
syntax="proto3";
syntax = "proto3";
package gofakeit.example;
option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/example";

import "gofakeit/gofakeit.proto";

option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/example";

message User {
fixed64 user_id = 1;
string first_name = 2 [(gofakeit.generate).tag = "{firstname}"];
string last_name = 3 [(gofakeit.generate).tag = "{lastname}"];
string email = 4 [(gofakeit.generate).tag = "{email}"];
Location location = 5;
repeated string hobbies = 6 [
(gofakeit.generate).repeated.range = { min: 1, max: 3},
(gofakeit.generate).repeated.range = {
min: 1,
max: 3
},
(gofakeit.generate).repeated.element.tag = "{hobby}"
];
map<string, PetType> pets = 7 [
(gofakeit.generate).map.range = { min: 1, max: 3},
(gofakeit.generate).map.range = {
min: 1,
max: 3
},
(gofakeit.generate).map.key.tag = "{petname}"
];
}
Expand Down
6 changes: 4 additions & 2 deletions proto/gofakeit/gofakeit.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
syntax="proto3";
syntax = "proto3";

package gofakeit;
option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit";

import "google/protobuf/descriptor.proto";

option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit";

extend google.protobuf.FieldOptions {
Generator generate = 112233;
}
Expand Down
21 changes: 10 additions & 11 deletions proto/gofakeit/test/map.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
syntax = "proto3";
package gofakeit.test;
option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/test";

import "gofakeit/gofakeit.proto";

option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/test";

enum MapEnum {
MAP_ENUM_UNSPECIFIED = 0;
MAP_ENUM_ONE = 1;
Expand All @@ -13,7 +15,7 @@ message MapMsg {
string foo = 1;
}

message MapDefaults{
message MapDefaults {
map<string, bool> scalars = 1;
map<int32, MapEnum> enums = 2;
map<string, MapMsg> messages = 3;
Expand All @@ -28,23 +30,20 @@ message MapTags {
}

message MapLength {
map<string, string> values = 1 [
(gofakeit.generate).map.len = 3
];
map<string, string> values = 1 [(gofakeit.generate).map.len = 3];
}

message MapRange {
map<string, string> values = 1 [
(gofakeit.generate).map.range = { min: 1, max: 2 }
];
map<string, string> values = 1 [(gofakeit.generate).map.range = {
min: 1,
max: 2
}];
}

message MapSkip {
map<string, string> values = 1 [
(gofakeit.generate).map.key.skip = true,
(gofakeit.generate).map.value.skip = true
];
map<string, string> skipped = 2 [
(gofakeit.generate).skip = true
];
map<string, string> skipped = 2 [(gofakeit.generate).skip = true];
}
14 changes: 10 additions & 4 deletions proto/gofakeit/test/message.proto
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
syntax = "proto3";
package gofakeit.test;
option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/test";

import "gofakeit/gofakeit.proto";

option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/test";

message SelfRecursive {
string foo = 1 [(gofakeit.generate).tag = "{phone}"];
SelfRecursive recurse = 2;
}

message PairRecursive {
message A { B b = 1; }
message B { A a = 2; }
message A {
B b = 1;
}
message B {
A a = 2;
}
}

message MessageSkipped {
MessageSkipped skipped = 1 [(gofakeit.generate).skip = true];
}
}
16 changes: 13 additions & 3 deletions proto/gofakeit/test/oneofs.proto
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
syntax = "proto3";
package gofakeit.test;
option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/test";

import "gofakeit/gofakeit.proto";

option go_package = "github.com/rodaine/protogofakeit/gen/gofakeit/test";

enum OneOfEnum {
ONE_OF_ENUM_UNSPECIFIED = 0;
ONE_OF_ENUM_ONE = 1;
ONE_OF_ENUM_TWO = 2;
}

message OneOf{
message OneOf {
oneof fields {
string scalar = 1;
OneOfEnum enum = 2;
OneOf message = 3;
}
}
}

// see https://github.com/rodaine/protogofakeit/issues/5
message OneOfMessages {
oneof kind {
OneOfMessages foo = 1;
OneOfMessages bar = 2;
}
}
Loading