Skip to content

Commit

Permalink
Use auth annotations to render security schema in method section
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Oct 7, 2024
1 parent c809810 commit ae2b44e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion _examples/openapi.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# example v0.0.1 ebe5209e9238f02a045c540943d0298b747f5f03
# example v0.0.1 9e3db8dcce83f00fbc6c12b6a2b712b5fdd38874
# --
# Code generated by [email protected] with ../ generator; DO NOT EDIT
#
Expand Down Expand Up @@ -537,6 +537,9 @@ paths:
/rpc/ExampleService/GetUserV2:
post:
summary: GetUserV2
security:
- ApiKeyAuth: []
- ServiceAuth: []
requestBody:
content:
application/json:
Expand Down
1 change: 1 addition & 0 deletions _examples/proto.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct Optional
service ExampleService
@deprecated:GetUserV2
- GetUser(header: map<string,string>, userID: uint64) => (code: uint32, user: User)
@auth:"ApiKeyAuth,ServiceAuth"
- GetUserV2(header: map<string,string>, userID: uint64) => (code: uint32, user: User, profilePicture: string)
- FindUser(s: SearchFilter) => (name: string, user: User)
- ListUsers() => (users: []User)
Expand Down
8 changes: 8 additions & 0 deletions main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ paths:
{{- if (index $method.Annotations "deprecated") }}
deprecated: true
{{- end }}
{{- if (index $method.Annotations "auth") }}
security:
{{- $auth := index $method.Annotations "auth" -}}
{{- $authParts := split "," $auth.Value -}}
{{- range $authParts }}
- {{ . }}: []
{{- end }}
{{- end }}
{{- if gt (len $method.Comments) 0 }}
description: "{{ replaceAll (join $method.Comments "\n") "\"" "'" }}"
{{- end }}
Expand Down

0 comments on commit ae2b44e

Please sign in to comment.