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

Add Schema field to Spec for introspection #629

Merged
merged 6 commits into from
Nov 9, 2023
Merged

Add Schema field to Spec for introspection #629

merged 6 commits into from
Nov 9, 2023

Conversation

emcfarlane
Copy link
Contributor

@emcfarlane emcfarlane commented Nov 6, 2023

New field Schema of type any on Spec. For proto based schemas the type will be of protoreflect.MethodDescriptor. This allows for easy introspection to interceptors.

Updated generated code to add the new WithSchema option to both handlers and clients. Schema is fetched from the proto file using the file.GoDescriptorIdent. To ensure generated code is matched with a library that includes the option a new version tag is added for v1.13.

Example

For a unary request one can access the input and output descriptors by casting the interface and using protoreflect:

methodDesc, ok := req.Spec().Schema.(protoreflect.MethodDescriptor)
if !ok {
	return nil, fmt.Errorf("expected protoreflect.MethodDescriptor got %T", req.Spec().Schema)
}
inputDesc := methodDesc.Input()
outputDesc := methodDesc.Output()

Fixes #571 and #600

New field Schema of type any on Spec objects. For proto based schemas
the type will be of protoreflect.MethodDescriptor. This allows for easy
introspection to interceptors.
client_ext_test.go Outdated Show resolved Hide resolved
client_ext_test.go Outdated Show resolved Hide resolved
client_ext_test.go Outdated Show resolved Hide resolved
cmd/protoc-gen-connect-go/main.go Outdated Show resolved Hide resolved
@emcfarlane emcfarlane requested a review from jhump November 8, 2023 17:34
client_ext_test.go Outdated Show resolved Hide resolved
@jhump jhump merged commit 8292c67 into main Nov 9, 2023
8 checks passed
@jhump jhump deleted the ed/schema branch November 9, 2023 13:31
@jhump jhump added the enhancement New feature or request label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose deprecated option in interceptor
2 participants