From 45f202d7bf85d1d7d28a7c4fdcc108caacb1787a Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Wed, 26 Mar 2025 11:00:40 +0100 Subject: [PATCH] Escape quotes & improve endpoint summary/description --- _examples/openapi.gen.yaml | 5 +++-- _examples/proto.ridl | 46 ++++++++++++++++++++------------------ main.go.tmpl | 6 ++--- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/_examples/openapi.gen.yaml b/_examples/openapi.gen.yaml index 20599bc..4e00da3 100644 --- a/_examples/openapi.gen.yaml +++ b/_examples/openapi.gen.yaml @@ -1,4 +1,4 @@ -# example v0.0.1 ee5a444237d744dbda91bc77751f0b0d698e7502 +# example v0.0.1 9814b024890e4f9bf0fb6406686c29bcc402b24a # -- # Code generated by webrpc-gen@v0.25.0 with ../ generator; DO NOT EDIT # @@ -587,7 +587,6 @@ paths: security: - JWT: [] description: | - Replaces GetUser endpoint. requestBody: content: @@ -633,6 +632,8 @@ paths: description: | The filters are q (string) and active (bool). + + The minimal length of the "q" filter is 3 characters. requestBody: content: application/json: diff --git a/_examples/proto.ridl b/_examples/proto.ridl index bf30b9d..cfa34b8 100644 --- a/_examples/proto.ridl +++ b/_examples/proto.ridl @@ -1,7 +1,7 @@ -webrpc = v1 # version of webrpc schema format (ridl or json) +webrpc = v1 # version of webrpc schema format (ridl or json) -name = example # name of your backend app -version = v0.0.1 # version of your schema +name = example # name of your backend app +version = v0.0.1 # version of your schema enum Kind: uint32 - USER @@ -45,35 +45,37 @@ struct Optional - email?: string service ExampleService - @deprecated + @deprecated - Ping() - - @deprecated:"Use GetUserV2 instead." - @auth:JWT + + @deprecated:"Use GetUserV2 instead." + @auth:JWT - GetUser(header: map, userID: uint64) => (code: uint32, user: User) - - # GetUserV2 returns user based on given userID. - # - # Replaces GetUser endpoint. - @auth:JWT + + # GetUserV2 returns user based on given userID. + # Replaces GetUser endpoint. + @auth:JWT - GetUserV2(header: map, userID: uint64) => (code: uint32, user: User, profilePicture: string) - # FindUser searches for a user using the given search filter. - # - # The filters are q (string) and active (bool). - @auth:JWT + # FindUser searches for a user using the given search filter. + # + # The filters are q (string) and active (bool). + # + # The minimal length of the "q" filter is 3 characters. + @auth:JWT - FindUser(s: SearchFilter) => (name: string, user: User) - # ListUsers returns all users. - @auth:JWT + # ListUsers returns all users. + @auth:JWT - ListUsers() => (users: []User) - - GetComplex() => (complex: ComplexType) + - GetComplex() => (complex: ComplexType) - GetAllOptional() => (optional: Optional) service AdminService - @auth:JWT + @auth:JWT - ListUsers() => (users: []User) -error 100 RateLimited "too many requests" HTTP 429 -error 101 DatabaseDown "service outage" HTTP 503 \ No newline at end of file +error 100 RateLimited "too many requests" HTTP 429 +error 101 DatabaseDown "service outage" HTTP 503 + diff --git a/main.go.tmpl b/main.go.tmpl index b359cfa..1485571 100644 --- a/main.go.tmpl +++ b/main.go.tmpl @@ -134,7 +134,7 @@ paths: {{- $deprecated := index $method.Annotations "deprecated" }} /rpc/{{$service.Name}}/{{$method.Name}}: post: - summary: "{{ if $deprecated }}{{ if $deprecated.Value }}Deprecated: {{$deprecated.Value}}{{else}}Deprecated.{{end}}{{else if gt (len $method.Comments) 0}}{{index $method.Comments 0}}{{end}}" + summary: {{ if $deprecated }}{{ if $deprecated.Value }}{{printf "%q" (print "Deprecated: " $deprecated.Value)}}{{else}}"Deprecated."{{end}}{{else if gt (len $method.Comments) 0}}{{printf "%q" (index $method.Comments 0)}}{{else}}""{{end}} {{- if $deprecated }} deprecated: true {{- end }} @@ -151,11 +151,9 @@ paths: {{- end }} {{- if gt (len $method.Comments) 1 }} description: | - {{- range $i, $comment := $method.Comments }} - {{- if gt $i 0 }} + {{- range $i, $comment := (slice $method.Comments 1) }} {{$comment}} {{- end }} - {{- end }} {{- end }} requestBody: content: