Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort attribute and nested block in schema order by name #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions schemamd/render.go
Expand Up @@ -201,19 +201,22 @@ func writeRootBlock(w io.Writer, block *tfjson.SchemaBlock) error {
// "description_kind": "plain"
// },
func writeBlockChildren(w io.Writer, parents []string, block *tfjson.SchemaBlock, root bool) error {
names := []string{}
var attributeNames, nestedBlockNames []string
for n := range block.Attributes {
names = append(names, n)
attributeNames = append(attributeNames, n)
}
sort.Slice(attributeNames, func(i, j int) bool { return attributeNames[i] < attributeNames[j] })

for n := range block.NestedBlocks {
names = append(names, n)
nestedBlockNames = append(nestedBlockNames, n)
}
sort.Slice(nestedBlockNames, func(i, j int) bool { return nestedBlockNames[i] < nestedBlockNames[j] })

groups := map[int][]string{}

// Group Attributes/Blocks by characteristics.
nameLoop:
for _, n := range names {
for _, n := range append(attributeNames, nestedBlockNames...) {
if childBlock, ok := block.NestedBlocks[n]; ok {
for i, gf := range groupFilters {
if gf.filterBlock(childBlock) {
Expand Down