-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
MethodDescriptor: add input and output types #1503
Conversation
I agree - it would be better to return the Descriptor. |
|
||
lazy val inputType: Descriptor = { | ||
val inputType = asProto.inputType.getOrElse( | ||
throw new DescriptorValidationException(this, "missing method input type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s"Missing method input type for method $fullName"
) | ||
FileDescriptor | ||
.find(containingService.file, this, inputType) | ||
.getOrElse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets use pattern matching on case Some(d: Descriptor)
to make the asInstanceOf unnecessary and handle the case that what's being found isn't a descriptor.
FileDescriptor | ||
.find(containingService.file, this, inputType) | ||
.getOrElse( | ||
throw new DescriptorValidationException(this, "couldn't build input type descriptor") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't
... for $fullName
} | ||
|
||
lazy val outputType: ScalaType = { | ||
lazy val outputType: Descriptor = { | ||
val outputType = asProto.outputType.getOrElse( | ||
throw new DescriptorValidationException(this, "missing method output type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
.asInstanceOf[Descriptor] | ||
) | ||
FileDescriptor | ||
.find(containingService.file, this, outputType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as earlier comments (capital letter, avoid asInstanceOf through pattern matching)
what it says on the tin.
on gitter, there was mention that these fields would maybe be better exposed as
ScalaType
rather than the message descriptor directly. while I don't think this makes a huge difference, I think it makes consuming the endpoint a little more cumbersome. iiuc protobuf method in/out types will always be messages. upcasting to the more generalScalaType
means calling code will just have to cast back down toScalaType.Message
to finally get at the underlyingDescriptor
.I think a better alternative would be to return the
Descriptor
directly, since afaict wrapping it doesn't add value.Alternatively, the fields could be typed as
ScalaType.Message
to avoid the up & down casts.