Generates Typescript helpers for Protobuf APIs conforming to AIP.
go get go.einride.tech/protoc-gen-typescript-aip
Or download a prebuilt binary from releases.
protoc
--typescript-aip_out [OUTPUT DIR] \
[.proto files ...]
plugins:
- name: typescript-aip
out: [OUTPUT DIR]
strategy: all
filename Name of the file to generate the code to.
Default: `index.ts`.
insertion_point If non-empty, indicates that the named file should already exist,
and the content here is to be inserted into that file at a defined
insertion point.
exclude_resource_definitions
If set to true, resource names will not be generated for resource definitions
in the file scope, only on messages. Default: false.
Generates helpers for working with resource names, based on ResourceDescriptor annotations.
A resource annotated with
option (google.api.resource) = {
type: "account-example.einride.tech/User"
pattern: "tenants/{tenant}/users/{user}"
singular: "user"
plural: "users"
};
generates the following API
// Parsing a string:
const name = UserResourceName.parse("tenants/1/users/2")
// Getting variable segments:
console.log(name.tenant); // "1"
console.log(name.user); // "2"
// Getting the string back:
console.log(name.toString()) // "tenants/1/users/2"
// Traversing the resource hierarchy:
const tenant = name.tenantResourceName();
console.log(tenant.toString()) // "tenants/1"
// Constructing the resource name from segments:
const name = UserResourceName.from("tenant", "user")
console.log(name.tenant) // "tenant"
console.log(name.user) // "user"
console.log(name.toString()) // "tenants/tenant/users/user"