You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the proto files for which I generate TS code, there are messages with the same names but in different packages. For example, within one message, there can be a field of a type with the same name, but from a different package.
It's easier to demonstrate with an example:
In the code generated for api.proto, the import of User includes an alias to avoid collisions:
import{UserasUser1}from"./model.js";
However, in the constructor methods toJson and fromJson of User (in api.ts) incorrect message name is generated. Instead of the alias User1, there is User (User.fromJson/User.toJson) in map-functions:
For non-repeated fields, the correct alias User1 is created.
Solution
After studying the code, I guess I found a place with an error. Calling toCodeString, toString leads to caching of the calculated value (code, codeWithImports).
As far as I understand, because of this, when code is generated from all the collected Code instances later, these objects retain an incorrect value that does not take into account the necessary parameters/context.
I've opened a small PR, that fixes this.
The text was updated successfully, but these errors were encountered:
Ah! Your diagnosis is exactly right; we need to keep the readSnippet as the Code object for its import to get rewritten appropriately. Thanks for the fix and great PR!
Hi! Thanks for the lib 🙂
Problem
In the proto files for which I generate TS code, there are messages with the same names but in different packages. For example, within one message, there can be a field of a type with the same name, but from a different package.
It's easier to demonstrate with an example:
In the code generated for api.proto, the import of
User
includes an alias to avoid collisions:However, in the constructor methods
toJson
andfromJson
ofUser
(inapi.ts
) incorrect message name is generated. Instead of the aliasUser1
, there isUser
(User.fromJson
/User.toJson
) in map-functions:For non-repeated fields, the correct alias
User1
is created.Solution
After studying the code, I guess I found a place with an error. Calling toCodeString, toString leads to caching of the calculated value (code, codeWithImports).
As far as I understand, because of this, when code is generated from all the collected
Code
instances later, these objects retain an incorrect value that does not take into account the necessary parameters/context.I've opened a small PR, that fixes this.
The text was updated successfully, but these errors were encountered: