This protoc plugin generates CUE files.
Complies with protojson.
| Proto Type | CUE Type | Comments |
|---|---|---|
map<K, V> |
{ [string]: V } |
All keys are converted to strings. |
repeated V |
[...V] |
|
bool |
bool |
Use default option for defaults. |
string |
string |
Use default option for defaults. |
bytes |
bytes |
Use default option for defaults. |
int32 |
int32 |
Use default option for defaults. |
fixed32 |
int32 |
Use default option for defaults. |
uint32 |
uint32 |
Use default option for defaults. |
int64 |
int64 |
Use default option for defaults. |
fixed64 |
int64 |
Use default option for defaults. |
uint64 |
uint64 |
Use default option for defaults. |
float |
float32 |
Use default option for defaults. |
double |
float64 |
Use default option for defaults. |
Any |
*null | { "@type": string, ... } |
|
Struct |
*null | { [string]: _ } |
|
Value |
*null | _ |
|
ListValue |
*null | [...] |
|
NullValue |
*null | null |
|
BoolValue |
*null | bool |
|
StringValue |
*null | string |
|
Int32Value |
*null | int32 |
|
UInt32Value |
*null | uint32 |
|
Int64Value |
*null | int64 |
|
UInt64Value |
*null | uint64 |
|
FloatValue |
*null | float32 |
|
DoubleValue |
*null | double |
|
Empty |
*null | close({}) |
|
Timestamp |
*null | string |
See the Timestamp section for more information. |
Duration |
*null | string |
See the Duration section for more information. |
FieldMask |
*null | string |
import "github.com/ornew/protoc-gen-cue/pkg/options/cue.proto";
message Foo {
string name = 1 [(cue.field).expr = '!="xxx"'];
int32 age = 2 [(cue.field).expr = '<100'];
int32 age_next_year = 3 [(cue.field).expr = 'age+1'];
}To:
#Foo: {
name: string
name: !="xxx"
age: int32
age: <100
ageNextYear: int32
ageNextYear: age+1
}You can specify default values using the default field option:
message User {
bool active = 1 [(cue.field).default = "*true"];
int32 age = 2 [(cue.field).default = "*18"];
string role = 3 [(cue.field).default = "*\"user\""];
}To:
#User: {
active: *true | bool
age: *18 | int32
role: *"user" | string
}You can specify a custom CUE import path for your proto files:
option (cue.cue_package) = "example.com/schemas/v1";This allows you to control the CUE import path independently from the Go package path.
enum Bar {
ZERO = 0;
ONE = 1;
}To:
#Bar: *#Bar_ZERO | #Bar_ONE
#Bar_ZERO: "ZERO"
#Bar_ONE: "ONE"message Car {
oneof id {
string product_name = 1;
int32 serial_number = 2;
}
}To:
#Car: {
_oneof_id: productName & serialNumber
productName?: string
serialNumber?: int32
}Currently defined by an unconstrained string. This is due to the fact that CUE's built-in time.Time constraint is incompatible with the JSON format defined in the timestamppb. We plan to fix this issue in a future version to follow the original format. See for more details: time.Time on pkg.go.dev and timestamppb.Timestamp
Currently defined by an unconstrained string. This is due to the fact that CUE's built-in time.Duration constraint is incompatible with the JSON format defined in the durationpb. We plan to fix this issue in a future version to follow the original format. See for more details: time.Duration in pkg.go.dev and descriptorpb.Duration
message Dog {
optional string nick_name = 1;
}To:
#Dog: {
nickName?: string
}