Skip to content

Commit 6104edc

Browse files
committed
feat: add type alias support
Renders RIDL type aliases as named OpenAPI schema components. Updates go.mod to webrpc v0.36.1 and fixes stream method succinct form compatibility.
1 parent 43d54da commit 6104edc

6 files changed

Lines changed: 15 additions & 50 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- name: Install webrpc-gen
1717
run: |
18-
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.32.3/webrpc-gen.linux-amd64
18+
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.37.0/webrpc-gen.linux-amd64
1919
chmod +x ./webrpc-gen
2020
echo $PWD >> $GITHUB_PATH
2121

_examples/api.ridl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ service ExampleService
3232
- GetComplex() => (complex: ComplexType)
3333
- GetAllOptional() => (optional: Optional)
3434

35-
- StreamUserNotifications() => stream (StreamNotificationsResponse)
36-
3735
service ExampleService2
3836
@deprecated
3937
- Ping()
@@ -64,6 +62,9 @@ error 100 RateLimited "too many requests" HTTP 429
6462
error 101 DatabaseDown "service outage" HTTP 503
6563

6664

65+
type Username: string
66+
type Age: uint32
67+
6768
enum Kind: uint32
6869
- USER
6970
- ADMIN

_examples/openapi.gen.yaml

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# example v1.0.0 78160f3365e4f91df80f171a445efde0a288026e
1+
# example v1.0.0 ceb35c0c54325918ffdd24bf625bb6c8c941f75e
22
# --
3-
# Code generated by webrpc-gen@v0.32.3 with ../ generator; DO NOT EDIT
3+
# Code generated by webrpc-gen@v0.36.1-7-g392437b with ../ generator; DO NOT EDIT
44
#
55
# webrpc-gen -schema=./api.ridl -target=../ -out=./openapi.gen.yaml -title=Example webrpc API -apiVersion=v22.11.8 -serverUrl=https://api.example.com -serverDescription=Production -securityAnnotation=@auth -securitySchemes={ 'ApiKeyAuth': { 'type': 'apiKey', 'in': 'header', 'description': 'Project access key for authenticating requests', 'name': 'X-Access-Key' }, 'ServiceAuth': { 'type': 'apiKey', 'in': 'header', 'description': 'Project access key for authenticating requests', 'name': 'X-Access-Key' } }
66
openapi: 3.0.0
@@ -299,6 +299,12 @@ components:
299299
status:
300300
type: number
301301
example: 503
302+
Username:
303+
type: string
304+
305+
Age:
306+
type: number
307+
302308
Kind:
303309
type: string
304310
description: Represented as uint32 on the server side
@@ -886,50 +892,6 @@ paths:
886892
- $ref: '#/components/schemas/ErrorWebrpcServerPanic'
887893
- $ref: '#/components/schemas/ErrorWebrpcInternalError'
888894
- $ref: '#/components/schemas/ErrorDatabaseDown'
889-
/v1/ExampleService/StreamUserNotifications:
890-
post:
891-
operationId: ExampleService-StreamUserNotifications
892-
tags: ["ExampleService"]
893-
summary: ""
894-
requestBody:
895-
content:
896-
application/json:
897-
schema:
898-
type: object
899-
responses:
900-
'200':
901-
description: OK
902-
content:
903-
application/x-ndjson:
904-
schema:
905-
$ref: '#/components/schemas/StreamNotificationsResponse'
906-
# OpenAPI 3.2.0 streaming (itemSchema) is not supported by 3.1.0 tooling:
907-
# itemSchema:
908-
# $ref: '#/components/schemas/ExampleService_StreamUserNotifications_Response'
909-
'4XX':
910-
description: Client error
911-
content:
912-
application/json:
913-
schema:
914-
oneOf:
915-
- $ref: '#/components/schemas/ErrorWebrpcEndpoint'
916-
- $ref: '#/components/schemas/ErrorWebrpcRequestFailed'
917-
- $ref: '#/components/schemas/ErrorWebrpcBadRoute'
918-
- $ref: '#/components/schemas/ErrorWebrpcBadMethod'
919-
- $ref: '#/components/schemas/ErrorWebrpcBadRequest'
920-
- $ref: '#/components/schemas/ErrorWebrpcClientAborted'
921-
- $ref: '#/components/schemas/ErrorWebrpcStreamLost'
922-
- $ref: '#/components/schemas/ErrorRateLimited'
923-
'5XX':
924-
description: Server error
925-
content:
926-
application/json:
927-
schema:
928-
oneOf:
929-
- $ref: '#/components/schemas/ErrorWebrpcBadResponse'
930-
- $ref: '#/components/schemas/ErrorWebrpcServerPanic'
931-
- $ref: '#/components/schemas/ErrorWebrpcInternalError'
932-
- $ref: '#/components/schemas/ErrorDatabaseDown'
933895
/v1/ExampleService2/Ping:
934896
post:
935897
operationId: ExampleService2-Ping

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/webrpc/gen-openapi
22

3-
go 1.16
3+
go 1.23.12

go.sum

Whitespace-only changes.

type.go.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
{{- range $type.Fields}}
1515
- {{.Name}}
1616
{{- end -}}
17+
{{- else if isAliasType $type}}
18+
{{ template "fieldType" dict "Type" $type.Type "TypeMap" $typeMap "Indent" " " }}
1719
{{else}}
1820
type: object
1921
{{- if gt (len $type.Fields) 0}}

0 commit comments

Comments
 (0)