fix: example blocks — jsonencode for json types, TODO instead of hardcoded values, add resource_name
This commit is contained in:
@@ -219,6 +219,7 @@ func exampleBlock(spec types.ServiceSpec, version string, apiEndpoint string) st
|
||||
b.WriteString(fmt.Sprintf(" api_endpoint = \"%s\"\n", apiEndpoint))
|
||||
b.WriteString("}\n")
|
||||
b.WriteString(fmt.Sprintf("resource \"nubes_%s\" \"baza\" {\n", spec.Name))
|
||||
b.WriteString(" resource_name = \"TODO\"\n\n")
|
||||
|
||||
for _, p := range requiredParams {
|
||||
b.WriteString(formatParamOrBlock(p, " ", true))
|
||||
@@ -555,6 +556,9 @@ func formatParamLine(p types.ParamSpec, indent string, requiredOnly bool) string
|
||||
return ""
|
||||
}
|
||||
value := sampleValue(p)
|
||||
if isJsonType(p) {
|
||||
value = fmt.Sprintf("jsonencode(%s)", value)
|
||||
}
|
||||
comment := strings.TrimSpace(stripHTML(p.Descr))
|
||||
if comment == "" {
|
||||
comment = strings.TrimSpace(stripHTML(p.Man))
|
||||
@@ -578,6 +582,9 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str
|
||||
b.WriteString(fmt.Sprintf("%s%s {\n", indent, paramCode))
|
||||
for _, sp := range p.SubParams {
|
||||
spVal := sampleValue(sp)
|
||||
if isJsonType(sp) {
|
||||
spVal = fmt.Sprintf("jsonencode(%s)", spVal)
|
||||
}
|
||||
spCode := ToSnake(sp.Code)
|
||||
spComment := strings.TrimSpace(stripHTML(sp.Descr))
|
||||
if spComment == "" {
|
||||
@@ -600,6 +607,9 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str
|
||||
b.WriteString(fmt.Sprintf("%s # Каждый элемент массива — объект с полями:\n", indent))
|
||||
for _, sp := range p.SubParams {
|
||||
spVal := sampleValue(sp)
|
||||
if isJsonType(sp) {
|
||||
spVal = fmt.Sprintf("jsonencode(%s)", spVal)
|
||||
}
|
||||
spCode := ToSnake(sp.Code)
|
||||
spComment := strings.TrimSpace(stripHTML(sp.Descr))
|
||||
if spComment == "" {
|
||||
@@ -622,7 +632,7 @@ func sampleValue(p types.ParamSpec) string {
|
||||
return formatLiteral(p.Default)
|
||||
}
|
||||
if len(p.ValueList) > 0 {
|
||||
return formatLiteral(p.ValueList[0])
|
||||
return "\"TODO\""
|
||||
}
|
||||
dtype := strings.ToLower(firstType(p))
|
||||
switch {
|
||||
@@ -713,6 +723,10 @@ func normalizeType(dtype string) string {
|
||||
return strings.TrimSpace(cleaned)
|
||||
}
|
||||
|
||||
func isJsonType(p types.ParamSpec) bool {
|
||||
return strings.Contains(strings.ToLower(firstType(p)), "json")
|
||||
}
|
||||
|
||||
func defaultCell(value interface{}) string {
|
||||
if !hasDefault(value) {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user