Inject id resource output property in docs (#4443)

All resources have an implicit `id` output property that must be injected in docs.
This commit is contained in:
Justin Van Patten 2020-04-18 14:17:08 -07:00 committed by GitHub
parent a5a6863f57
commit 5328b6801f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 12 deletions

View file

@ -819,9 +819,15 @@ func (mod *modContext) getProperties(properties []*schema.Property, lang string,
})
}
// Sort required props to move them to the top of the properties list.
// Sort required props to move them to the top of the properties list, then by name.
sort.SliceStable(docProperties, func(i, j int) bool {
return docProperties[i].IsRequired && !docProperties[j].IsRequired
pi, pj := docProperties[i], docProperties[j]
switch {
case pi.IsRequired != pj.IsRequired:
return pi.IsRequired && !pj.IsRequired
default:
return pi.Name < pj.Name
}
})
return docProperties
@ -1145,15 +1151,21 @@ func (mod *modContext) genResource(r *schema.Resource) resourceDocArgs {
if !r.IsProvider {
filteredOutputProps = filterOutputProperties(r.InputProperties, r.Properties)
}
hasFilteredOutputProps := len(filteredOutputProps) > 0
// All resources have an implicit `id` output property, that we must inject into the docs.
filteredOutputProps = append(filteredOutputProps, &schema.Property{
Name: "id",
Comment: "The provider-assigned unique ID for this managed resource.",
Type: schema.StringType,
IsRequired: true,
})
for _, lang := range supportedLanguages {
inputProps[lang] = mod.getProperties(r.InputProperties, lang, true, false)
outputProps[lang] = mod.getProperties(filteredOutputProps, lang, false, false)
if r.IsProvider {
continue
}
if hasFilteredOutputProps {
outputProps[lang] = mod.getProperties(filteredOutputProps, lang, false, false)
}
if r.StateInputs != nil {
stateInputs[lang] = mod.getProperties(r.StateInputs.Properties, lang, true, false)
}

View file

@ -86,15 +86,10 @@ The {{ .Header.Title }} resource accepts the following [input]({{ htmlSafe "{{<
<!-- Output properties -->
### Outputs
{{ if ne (len .OutputProperties) 0 }}
All [input](#inputs) properties are implicitly available as output properties. Additionally, the {{ .Header.Title }} resource produces the following computed outputs.
The following output properties are available:
All [input](#inputs) properties are implicitly available as output properties. Additionally, the {{ .Header.Title }} resource produces the following output properties:
{{ template "properties" .OutputProperties }}
{{ else }}
All [input](#inputs) properties are implicitly available as output properties. The {{ .Header.Title }} resource does not produce any additional output properties.
{{ end }}
<!-- Read resource -->
{{ if ne (len .StateInputs) 0 }}