Skip to content

Commit

Permalink
fix: order of anchors of nested attributes (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariux authored Dec 29, 2021
1 parent 41d2ff8 commit 9b95fbb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/renderers/markdown/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (mw *markdownWriter) writeAttribute(attribute entities.Attribute, parentNam
return err
}

nestedParentName := fmt.Sprintf("%s-%s", attribute.Name, parentName)
nestedParentName := fmt.Sprintf("%s-%s", parentName, attribute.Name)

return mw.writeAttributes(attribute.Attributes, nestedParentName)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/renderers/markdown/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestWriteAttribute(t *testing.T) {
Required: true,
},
want: mdAttribute{
item: " - [**`string_attribute`**](#attr-string_attribute-parent_var_name): *(**Required** `string`, Forces new resource)*<a name=\"attr-string_attribute-parent_var_name\"></a>",
item: " - [**`string_attribute`**](#attr-parent_var_name-string_attribute): *(**Required** `string`, Forces new resource)*<a name=\"attr-parent_var_name-string_attribute\"></a>",
description: " i am this attribute's description",
},
},
Expand All @@ -184,7 +184,7 @@ func TestWriteAttribute(t *testing.T) {
Required: false,
},
want: mdAttribute{
item: " - [**`number_attribute`**](#attr-number_attribute-parent_var_name): *(Optional `number`, Forces new resource)*<a name=\"attr-number_attribute-parent_var_name\"></a>",
item: " - [**`number_attribute`**](#attr-parent_var_name-number_attribute): *(Optional `number`, Forces new resource)*<a name=\"attr-parent_var_name-number_attribute\"></a>",
},
},
{
Expand All @@ -199,7 +199,7 @@ func TestWriteAttribute(t *testing.T) {
Required: false,
},
want: mdAttribute{
item: "- [**`bool_attribute`**](#attr-bool_attribute-parent_var_name): *(Optional `bool`)*<a name=\"attr-bool_attribute-parent_var_name\"></a>",
item: "- [**`bool_attribute`**](#attr-parent_var_name-bool_attribute): *(Optional `bool`)*<a name=\"attr-parent_var_name-bool_attribute\"></a>",
},
},
{
Expand All @@ -213,7 +213,7 @@ func TestWriteAttribute(t *testing.T) {
Default: []byte("123"),
},
want: mdAttribute{
item: " - [**`i_have_a_default`**](#attr-i_have_a_default-parent_var_name): *(Optional `number`)*<a name=\"attr-i_have_a_default-parent_var_name\"></a>",
item: " - [**`i_have_a_default`**](#attr-parent_var_name-i_have_a_default): *(Optional `number`)*<a name=\"attr-parent_var_name-i_have_a_default\"></a>",
description: " Default is `123`.",
},
},
Expand Down
2 changes: 1 addition & 1 deletion templates/markdown/attribute.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{define "attribute"}}{{indent (multiply .Level 2) "-"}} [**`{{.Name}}`**](#attr-{{.Name}}-{{.ParentName}}): *({{if .Required}}**Required**{{else}}Optional{{end}} `{{template "variableType" .Type}}`{{if .ForcesRecreation}}, Forces new resource{{end}})*<a name="attr-{{.Name}}-{{.ParentName}}"></a>
{{define "attribute"}}{{indent (multiply .Level 2) "-"}} [**`{{.Name}}`**](#attr-{{.ParentName}}-{{.Name}}): *({{if .Required}}**Required**{{else}}Optional{{end}} `{{template "variableType" .Type}}`{{if .ForcesRecreation}}, Forces new resource{{end}})*<a name="attr-{{.ParentName}}-{{.Name}}"></a>

{{- if .Description}}{{- newline}}{{indent (getIndent .Level) .Description}}{{end}}

Expand Down
12 changes: 6 additions & 6 deletions test/testdata/golden-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ See [variables.tf] and [examples/] for details and use-cases.

Each `policy_bindings` object in the list accepts the following attributes:

- [**`role`**](#attr-role-policy_bindings): *(**Required** `string`)*<a name="attr-role-policy_bindings"></a>
- [**`role`**](#attr-policy_bindings-role): *(**Required** `string`)*<a name="attr-policy_bindings-role"></a>

The role that should be applied.

- [**`members`**](#attr-members-policy_bindings): *(Optional `set(string)`)*<a name="attr-members-policy_bindings"></a>
- [**`members`**](#attr-policy_bindings-members): *(Optional `set(string)`)*<a name="attr-policy_bindings-members"></a>

Identities that will be granted the privilege in `role`.

Default is `var.members`.

- [**`condition`**](#attr-condition-policy_bindings): *(Optional `object(condition)`)*<a name="attr-condition-policy_bindings"></a>
- [**`condition`**](#attr-policy_bindings-condition): *(Optional `object(condition)`)*<a name="attr-policy_bindings-condition"></a>

An IAM Condition for a given binding.

Expand All @@ -158,15 +158,15 @@ See [variables.tf] and [examples/] for details and use-cases.
The `condition` object accepts the following attributes:
- [**`expression`**](#attr-expression-condition-policy_bindings): *(**Required** `string`)*<a name="attr-expression-condition-policy_bindings"></a>
- [**`expression`**](#attr-policy_bindings-condition-expression): *(**Required** `string`)*<a name="attr-policy_bindings-condition-expression"></a>
Textual representation of an expression in Common Expression Language syntax.
- [**`title`**](#attr-title-condition-policy_bindings): *(**Required** `string`)*<a name="attr-title-condition-policy_bindings"></a>
- [**`title`**](#attr-policy_bindings-condition-title): *(**Required** `string`)*<a name="attr-policy_bindings-condition-title"></a>
A title for the expression, i.e. a short string describing its purpose.
- [**`description`**](#attr-description-condition-policy_bindings): *(Optional `string`)*<a name="attr-description-condition-policy_bindings"></a>
- [**`description`**](#attr-policy_bindings-condition-description): *(Optional `string`)*<a name="attr-policy_bindings-condition-description"></a>
An optional description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI.
Expand Down
6 changes: 3 additions & 3 deletions test/testdata/markdown-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ We can add infinite subsections!

Each `test_object` object in the list accepts the following attributes:

- [**`name`**](#attr-name-test_objects): *(Optional `string`)*<a name="attr-name-test_objects"></a>
- [**`name`**](#attr-test_objects-name): *(Optional `string`)*<a name="attr-test_objects-name"></a>

A string

- [**`something_complex`**](#attr-something_complex-test_objects): *(Optional `object(nested_object)`)*<a name="attr-something_complex-test_objects"></a>
- [**`something_complex`**](#attr-test_objects-something_complex): *(Optional `object(nested_object)`)*<a name="attr-test_objects-something_complex"></a>

Some other object

The `nested_object` object accepts the following attributes:

- [**`nested_string`**](#attr-nested_string-something_complex-test_objects): *(Optional `string`)*<a name="attr-nested_string-something_complex-test_objects"></a>
- [**`nested_string`**](#attr-test_objects-something_complex-nested_string): *(Optional `string`)*<a name="attr-test_objects-something_complex-nested_string"></a>

a nested string

0 comments on commit 9b95fbb

Please sign in to comment.