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