From 07af886029fe5ed05f2d93af628677fed05da0d5 Mon Sep 17 00:00:00 2001 From: Lukas Jenicek Date: Wed, 24 Apr 2024 14:33:37 +0200 Subject: [PATCH] render comments in webrpc methods --- _examples/golang-basics/example.gen.go | 12 +++++++++--- _examples/golang-basics/example.ridl | 3 +++ _examples/golang-imports/api.gen.go | 2 +- types.go.tmpl | 10 ++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/_examples/golang-basics/example.gen.go b/_examples/golang-basics/example.gen.go index ec0f14f..632dd51 100644 --- a/_examples/golang-basics/example.gen.go +++ b/_examples/golang-basics/example.gen.go @@ -1,6 +1,6 @@ -// example v0.0.1 8713979f949e7797d4f7506750b6e18f3b9c7c1b +// example v0.0.1 3a3a4087149f1118f0b9494fa254afab46564a1b // -- -// Code generated by webrpc-gen@v0.18.2 with ../../../gen-golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.18.3 with ../../../gen-golang generator. DO NOT EDIT. // // webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -legacyErrors -fixEmptyArrays -out=./example.gen.go package main @@ -33,7 +33,7 @@ func WebRPCSchemaVersion() string { // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "8713979f949e7797d4f7506750b6e18f3b9c7c1b" + return "3a3a4087149f1118f0b9494fa254afab46564a1b" } // @@ -177,6 +177,9 @@ var WebRPCServices = map[string][]string{ type ExampleService interface { Ping(ctx context.Context) error + // Status endpoint + // + // gives you current status of running application Status(ctx context.Context) (bool, error) Version(ctx context.Context) (*Version, error) GetUser(ctx context.Context, header map[string]string, userID uint64) (*User, error) @@ -190,6 +193,9 @@ type ExampleService interface { type ExampleServiceClient interface { Ping(ctx context.Context) error + // Status endpoint + // + // gives you current status of running application Status(ctx context.Context) (bool, error) Version(ctx context.Context) (*Version, error) GetUser(ctx context.Context, header map[string]string, userID uint64) (*User, error) diff --git a/_examples/golang-basics/example.ridl b/_examples/golang-basics/example.ridl index 6c0fdbc..9b9f739 100644 --- a/_examples/golang-basics/example.ridl +++ b/_examples/golang-basics/example.ridl @@ -89,6 +89,9 @@ error 400300 UserNotFound "user not found" service ExampleService - Ping() + # Status endpoint + # + # gives you current status of running application - Status() => (status: bool) - Version() => (version: Version) - GetUser(header: map, userID: uint64) => (user: User) diff --git a/_examples/golang-imports/api.gen.go b/_examples/golang-imports/api.gen.go index ec63284..cd3a6a8 100644 --- a/_examples/golang-imports/api.gen.go +++ b/_examples/golang-imports/api.gen.go @@ -1,6 +1,6 @@ // example-api-service v1.0.0 eb9a5d4082a36a8cb84eaa4b3e1091fc4f1f6f3d // -- -// Code generated by webrpc-gen@v0.18.2 with ../../../gen-golang generator. DO NOT EDIT. +// Code generated by webrpc-gen@v0.18.3 with ../../../gen-golang generator. DO NOT EDIT. // // webrpc-gen -schema=./proto/api.ridl -target=../../../gen-golang -out=./api.gen.go -pkg=main -server -client -legacyErrors=true -fmt=false package main diff --git a/types.go.tmpl b/types.go.tmpl index 9ba6b0a..9b88d38 100644 --- a/types.go.tmpl +++ b/types.go.tmpl @@ -47,6 +47,11 @@ var WebRPCServices = map[string][]string{ {{ if $opts.types -}} type {{$service.Name}} interface { {{- range $_, $method := $service.Methods}} + {{- if gt (len $method.Comments) 0 -}} + {{- range $_, $comment := $method.Comments }} + // {{ replaceAll $comment "\"" "'" }} + {{- end }} + {{- end }} {{ if eq $method.StreamOutput true -}} {{$method.Name}}(ctx context.Context{{range $_, $input := $method.Inputs}}, {{$input.Name}} {{template "field" dict "Name" $input.Name "Type" $input.Type "TypeMap" $typeMap "TypePrefix" $typePrefix "Optional" $input.Optional "TypeMeta" $input.Meta}}{{end}}, stream {{$method.Name}}StreamWriter) error {{- else -}} @@ -144,6 +149,11 @@ func (w *streamWriter) write(respPayload interface{}) error { {{ range $_, $service := $services -}} type {{$service.Name}}Client interface { {{- range $_, $method := $service.Methods}} + {{- if gt (len $method.Comments) 0 }} + {{- range $_, $comment := $method.Comments }} + // {{ replaceAll $comment "\"" "'" }} + {{- end }} + {{- end }} {{ if eq $method.StreamOutput true -}} {{$method.Name}}(ctx context.Context{{range $_, $input := $method.Inputs}}, {{$input.Name}} {{template "field" dict "Name" $input.Name "Type" $input.Type "TypeMap" $typeMap "TypePrefix" $typePrefix "Optional" $input.Optional "TypeMeta" $input.Meta}}{{end}}) ({{$method.Name}}StreamReader, error) {{- else -}}