Add package details and atttribution to schema (#4256)

This commit is contained in:
Luke Hoban 2020-04-01 17:22:23 -07:00 committed by GitHub
parent ffdf7355e2
commit a0f615ad09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 4 deletions

View file

@ -128,6 +128,12 @@ type formalParam struct {
DefaultValue string
}
type packageDetails struct {
Repository string
License string
Notes string
}
type resourceDocArgs struct {
Header header
@ -162,6 +168,8 @@ type resourceDocArgs struct {
// NestedTypes is a slice of the nested types used in the input and
// output properties.
NestedTypes []docNestedType
PackageDetails packageDetails
}
type appearsIn struct {
@ -850,6 +858,12 @@ func (mod *modContext) genResource(r *schema.Resource) resourceDocArgs {
}
}
packageDetails := packageDetails{
Repository: mod.pkg.Repository,
License: mod.pkg.License,
Notes: mod.pkg.Attribution,
}
stateParam := name + "State"
data := resourceDocArgs{
Header: header{
@ -868,6 +882,8 @@ func (mod *modContext) genResource(r *schema.Resource) resourceDocArgs {
StateInputs: stateInputs,
StateParam: stateParam,
NestedTypes: mod.genNestedTypes(r, true /*resourceType*/),
PackageDetails: packageDetails,
}
return data
@ -1087,6 +1103,16 @@ func (mod *modContext) genIndex(exports []string) string {
fmt.Fprintf(w, "</ul>\n\n")
}
fmt.Fprintf(w, "<h3>Package Details</h3>\n")
fmt.Fprintf(w, "<dl class=\"package-details\">\n")
fmt.Fprintf(w, " <dt>Repository</dt>\n")
fmt.Fprintf(w, " <dd>%s</dd>\n", mod.pkg.Repository)
fmt.Fprintf(w, " <dt>License</dt>\n")
fmt.Fprintf(w, " <dd>%s</dd>\n", mod.pkg.License)
fmt.Fprintf(w, " <dt>Notes</dt>\n")
fmt.Fprintf(w, " <dd>%s</dd>\n", mod.pkg.Attribution)
fmt.Fprintf(w, "</dl>\n\n")
return w.String()
}

View file

@ -137,3 +137,15 @@ The following state arguments are supported:
{{ end }}
{{ end }}
<h3>Package Details</h3>
<dl class="package-details">
<dt>Repository</dt>
<dd><a href="{{ htmlSafe .PackageDetails.Repository }}">{{ htmlSafe .PackageDetails.Repository }}</a></dd>
<dt>License</dt>
<dd>{{ htmlSafe .PackageDetails.License }}</dd>
{{- if ne .PackageDetails.Notes "" -}}
<dt>Notes</dt>
<dd>{{ htmlSafe .PackageDetails.Notes }}</dd>
{{- end -}}
</dl>

View file

@ -854,7 +854,6 @@ func (pkg *pkgContext) genHeader(w io.Writer, goImports []string, importedPackag
pkgName = path.Base(pkg.mod)
}
fmt.Fprintf(w, "// nolint: lll\n")
fmt.Fprintf(w, "package %s\n\n", pkgName)
var imports []string
@ -1126,13 +1125,13 @@ func GeneratePackage(tool string, pkg *schema.Package) (map[string][]byte, error
switch mod {
case "":
buffer := &bytes.Buffer{}
fmt.Fprintf(buffer, "// Package %[1]s exports types, functions, subpackages for provisioning %[1]s resources.", pkg.pkg.Name)
fmt.Fprintf(buffer, "//\n")
if pkg.pkg.Description != "" {
printComment(buffer, pkg.pkg.Description, false)
fmt.Fprintf(buffer, "//\n")
} else {
fmt.Fprintf(buffer, "// Package %[1]s exports types, functions, subpackages for provisioning %[1]s resources.\n", pkg.pkg.Name)
fmt.Fprintf(buffer, "//\n")
}
fmt.Fprintf(buffer, "// nolint: lll\n")
fmt.Fprintf(buffer, "package %s\n", name)
setFile(path.Join(mod, "doc.go"), buffer.String())

View file

@ -264,6 +264,8 @@ type Package struct {
Homepage string
// License indicates which license is used for the package's contents.
License string
// Attribution allows freeform text attribution of derived work, if needed.
Attribution string
// Repository is the URL at which the source for the package can be found.
Repository string
// LogoURL is the URL for the package's logo, if any.
@ -431,6 +433,8 @@ type PackageSpec struct {
Homepage string `json:"homepage,omitempty"`
// License indicates which license is used for the package's contents.
License string `json:"license,omitempty"`
// Attribution allows freeform text attribution of derived work, if needed.
Attribution string `json:"attribution,omitempty"`
// Repository is the URL at which the source for the package can be found.
Repository string `json:"repository,omitempty"`
// LogoURL is the URL for the package's logo, if any.
@ -530,6 +534,7 @@ func ImportSpec(spec PackageSpec) (*Package, error) {
Keywords: spec.Keywords,
Homepage: spec.Homepage,
License: spec.License,
Attribution: spec.Attribution,
Repository: spec.Repository,
Config: config,
Types: typeList,

View file

@ -167,6 +167,7 @@ github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=