diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d3a432..2a5ac3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - name: Install webrpc-gen run: | - curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.32.3/webrpc-gen.linux-amd64 + curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.37.0/webrpc-gen.linux-amd64 chmod +x ./webrpc-gen echo $PWD >> $GITHUB_PATH diff --git a/.github/workflows/notify-main.yml b/.github/workflows/notify-main.yml new file mode 100644 index 0000000..1d65bd1 --- /dev/null +++ b/.github/workflows/notify-main.yml @@ -0,0 +1,18 @@ +name: Notify main repo + +on: + push: + tags: + - "v*" + +jobs: + notify: + runs-on: ubuntu-latest + steps: + - name: Dispatch to webrpc/webrpc + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.GH_TOKEN_GIT_COMMIT }} + repository: webrpc/webrpc + event-type: generator-updated + client-payload: '{"generator": "gen-openapi", "version": "${{ github.ref_name }}"}' diff --git a/_examples/api.ridl b/_examples/api.ridl index 0ce6a61..14dfe86 100644 --- a/_examples/api.ridl +++ b/_examples/api.ridl @@ -32,8 +32,6 @@ service ExampleService - GetComplex() => (complex: ComplexType) - GetAllOptional() => (optional: Optional) - - StreamUserNotifications() => stream (StreamNotificationsResponse) - service ExampleService2 @deprecated - Ping() @@ -64,6 +62,9 @@ error 100 RateLimited "too many requests" HTTP 429 error 101 DatabaseDown "service outage" HTTP 503 +type Username: string +type Age: uint32 + enum Kind: uint32 - USER - ADMIN diff --git a/_examples/openapi.gen.yaml b/_examples/openapi.gen.yaml index 88e5fec..39914ab 100644 --- a/_examples/openapi.gen.yaml +++ b/_examples/openapi.gen.yaml @@ -1,6 +1,6 @@ -# example v1.0.0 78160f3365e4f91df80f171a445efde0a288026e +# example v1.0.0 ceb35c0c54325918ffdd24bf625bb6c8c941f75e # -- -# Code generated by webrpc-gen@v0.32.3 with ../ generator; DO NOT EDIT +# Code generated by webrpc-gen@v0.37.0 with ../ generator; DO NOT EDIT # # 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' } } openapi: 3.0.0 @@ -299,6 +299,12 @@ components: status: type: number example: 503 + Username: + type: string + + Age: + type: number + Kind: type: string description: Represented as uint32 on the server side @@ -886,50 +892,6 @@ paths: - $ref: '#/components/schemas/ErrorWebrpcServerPanic' - $ref: '#/components/schemas/ErrorWebrpcInternalError' - $ref: '#/components/schemas/ErrorDatabaseDown' - /v1/ExampleService/StreamUserNotifications: - post: - operationId: ExampleService-StreamUserNotifications - tags: ["ExampleService"] - summary: "" - requestBody: - content: - application/json: - schema: - type: object - responses: - '200': - description: OK - content: - application/x-ndjson: - schema: - $ref: '#/components/schemas/StreamNotificationsResponse' - # OpenAPI 3.2.0 streaming (itemSchema) is not supported by 3.1.0 tooling: - # itemSchema: - # $ref: '#/components/schemas/ExampleService_StreamUserNotifications_Response' - '4XX': - description: Client error - content: - application/json: - schema: - oneOf: - - $ref: '#/components/schemas/ErrorWebrpcEndpoint' - - $ref: '#/components/schemas/ErrorWebrpcRequestFailed' - - $ref: '#/components/schemas/ErrorWebrpcBadRoute' - - $ref: '#/components/schemas/ErrorWebrpcBadMethod' - - $ref: '#/components/schemas/ErrorWebrpcBadRequest' - - $ref: '#/components/schemas/ErrorWebrpcClientAborted' - - $ref: '#/components/schemas/ErrorWebrpcStreamLost' - - $ref: '#/components/schemas/ErrorRateLimited' - '5XX': - description: Server error - content: - application/json: - schema: - oneOf: - - $ref: '#/components/schemas/ErrorWebrpcBadResponse' - - $ref: '#/components/schemas/ErrorWebrpcServerPanic' - - $ref: '#/components/schemas/ErrorWebrpcInternalError' - - $ref: '#/components/schemas/ErrorDatabaseDown' /v1/ExampleService2/Ping: post: operationId: ExampleService2-Ping diff --git a/go.mod b/go.mod index 1a4975d..30763f4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/webrpc/gen-openapi -go 1.16 +go 1.23.12 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/type.go.tmpl b/type.go.tmpl index 030d2aa..38d5ab9 100644 --- a/type.go.tmpl +++ b/type.go.tmpl @@ -14,6 +14,8 @@ {{- range $type.Fields}} - {{.Name}} {{- end -}} + {{- else if isAliasType $type}} + {{ template "fieldType" dict "Type" $type.Type "TypeMap" $typeMap "Indent" " " }} {{else}} type: object {{- if gt (len $type.Fields) 0}}