Match should skip unexported fields as they won't be serialized #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some of our DTO objects include unexported fields.
This small patch just ignores those fields, as they aren't serialized by the JSON encoder. This means they shouldn't form part of the API contract. And they can even cause
panics
if they include types that can't be handled.Although I ran into this issue while experimenting with GRPC + Pact, I think this fix makes sense outside of this context as well. Any manually-written object might also have non-exported fields that shouldn't be part of the API Contract, while still ideally being supported by
dsl.Match
.GRPC Details
Note: these details probably aren't needed. This gets into the complications of my experiments with GRPC + Pact. But I wanted to include it for completeness.
I received this panic when creating the consumer pact:
This was caused by an interaction like
That
pactpb
helper delegates todsl.Match(src)
but adds support for GRPC well-known types, likegoogle.protobuf.Timestamp
.The
apiv1.SayHelloResponse
is from a protobuf likeCompiling with the go generator results in
The
panic
above is due to the unexportedstate
field:whose
DoNotCompare
isHence the panic on
unhandled type: func()
So by just ignoring unexported fields (as I think we should be doing anyway), we can avoid this whole mess. :)