Skip to content

Commit

Permalink
calc path in title next to anchorID
Browse files Browse the repository at this point in the history
Fixes hashicorp#285

Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
  • Loading branch information
sebhoss committed Mar 30, 2024
1 parent e3fab9a commit b84169e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
43 changes: 25 additions & 18 deletions schemamd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ var (
)

type nestedType struct {
anchorID string
path []string
block *tfjson.SchemaBlock
object *cty.Type
attrs *tfjson.SchemaNestedAttributeType
anchorID string
pathTitle string
path []string
block *tfjson.SchemaBlock
object *cty.Type
attrs *tfjson.SchemaNestedAttributeType

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

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

nestedTypes = append(nestedTypes, nestedType{
anchorID: anchorID,
path: path,
attrs: att.AttributeNestedType,
anchorID: anchorID,
pathTitle: pathTitle,
path: path,
attrs: att.AttributeNestedType,

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

nestedTypes = append(nestedTypes, nestedType{
anchorID: anchorID,
path: path,
object: &att.AttributeType,
anchorID: anchorID,
pathTitle: pathTitle,
path: path,
object: &att.AttributeType,

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

nt := att.AttributeType.ElementType()
nestedTypes = append(nestedTypes, nestedType{
anchorID: anchorID,
path: path,
object: &nt,
anchorID: anchorID,
pathTitle: pathTitle,
path: path,
object: &nt,

group: group,
})
Expand Down Expand Up @@ -153,10 +158,12 @@ func writeBlockType(w io.Writer, path []string, block *tfjson.SchemaBlockType) (
}

anchorID := "nestedblock--" + strings.Join(path, "--")
pathTitle := strings.Join(path, ".")
nt := nestedType{
anchorID: anchorID,
path: path,
block: block.Block,
anchorID: anchorID,
pathTitle: pathTitle,
path: path,
block: block.Block,
}

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

_, err = io.WriteString(w, "### Nested Schema for `"+strings.Join(nt.path, ".")+"`\n\n")
_, err = io.WriteString(w, "### Nested Schema for `"+nt.pathTitle+"`\n\n")
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions schemamd/testdata/awscc_acmpca_certificate.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Optional:
- `uniform_resource_identifier` (String) String that contains X.509 UniformResourceIdentifier information.

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

Optional:

Expand All @@ -136,7 +136,7 @@ Optional:


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

Required:

Expand All @@ -145,7 +145,7 @@ Required:


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

Required:

Expand Down

0 comments on commit b84169e

Please sign in to comment.