mirror of https://github.com/kubevela/kubevela.git
* Fix: make any as top value in cue Signed-off-by: iyear <ljyngup@gmail.com> * Feat: support different cue special type in type option Signed-off-by: iyear <ljyngup@gmail.com> * Fix: unit test type option Signed-off-by: iyear <ljyngup@gmail.com> --------- Signed-off-by: iyear <ljyngup@gmail.com> |
||
|---|---|---|
| .. | ||
| testdata | ||
| README.md | ||
| convert.go | ||
| convert_test.go | ||
| generator.go | ||
| generator_test.go | ||
| option.go | ||
| option_test.go | ||
| tag.go | ||
| tag_test.go | ||
| util.go | ||
| util_test.go | ||
README.md
CUE Generator
Auto generation of CUE schema and docs from Go struct
Type Conversion
- All comments will be copied to CUE schema
Basic Types
| Go Type | CUE Type |
|---|---|
int |
int |
int8 |
int8 |
int16 |
int16 |
int32 |
int32 |
int64 |
int64 |
uint |
uint |
uint8 |
uint8 |
uint16 |
uint16 |
uint32 |
uint32 |
uint64 |
uint64 |
float32 |
float32 |
float64 |
float64 |
string |
string |
bool |
bool |
nil |
null |
byte |
uint8 |
uintptr |
uint64 |
[]byte |
bytes |
interface{}/any |
_ |
Map Type
- CUE only supports
map[string]Ttype, which is converted to[string]: Tin CUE schema - All
map[string]any/map[string]interface{}are converted to{...}in CUE schema
Struct Type
- Fields will be expanded recursively in CUE schema
- All unexported fields will be ignored
- Do not support recursive struct type, which will cause infinite loop
json Tag:
- Fields with
json:"FIELD_NAME"tag will be renamed toFIELD_NAMEin CUE schema, otherwise the field name will be used - Fields with
json:"-"tag will be ignored in generation - Anonymous fields with
json:",inline"tag will be expanded inlined in CUE schema - Fields with
json:",omitempty"tag will be marked as optional in CUE schema
cue Tag:
- Format:
cue:"key1:value1;key2:value2;boolValue1;boolValue2" - Fields with
cue:"enum:VALUE1,VALUE2"tag will be set with enum valuesVALUE1andVALUE2in CUE schema - Fields with
cue:"default:VALUE"tag will be set with default valueVALUEin CUE schema, andVALUEmust be one of go basic types, includingint,float,string,bool - Separators
';',':'and','can be escaped with'\', e.g.cue:"default:va\\;lue\\:;enum:e\\;num1,e\\:num2\\,enum3"will be parsed asDefault: "va;lue:", Enum: []string{"e;num1", "e:num2,enum3"}}