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

lexgen: handle 'ref' as procedure input type #788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lex/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,16 @@ func writeMethods(typename string, ts *TypeSchema, w io.Writer) error {
case "record":
return nil
case "query":
return ts.WriteRPC(w, typename)
return ts.WriteRPC(w, typename, fmt.Sprintf("%s_Input", typename))
case "procedure":
return ts.WriteRPC(w, typename)
if ts.Input == nil || ts.Input.Schema == nil || ts.Input.Schema.Type == "object" {
return ts.WriteRPC(w, typename, fmt.Sprintf("%s_Input", typename))
} else if ts.Input.Schema.Type == "ref" {
inputname, _ := ts.namesFromRef(ts.Input.Schema.Ref)
return ts.WriteRPC(w, typename, inputname)
} else {
return fmt.Errorf("unhandled input type: %s", ts.Input.Schema.Type)
}
case "object", "string":
return nil
case "subscription":
Expand Down
4 changes: 2 additions & 2 deletions lex/type_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type TypeSchema struct {
Maximum any `json:"maximum"`
}

func (s *TypeSchema) WriteRPC(w io.Writer, typename string) error {
func (s *TypeSchema) WriteRPC(w io.Writer, typename, inputname string) error {
pf := printerf(w)
fname := typename

Expand All @@ -65,7 +65,7 @@ func (s *TypeSchema) WriteRPC(w io.Writer, typename string) error {
case EncodingCBOR, EncodingCAR, EncodingANY, EncodingMP4:
params = fmt.Sprintf("%s, input io.Reader", params)
case EncodingJSON:
params = fmt.Sprintf("%s, input *%s_Input", params, fname)
params = fmt.Sprintf("%s, input *%s", params, inputname)

default:
return fmt.Errorf("unsupported input encoding (RPC input): %q", s.Input.Encoding)
Expand Down
Loading