Skip to content

Commit

Permalink
Update v2.2.1 (#14)
Browse files Browse the repository at this point in the history
* UPDATE v2.2.1
  • Loading branch information
fenos authored Jul 18, 2021
1 parent ac1f533 commit 7c4d757
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 14 deletions.
6 changes: 5 additions & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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

Expand All @@ -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

115 changes: 115 additions & 0 deletions example/generated/haberdasher.twirp.yaml
Original file line number Diff line number Diff line change
@@ -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: ""
107 changes: 107 additions & 0 deletions example/generated/haberdasher.yaml
Original file line number Diff line number Diff line change
@@ -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: ""
1 change: 1 addition & 0 deletions example/generated/index.ts
Original file line number Diff line number Diff line change
@@ -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";
30 changes: 24 additions & 6 deletions example/generated/service.twirp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export class HaberdasherClientJSON implements HaberdasherClient {
this.ListHat.bind(this);
}
MakeHat(request: Size): Promise<Hat> {
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",
Expand All @@ -51,7 +54,10 @@ export class HaberdasherClientJSON implements HaberdasherClient {
}

FindHat(request: FindHatRPC): Promise<FindHatRPC> {
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",
Expand All @@ -64,7 +70,10 @@ export class HaberdasherClientJSON implements HaberdasherClient {
}

ListHat(request: ListHatRPC): Promise<ListHatRPC> {
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",
Expand Down Expand Up @@ -279,7 +288,10 @@ async function handleMakeHatJSON<T extends TwirpContext = TwirpContext>(
}

return JSON.stringify(
Hat.toJson(response, { useProtoFieldName: true }) as string
Hat.toJson(response, {
useProtoFieldName: true,
emitDefaultValues: false,
}) as string
);
}

Expand Down Expand Up @@ -314,7 +326,10 @@ async function handleFindHatJSON<T extends TwirpContext = TwirpContext>(
}

return JSON.stringify(
FindHatRPC.toJson(response, { useProtoFieldName: true }) as string
FindHatRPC.toJson(response, {
useProtoFieldName: true,
emitDefaultValues: false,
}) as string
);
}

Expand Down Expand Up @@ -349,7 +364,10 @@ async function handleListHatJSON<T extends TwirpContext = TwirpContext>(
}

return JSON.stringify(
ListHatRPC.toJson(response, { useProtoFieldName: true }) as string
ListHatRPC.toJson(response, {
useProtoFieldName: true,
emitDefaultValues: false,
}) as string
);
}
async function handleMakeHatProtobuf<T extends TwirpContext = TwirpContext>(
Expand Down
14 changes: 10 additions & 4 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 7c4d757

Please sign in to comment.