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
Place default ID attribute in Read Only group #46
Changes from 2 commits
e6cc7a3
40b0963
96fb961
5e66e53
af5eaa6
3ad1834
9ee2af1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ func Render(schema *tfjson.Schema, w io.Writer) error { | |
} | ||
|
||
type groupFilter struct { | ||
name string | ||
topLevelTitle string | ||
nestedTitle string | ||
|
||
|
@@ -34,9 +35,9 @@ type groupFilter struct { | |
|
||
var ( | ||
groupFilters = []groupFilter{ | ||
{"### Required", "Required:", childIsRequired}, | ||
{"### Optional", "Optional:", childIsOptional}, | ||
{"### Read-Only", "Read-Only:", childIsReadOnly}, | ||
{"Required", "### Required", "Required:", childIsRequired}, | ||
{"Optional", "### Optional", "Optional:", childIsOptional}, | ||
{"Read Only", "### Read-Only", "Read-Only:", childIsReadOnly}, | ||
} | ||
) | ||
|
||
|
@@ -57,10 +58,6 @@ func writeAttribute(w io.Writer, path []string, att *tfjson.SchemaAttribute, gro | |
return nil, err | ||
} | ||
|
||
if name == "id" && att.Description == "" { | ||
att.Description = "The ID of this resource." | ||
} | ||
|
||
err = WriteAttributeDescription(w, att, false) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -161,7 +158,13 @@ func writeBlockChildren(w io.Writer, parents []string, block *tfjson.SchemaBlock | |
childBlock := block.NestedBlocks[n] | ||
childAtt := block.Attributes[n] | ||
for i, gf := range groupFilters { | ||
if gf.filter(childBlock, childAtt) { | ||
if n == "id" && childAtt.Description == "" { | ||
if gf.name == "Read Only" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of creating a new field There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the current implementation to check this. I think my original rationale was trying to give it an enum style ID that could be referenced (in case it needed to be for any other purposes) But I'm totally fine just checking against an existing field. |
||
childAtt.Description = "The ID of this resource." | ||
groups[i] = append(groups[i], n) | ||
goto NextName | ||
} | ||
} else if gf.filter(childBlock, childAtt) { | ||
groups[i] = append(groups[i], n) | ||
goto NextName | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd do a lowercase comparison with
id
, just to stay on the safe side