Skip to content

Commit 98fb3b8

Browse files
committed
Config optional based on field behavior annotation
1 parent 72ce714 commit 98fb3b8

File tree

7 files changed

+300
-269
lines changed

7 files changed

+300
-269
lines changed

examples/proto/buf.gen.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ version: v1
33
plugins:
44
- name: typescript-http
55
out: gen/typescript
6+
opt:
7+
- use_required_behavior=true

examples/proto/gen/typescript/einride/example/freight/v1/index.ts

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,50 @@
66
// [site][einride.example.freight.v1.Site].
77
export type Shipment = {
88
// The resource name of the shipment.
9-
name: string | undefined;
9+
name?: string;
1010
// The creation timestamp of the shipment.
1111
//
1212
// Behaviors: OUTPUT_ONLY
13-
createTime: wellKnownTimestamp | undefined;
13+
create_time?: wellKnownTimestamp;
1414
// The last update timestamp of the shipment.
1515
// Updated when create/update/delete operation is shipment.
1616
//
1717
// Behaviors: OUTPUT_ONLY
18-
updateTime: wellKnownTimestamp | undefined;
18+
update_time?: wellKnownTimestamp;
1919
// The deletion timestamp of the shipment.
2020
//
2121
// Behaviors: OUTPUT_ONLY
22-
deleteTime: wellKnownTimestamp | undefined;
22+
delete_time?: wellKnownTimestamp;
2323
// The resource name of the origin site of the shipment.
2424
// Format: shippers/{shipper}/sites/{site}
2525
//
2626
// Behaviors: REQUIRED
27-
originSite: string | undefined;
27+
origin_site: string | undefined;
2828
// The resource name of the destination site of the shipment.
2929
// Format: shippers/{shipper}/sites/{site}
3030
//
3131
// Behaviors: REQUIRED
32-
destinationSite: string | undefined;
32+
destination_site: string | undefined;
3333
// The earliest pickup time of the shipment at the origin site.
3434
//
3535
// Behaviors: REQUIRED
36-
pickupEarliestTime: wellKnownTimestamp | undefined;
36+
pickup_earliest_time: wellKnownTimestamp | undefined;
3737
// The latest pickup time of the shipment at the origin site.
3838
//
3939
// Behaviors: REQUIRED
40-
pickupLatestTime: wellKnownTimestamp | undefined;
40+
pickup_latest_time: wellKnownTimestamp | undefined;
4141
// The earliest delivery time of the shipment at the destination site.
4242
//
4343
// Behaviors: REQUIRED
44-
deliveryEarliestTime: wellKnownTimestamp | undefined;
44+
delivery_earliest_time: wellKnownTimestamp | undefined;
4545
// The latest delivery time of the shipment at the destination site.
4646
//
4747
// Behaviors: REQUIRED
48-
deliveryLatestTime: wellKnownTimestamp | undefined;
48+
delivery_latest_time: wellKnownTimestamp | undefined;
4949
// The line items of the shipment.
50-
lineItems: LineItem[] | undefined;
50+
line_items?: LineItem[];
5151
// Annotations of the shipment.
52-
annotations: { [key: string]: string } | undefined;
52+
annotations?: { [key: string]: string };
5353
};
5454

5555
// Encoded using RFC 3339, where generated output will always be Z-normalized
@@ -60,62 +60,62 @@ type wellKnownTimestamp = string;
6060
// A shipment line item.
6161
export type LineItem = {
6262
// The title of the line item.
63-
title: string | undefined;
63+
title?: string;
6464
// The quantity of the line item.
65-
quantity: number | undefined;
65+
quantity?: number;
6666
// The weight of the line item in kilograms.
67-
weightKg: number | undefined;
67+
weight_kg?: number;
6868
// The volume of the line item in cubic meters.
69-
volumeM3: number | undefined;
69+
volume_m3?: number;
7070
};
7171

7272
// A shipper is a supplier or owner of goods to be transported.
7373
export type Shipper = {
7474
// The resource name of the shipper.
75-
name: string | undefined;
75+
name?: string;
7676
// The creation timestamp of the shipper.
7777
//
7878
// Behaviors: OUTPUT_ONLY
79-
createTime: wellKnownTimestamp | undefined;
79+
create_time?: wellKnownTimestamp;
8080
// The last update timestamp of the shipper.
8181
// Updated when create/update/delete operation is performed.
8282
//
8383
// Behaviors: OUTPUT_ONLY
84-
updateTime: wellKnownTimestamp | undefined;
84+
update_time?: wellKnownTimestamp;
8585
// The deletion timestamp of the shipper.
8686
//
8787
// Behaviors: OUTPUT_ONLY
88-
deleteTime: wellKnownTimestamp | undefined;
88+
delete_time?: wellKnownTimestamp;
8989
// The display name of the shipper.
9090
//
9191
// Behaviors: REQUIRED
92-
displayName: string | undefined;
92+
display_name: string | undefined;
9393
};
9494

9595
// A site is a node in a [shipper][einride.example.freight.v1.Shipper]'s
9696
// transport network.
9797
export type Site = {
9898
// The resource name of the site.
99-
name: string | undefined;
99+
name?: string;
100100
// The creation timestamp of the site.
101101
//
102102
// Behaviors: OUTPUT_ONLY
103-
createTime: wellKnownTimestamp | undefined;
103+
create_time?: wellKnownTimestamp;
104104
// The last update timestamp of the site.
105105
// Updated when create/update/delete operation is performed.
106106
//
107107
// Behaviors: OUTPUT_ONLY
108-
updateTime: wellKnownTimestamp | undefined;
108+
update_time?: wellKnownTimestamp;
109109
// The deletion timestamp of the site.
110110
//
111111
// Behaviors: OUTPUT_ONLY
112-
deleteTime: wellKnownTimestamp | undefined;
112+
delete_time?: wellKnownTimestamp;
113113
// The display name of the site.
114114
//
115115
// Behaviors: REQUIRED
116-
displayName: string | undefined;
116+
display_name: string | undefined;
117117
// The geographic location of the site.
118-
latLng: googletype_LatLng | undefined;
118+
lat_lng?: googletype_LatLng;
119119
};
120120

121121
// An object that represents a latitude/longitude pair. This is expressed as a
@@ -125,9 +125,9 @@ export type Site = {
125125
// standard</a>. Values must be within normalized ranges.
126126
export type googletype_LatLng = {
127127
// The latitude in degrees. It must be in the range [-90.0, +90.0].
128-
latitude: number | undefined;
128+
latitude?: number;
129129
// The longitude in degrees. It must be in the range [-180.0, +180.0].
130-
longitude: number | undefined;
130+
longitude?: number;
131131
};
132132

133133
// Request message for FreightService.GetShipper.
@@ -143,23 +143,23 @@ export type GetShipperRequest = {
143143
export type ListShippersRequest = {
144144
// Requested page size. Server may return fewer shippers than requested.
145145
// If unspecified, server will pick an appropriate default.
146-
pageSize: number | undefined;
146+
page_size?: number;
147147
// A token identifying a page of results the server should return.
148148
// Typically, this is the value of
149149
// [ListShippersResponse.next_page_token][einride.example.freight.v1.ListShippersResponse.next_page_token]
150150
// returned from the previous call to `ListShippers` method.
151-
pageToken: string | undefined;
151+
page_token?: string;
152152
};
153153

154154
// Response message for FreightService.ListShippers.
155155
export type ListShippersResponse = {
156156
// The list of shippers.
157-
shippers: Shipper[] | undefined;
157+
shippers?: Shipper[];
158158
// A token to retrieve next page of results. Pass this value in the
159159
// [ListShippersRequest.page_token][einride.example.freight.v1.ListShippersRequest.page_token]
160160
// field in the subsequent call to `ListShippers` method to retrieve the next
161161
// page of results.
162-
nextPageToken: string | undefined;
162+
next_page_token?: string;
163163
};
164164

165165
// Request message for FreightService.CreateShipper.
@@ -179,7 +179,7 @@ export type UpdateShipperRequest = {
179179
// Behaviors: REQUIRED
180180
shipper: Shipper | undefined;
181181
// The list of fields to be updated.
182-
updateMask: wellKnownFieldMask | undefined;
182+
update_mask?: wellKnownFieldMask;
183183
};
184184

185185
// In JSON, a field mask is encoded as a single string where paths are
@@ -237,23 +237,23 @@ export type ListSitesRequest = {
237237
parent: string | undefined;
238238
// Requested page size. Server may return fewer sites than requested.
239239
// If unspecified, server will pick an appropriate default.
240-
pageSize: number | undefined;
240+
page_size?: number;
241241
// A token identifying a page of results the server should return.
242242
// Typically, this is the value of
243243
// [ListSitesResponse.next_page_token][einride.example.freight.v1.ListSitesResponse.next_page_token]
244244
// returned from the previous call to `ListSites` method.
245-
pageToken: string | undefined;
245+
page_token?: string;
246246
};
247247

248248
// Response message for FreightService.ListSites.
249249
export type ListSitesResponse = {
250250
// The list of sites.
251-
sites: Site[] | undefined;
251+
sites?: Site[];
252252
// A token to retrieve next page of results. Pass this value in the
253253
// [ListSitesRequest.page_token][einride.example.freight.v1.ListSitesRequest.page_token]
254254
// field in the subsequent call to `ListSites` method to retrieve the next
255255
// page of results.
256-
nextPageToken: string | undefined;
256+
next_page_token?: string;
257257
};
258258

259259
// Request message for FreightService.CreateSite.
@@ -278,7 +278,7 @@ export type UpdateSiteRequest = {
278278
// Behaviors: REQUIRED
279279
site: Site | undefined;
280280
// The list of fields to be updated.
281-
updateMask: wellKnownFieldMask | undefined;
281+
update_mask?: wellKnownFieldMask;
282282
};
283283

284284
// Request message for FreightService.DeleteSite.
@@ -308,23 +308,23 @@ export type ListShipmentsRequest = {
308308
parent: string | undefined;
309309
// Requested page size. Server may return fewer shipments than requested.
310310
// If unspecified, server will pick an appropriate default.
311-
pageSize: number | undefined;
311+
page_size?: number;
312312
// A token identifying a page of results the server should return.
313313
// Typically, this is the value of
314314
// [ListShipmentsResponse.next_page_token][einride.example.freight.v1.ListShipmentsResponse.next_page_token]
315315
// returned from the previous call to `ListShipments` method.
316-
pageToken: string | undefined;
316+
page_token?: string;
317317
};
318318

319319
// Response message for FreightService.ListShipments.
320320
export type ListShipmentsResponse = {
321321
// The list of shipments.
322-
shipments: Shipment[] | undefined;
322+
shipments?: Shipment[];
323323
// A token to retrieve next page of results. Pass this value in the
324324
// [ListShipmentsRequest.page_token][einride.example.freight.v1.ListShipmentsRequest.page_token]
325325
// field in the subsequent call to `ListShipments` method to retrieve the next
326326
// page of results.
327-
nextPageToken: string | undefined;
327+
next_page_token?: string;
328328
};
329329

330330
// Request message for FreightService.CreateShipment.
@@ -349,7 +349,7 @@ export type UpdateShipmentRequest = {
349349
// Behaviors: REQUIRED
350350
shipment: Shipment | undefined;
351351
// The list of fields to be updated.
352-
updateMask: wellKnownFieldMask | undefined;
352+
update_mask?: wellKnownFieldMask;
353353
};
354354

355355
// Request message for FreightService.DeleteShipment.
@@ -456,11 +456,11 @@ export function createFreightServiceClient(
456456
const path = `v1/shippers`; // eslint-disable-line quotes
457457
const body = null;
458458
const queryParams: string[] = [];
459-
if (request.pageSize) {
460-
queryParams.push(`pageSize=${encodeURIComponent(request.pageSize.toString())}`)
459+
if (request.page_size) {
460+
queryParams.push(`page_size=${encodeURIComponent(request.page_size.toString())}`)
461461
}
462-
if (request.pageToken) {
463-
queryParams.push(`pageToken=${encodeURIComponent(request.pageToken.toString())}`)
462+
if (request.page_token) {
463+
queryParams.push(`page_token=${encodeURIComponent(request.page_token.toString())}`)
464464
}
465465
let uri = path;
466466
if (queryParams.length > 0) {
@@ -499,8 +499,8 @@ export function createFreightServiceClient(
499499
const path = `v1/${request.shipper.name}`; // eslint-disable-line quotes
500500
const body = JSON.stringify(request?.shipper ?? {});
501501
const queryParams: string[] = [];
502-
if (request.updateMask) {
503-
queryParams.push(`updateMask=${encodeURIComponent(request.updateMask.toString())}`)
502+
if (request.update_mask) {
503+
queryParams.push(`update_mask=${encodeURIComponent(request.update_mask.toString())}`)
504504
}
505505
let uri = path;
506506
if (queryParams.length > 0) {
@@ -562,11 +562,11 @@ export function createFreightServiceClient(
562562
const path = `v1/${request.parent}/sites`; // eslint-disable-line quotes
563563
const body = null;
564564
const queryParams: string[] = [];
565-
if (request.pageSize) {
566-
queryParams.push(`pageSize=${encodeURIComponent(request.pageSize.toString())}`)
565+
if (request.page_size) {
566+
queryParams.push(`page_size=${encodeURIComponent(request.page_size.toString())}`)
567567
}
568-
if (request.pageToken) {
569-
queryParams.push(`pageToken=${encodeURIComponent(request.pageToken.toString())}`)
568+
if (request.page_token) {
569+
queryParams.push(`page_token=${encodeURIComponent(request.page_token.toString())}`)
570570
}
571571
let uri = path;
572572
if (queryParams.length > 0) {
@@ -608,8 +608,8 @@ export function createFreightServiceClient(
608608
const path = `v1/${request.site.name}`; // eslint-disable-line quotes
609609
const body = JSON.stringify(request?.site ?? {});
610610
const queryParams: string[] = [];
611-
if (request.updateMask) {
612-
queryParams.push(`updateMask=${encodeURIComponent(request.updateMask.toString())}`)
611+
if (request.update_mask) {
612+
queryParams.push(`update_mask=${encodeURIComponent(request.update_mask.toString())}`)
613613
}
614614
let uri = path;
615615
if (queryParams.length > 0) {
@@ -671,11 +671,11 @@ export function createFreightServiceClient(
671671
const path = `v1/${request.parent}/shipments`; // eslint-disable-line quotes
672672
const body = null;
673673
const queryParams: string[] = [];
674-
if (request.pageSize) {
675-
queryParams.push(`pageSize=${encodeURIComponent(request.pageSize.toString())}`)
674+
if (request.page_size) {
675+
queryParams.push(`page_size=${encodeURIComponent(request.page_size.toString())}`)
676676
}
677-
if (request.pageToken) {
678-
queryParams.push(`pageToken=${encodeURIComponent(request.pageToken.toString())}`)
677+
if (request.page_token) {
678+
queryParams.push(`page_token=${encodeURIComponent(request.page_token.toString())}`)
679679
}
680680
let uri = path;
681681
if (queryParams.length > 0) {
@@ -717,8 +717,8 @@ export function createFreightServiceClient(
717717
const path = `v1/${request.shipment.name}`; // eslint-disable-line quotes
718718
const body = JSON.stringify(request?.shipment ?? {});
719719
const queryParams: string[] = [];
720-
if (request.updateMask) {
721-
queryParams.push(`updateMask=${encodeURIComponent(request.updateMask.toString())}`)
720+
if (request.update_mask) {
721+
queryParams.push(`update_mask=${encodeURIComponent(request.update_mask.toString())}`)
722722
}
723723
let uri = path;
724724
if (queryParams.length > 0) {

0 commit comments

Comments
 (0)