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

type generator: Use helper to identify duplicate fields to skip in message hierarchies #6

Open
polinasok opened this issue Nov 22, 2019 · 0 comments

Comments

@polinasok
Copy link
Contributor

Move the logic from the long function that generates the go type into a helper with good function and inline comments. Possible names: shouldEmitField(), skipField()

Some fields are redefined in hierarchical types, but to ensure consistent translation between JSON & Go, we must limit each field to appear only once. We need skip two types of duplicate fields:

  1. Parent definition defines field : type, child definition assigns a single value to that type => skip field in child
  2. Parent definition defines field : "any", child definitions refines the type to something concrete => skip field in parent
    NOTE: in case non-message types define the same

Programatic detection of these is tricky since we process one type at a time, so for now we just hardcode known fields/type pairs that fall into the above categories. Comments to document these cases will help.
"type" - use in ProtocolMessage, skip assignments in children (1)
"command" - use in Request and Response, skip assignments in children (1)
"event" - use in Event, skip assignments in all children (1)
"arguments" - skip any type in Request, use specific types in children (2)
"body" - skip any type in Response and Event, use specific types in children (2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant