diff --git a/example/Makefile b/example/Makefile index 3b9b69e..238dc74 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,5 +1,5 @@ -PROTOC_GEN_TWIRP_BIN="./../protoc-gen-twirp_ts" +PROTOC_GEN_TWIRP_BIN="./node_modules/.bin/protoc-gen-twirp_ts" PROTOC_GEN_PROTOBUF_TS_BIN="./node_modules/.bin/protoc-gen-ts" PROTOC_GEN_TS_PROTO_BIN="./node_modules/.bin/protoc-gen-ts_proto" @@ -20,6 +20,8 @@ ts-proto: clean --twirp_ts_opt="gateway" \ --twirp_ts_opt="ts_proto" \ --twirp_ts_opt="index_file" \ + --twirp_ts_opt="openapi_twirp" \ + --twirp_ts_opt="openapi_gateway" \ --twirp_ts_out=$(OUT_DIR) \ ./protos/*.proto @@ -33,6 +35,8 @@ protobuf-ts: clean --ts_out=$(OUT_DIR) \ --twirp_ts_opt="gateway" \ --twirp_ts_opt="index_file" \ + --twirp_ts_opt="openapi_twirp" \ + --twirp_ts_opt="openapi_gateway" \ --twirp_ts_out=$(OUT_DIR) \ ./protos/*.proto diff --git a/example/generated/haberdasher.twirp.yaml b/example/generated/haberdasher.twirp.yaml new file mode 100644 index 0000000..f7e89fa --- /dev/null +++ b/example/generated/haberdasher.twirp.yaml @@ -0,0 +1,115 @@ +openapi: 3.0.3 +info: + title: Haberdasher + version: 1.0.0 +paths: + /twirp.example.haberdasher.Haberdasher/MakeHat: + post: + summary: MakeHat produces a hat of mysterious, randomly-selected color! + operationId: Haberdasher_MakeHat + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/Size" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/Hat" + /twirp.example.haberdasher.Haberdasher/FindHat: + post: + summary: "" + operationId: Haberdasher_FindHat + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/FindHatRPC" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/FindHatRPC" + /twirp.example.haberdasher.Haberdasher/ListHat: + post: + summary: "" + operationId: Haberdasher_ListHat + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ListHatRPC" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListHatRPC" +components: + schemas: + Size: + properties: + inches: + type: integer + description: must be > 0 + description: Size of a Hat, in inches. + Hat: + properties: + id: + type: string + description: "" + inches: + type: integer + description: "" + color: + type: string + description: anything but "invisible" + name: + type: string + description: i.e. "bowler" + variants: + type: array + items: + $ref: "#/components/schemas/Hat" + description: "" + description: A Hat is a piece of headwear made by a Haberdasher. + FindHatRPC: + properties: + hat_id: + type: string + description: "" + description: "" + ListHatRPC: + properties: + filters: + type: array + items: + $ref: "#/components/schemas/Filter" + description: "" + description: "" + Filter: + properties: + order_by: + type: string + description: "" + pagination: + $ref: "#/components/schemas/Pagination" + description: "" + Pagination: + properties: + limit: + type: integer + description: "" + offset: + type: integer + description: "" + description: "" diff --git a/example/generated/haberdasher.yaml b/example/generated/haberdasher.yaml new file mode 100644 index 0000000..133fcba --- /dev/null +++ b/example/generated/haberdasher.yaml @@ -0,0 +1,107 @@ +openapi: 3.0.3 +info: + title: Haberdasher + version: 1.0.0 +paths: + /hat: + get: + summary: "" + operationId: Haberdasher_ListHat + parameters: + - name: filters + in: query + schema: + type: array + items: + $ref: "#/components/schemas/Filter" + description: "" + responses: + "200": + description: OK + content: + application/json: + schema: + type: object + properties: + undefined: + $ref: "#/components/schemas/ListHatRPC" + "/hat/{hat_id}": + get: + summary: "" + operationId: Haberdasher_FindHat + parameters: + - name: hat_id + in: path + required: true + schema: + type: string + description: "" + responses: + "200": + description: OK + content: + application/json: + schema: + type: object + properties: + undefined: + $ref: "#/components/schemas/FindHatRPC" +components: + schemas: + Size: + properties: + inches: + type: integer + description: must be > 0 + description: Size of a Hat, in inches. + Hat: + properties: + id: + type: string + description: "" + inches: + type: integer + description: "" + color: + type: string + description: anything but "invisible" + name: + type: string + description: i.e. "bowler" + variants: + type: array + items: + $ref: "#/components/schemas/Hat" + description: "" + description: A Hat is a piece of headwear made by a Haberdasher. + FindHatRPC: + properties: + hat_id: + type: string + description: "" + description: "" + ListHatRPC: + properties: + filters: + type: array + items: + $ref: "#/components/schemas/Filter" + description: "" + description: "" + Filter: + properties: + order_by: + type: string + description: "" + pagination: + $ref: "#/components/schemas/Pagination" + description: "" + Pagination: + properties: + limit: + type: integer + description: "" + offset: + type: integer + description: "" + description: "" diff --git a/example/generated/index.ts b/example/generated/index.ts index e26136a..2a5faca 100644 --- a/example/generated/index.ts +++ b/example/generated/index.ts @@ -1,4 +1,5 @@ export * from "./google/api/http"; export * from "./google/protobuf/descriptor"; export * from "./service"; +export * from "./service.twirp"; export * from "./gateway.twirp"; \ No newline at end of file diff --git a/example/generated/service.twirp.ts b/example/generated/service.twirp.ts index c7cfe7f..ea13b59 100644 --- a/example/generated/service.twirp.ts +++ b/example/generated/service.twirp.ts @@ -38,7 +38,10 @@ export class HaberdasherClientJSON implements HaberdasherClient { this.ListHat.bind(this); } MakeHat(request: Size): Promise { - const data = Size.toJson(request, { useProtoFieldName: true }); + const data = Size.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); const promise = this.rpc.request( "twirp.example.haberdasher.Haberdasher", "MakeHat", @@ -51,7 +54,10 @@ export class HaberdasherClientJSON implements HaberdasherClient { } FindHat(request: FindHatRPC): Promise { - const data = FindHatRPC.toJson(request, { useProtoFieldName: true }); + const data = FindHatRPC.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); const promise = this.rpc.request( "twirp.example.haberdasher.Haberdasher", "FindHat", @@ -64,7 +70,10 @@ export class HaberdasherClientJSON implements HaberdasherClient { } ListHat(request: ListHatRPC): Promise { - const data = ListHatRPC.toJson(request, { useProtoFieldName: true }); + const data = ListHatRPC.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); const promise = this.rpc.request( "twirp.example.haberdasher.Haberdasher", "ListHat", @@ -279,7 +288,10 @@ async function handleMakeHatJSON( } return JSON.stringify( - Hat.toJson(response, { useProtoFieldName: true }) as string + Hat.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string ); } @@ -314,7 +326,10 @@ async function handleFindHatJSON( } return JSON.stringify( - FindHatRPC.toJson(response, { useProtoFieldName: true }) as string + FindHatRPC.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string ); } @@ -349,7 +364,10 @@ async function handleListHatJSON( } return JSON.stringify( - ListHatRPC.toJson(response, { useProtoFieldName: true }) as string + ListHatRPC.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + }) as string ); } async function handleMakeHatProtobuf( diff --git a/example/package-lock.json b/example/package-lock.json index b9914f9..ba8af4e 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -796,14 +796,15 @@ } }, "twirp-ts": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/twirp-ts/-/twirp-ts-2.1.1.tgz", - "integrity": "sha512-+H7kmCd5ZY74folE8o4ebNUd8IxaO/Q4+TCsYTTyKCaFu/zYqUhmUcwbCvntvUnqxfcIYdK4aDGg8Qqs70nyaw==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/twirp-ts/-/twirp-ts-2.2.1.tgz", + "integrity": "sha512-T4T5CrU2yTybEHoAa/pQ6hZMrt8n+ZfE4uQDCyoHGxfGF9XiV1O272nyUj9kbZ1m+YYZVtNoaeeP0VuqmkUIzw==", "requires": { "@protobuf-ts/plugin-framework": "^2.0.0-alpha.27", "dot-object": "^2.1.4", "path-to-regexp": "^6.2.0", - "ts-poet": "^4.5.0" + "ts-poet": "^4.5.0", + "yaml": "^1.10.2" } }, "type-is": { @@ -840,6 +841,11 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, + "yaml": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", + "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==" + }, "yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", diff --git a/example/package.json b/example/package.json index 961e47a..e779812 100644 --- a/example/package.json +++ b/example/package.json @@ -12,7 +12,7 @@ "dependencies": { "axios": "^0.21.1", "express": "^4.17.1", - "twirp-ts": "^2.1.1", + "twirp-ts": "^2.2.1", "@protobuf-ts/plugin": "^2.0.0-alpha.27", "ts-proto": "^1.81.3" }, diff --git a/package-lock.json b/package-lock.json index 922de54..d1e9872 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "twirp-ts", - "version": "2.1.7", + "version": "2.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9c62822..76481c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "twirp-ts", - "version": "2.1.7", + "version": "2.2.1", "description": "Typescript implementation of the Twirp protocol", "main": "build/twirp/index.js", "bin": {