-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add getTypeUrl method to generated code #1463
Conversation
@taylorcode Thank you! We can merge it but I can't bring this PR up to date. Can you please press the Update button for me? Thank you! |
@taylorcode Also, adding a test would've been appreciated - just to make sure this feature does not get broken by a random change in the future. |
@alexander-fenster I've added a test but I'm not confident I did it correctly. I ran I noticed the test files within the |
61b3f62
to
ae0f73d
Compare
@taylorcode Mind giving the reviewers a permission to update your branch? Thank you! |
@alexander-fenster sorry, I'm not sure how to grant write access. Could you provide guidance? thanks |
An encoded proto containing a nested Any that is missing a typeUrl cannot be decoded in Python, and perhaps other languages.
js
python
It looks like in other languages, e.g. Java a nested Any message has a
getTypeUrl
method. It would be nice if protobufjs's Any also provided a similar method or property that would return the default type url.It seems like in order to add this to Any, we would need messages to know their default typeUrl. In other languages this can be determined through reflection, but for JS this doesn't work reliable for at least two reasons. First, we'd need a way to determine the constructor name. instance.constructor.name gives us this, but it does not work in IE, and the workarounds seem wonky. Second, minifiers can change the name of constructors. In practice this usually shouldn't be a problem because protobufjs messages are properties on an object and not local variables (and therefore not mangle-able), but there are minifiers that can mangle properties, such as closure. Therefore I think the default type url needs to be represented as a string.