Skip to content

Commit 9dce5a8

Browse files
committed
calc path in title next to anchorID
Fixes #285 Signed-off-by: Sebastian Hoß <[email protected]>
1 parent e7e94b3 commit 9dce5a8

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

schemamd/render.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ var (
5757
)
5858

5959
type nestedType struct {
60-
anchorID string
61-
path []string
62-
block *tfjson.SchemaBlock
63-
object *cty.Type
64-
attrs *tfjson.SchemaNestedAttributeType
60+
anchorID string
61+
pathTitle string
62+
path []string
63+
block *tfjson.SchemaBlock
64+
object *cty.Type
65+
attrs *tfjson.SchemaNestedAttributeType
6566

6667
group groupFilter
6768
}
@@ -87,6 +88,7 @@ func writeAttribute(w io.Writer, path []string, att *tfjson.SchemaAttribute, gro
8788
}
8889

8990
anchorID := "nestedatt--" + strings.Join(path, "--")
91+
pathTitle := strings.Join(path, ".")
9092
nestedTypes := []nestedType{}
9193
switch {
9294
case att.AttributeNestedType != nil:
@@ -96,9 +98,10 @@ func writeAttribute(w io.Writer, path []string, att *tfjson.SchemaAttribute, gro
9698
}
9799

98100
nestedTypes = append(nestedTypes, nestedType{
99-
anchorID: anchorID,
100-
path: path,
101-
attrs: att.AttributeNestedType,
101+
anchorID: anchorID,
102+
pathTitle: pathTitle,
103+
path: path,
104+
attrs: att.AttributeNestedType,
102105

103106
group: group,
104107
})
@@ -109,9 +112,10 @@ func writeAttribute(w io.Writer, path []string, att *tfjson.SchemaAttribute, gro
109112
}
110113

111114
nestedTypes = append(nestedTypes, nestedType{
112-
anchorID: anchorID,
113-
path: path,
114-
object: &att.AttributeType,
115+
anchorID: anchorID,
116+
pathTitle: pathTitle,
117+
path: path,
118+
object: &att.AttributeType,
115119

116120
group: group,
117121
})
@@ -123,9 +127,10 @@ func writeAttribute(w io.Writer, path []string, att *tfjson.SchemaAttribute, gro
123127

124128
nt := att.AttributeType.ElementType()
125129
nestedTypes = append(nestedTypes, nestedType{
126-
anchorID: anchorID,
127-
path: path,
128-
object: &nt,
130+
anchorID: anchorID,
131+
pathTitle: pathTitle,
132+
path: path,
133+
object: &nt,
129134

130135
group: group,
131136
})
@@ -153,10 +158,12 @@ func writeBlockType(w io.Writer, path []string, block *tfjson.SchemaBlockType) (
153158
}
154159

155160
anchorID := "nestedblock--" + strings.Join(path, "--")
161+
pathTitle := strings.Join(path, ".")
156162
nt := nestedType{
157-
anchorID: anchorID,
158-
path: path,
159-
block: block.Block,
163+
anchorID: anchorID,
164+
pathTitle: pathTitle,
165+
path: path,
166+
block: block.Block,
160167
}
161168

162169
_, err = io.WriteString(w, " (see [below for nested schema](#"+anchorID+"))")
@@ -344,7 +351,7 @@ func writeNestedTypes(w io.Writer, nestedTypes []nestedType) error {
344351
return err
345352
}
346353

347-
_, err = io.WriteString(w, "### Nested Schema for `"+strings.Join(nt.path, ".")+"`\n\n")
354+
_, err = io.WriteString(w, "### Nested Schema for `"+nt.pathTitle+"`\n\n")
348355
if err != nil {
349356
return err
350357
}

schemamd/testdata/awscc_acmpca_certificate.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Optional:
115115
- `uniform_resource_identifier` (String) String that contains X.509 UniformResourceIdentifier information.
116116

117117
<a id="nestedatt--api_passthrough--extensions--subject_alternative_names--directory_name"></a>
118-
### Nested Schema for `api_passthrough.extensions.subject_alternative_names.uniform_resource_identifier`
118+
### Nested Schema for `api_passthrough.extensions.subject_alternative_names.directory_name`
119119

120120
Optional:
121121

@@ -136,7 +136,7 @@ Optional:
136136

137137

138138
<a id="nestedatt--api_passthrough--extensions--subject_alternative_names--edi_party_name"></a>
139-
### Nested Schema for `api_passthrough.extensions.subject_alternative_names.uniform_resource_identifier`
139+
### Nested Schema for `api_passthrough.extensions.subject_alternative_names.edi_party_name`
140140

141141
Required:
142142

@@ -145,7 +145,7 @@ Required:
145145

146146

147147
<a id="nestedatt--api_passthrough--extensions--subject_alternative_names--other_name"></a>
148-
### Nested Schema for `api_passthrough.extensions.subject_alternative_names.uniform_resource_identifier`
148+
### Nested Schema for `api_passthrough.extensions.subject_alternative_names.other_name`
149149

150150
Required:
151151

0 commit comments

Comments
 (0)