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

fix: google protobuf timestamps don't properly get suffixed when useDate=false and prefix/suffix #1146

Merged
merged 1 commit into from
Dec 9, 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
228 changes: 228 additions & 0 deletions integration/suffix-usedate/google/protobuf/timestamp.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/suffix-usedate/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
useDate=false,typeSuffix=NoUseDateS,typePrefix=NoUseDateP
18 changes: 18 additions & 0 deletions integration/suffix-usedate/suffix-no-usedate-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NoUseDatePSuffixTypeNoUseDateS } from "./suffix-no-usedate-type";

describe("suffix", () => {
it("generates types correctly", () => {
const obj: NoUseDatePSuffixTypeNoUseDateS = {
createdAt: { seconds: 1317826080, nanos: 0 },
};
expect(obj).toBeTruthy();

// make sure all conversions to and from handle prefixes and suffixes
//
const json = NoUseDatePSuffixTypeNoUseDateS.toJSON(obj);

expect(json).toEqual({ createdAt: "2011-10-05T14:48:00.000Z" });

expect(NoUseDatePSuffixTypeNoUseDateS.fromJSON(json)).toEqual(obj);
});
});
6 changes: 6 additions & 0 deletions integration/suffix-usedate/suffix-no-usedate-type.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";
import "google/protobuf/timestamp.proto";

message SuffixType {
google.protobuf.Timestamp created_at = 9;
}
121 changes: 121 additions & 0 deletions integration/suffix-usedate/suffix-no-usedate-type.ts

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

2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ function makeTimestampMethods(
} else if (typeof o === "string") {
return ${toTimestamp}(new ${bytes.globalThis}.Date(o));
} else {
return Timestamp.fromJSON(o);
return ${options.typePrefix}Timestamp${options.typeSuffix}.fromJSON(o);
}
}
`,
Expand Down
Loading