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

MethodDescriptor: add input and output types #1503

Merged
merged 3 commits into from
Apr 10, 2023
Merged

MethodDescriptor: add input and output types #1503

merged 3 commits into from
Apr 10, 2023

Conversation

jordancoll
Copy link
Contributor

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 general ScalaType means calling code will just have to cast back down to ScalaType.Message to finally get at the underlying Descriptor.

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.

@thesamet
Copy link
Contributor

thesamet commented Apr 5, 2023

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")
Copy link
Contributor

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(
Copy link
Contributor

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")
Copy link
Contributor

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")
Copy link
Contributor

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)
Copy link
Contributor

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)

@thesamet thesamet merged commit 04b4198 into scalapb:master Apr 10, 2023
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

Successfully merging this pull request may close these issues.

2 participants