private/apigen: Don't print empty description & version in docs
If the API description or version is empty, don't print out in the docs
a placeholder for them.
In commit bcde51138d
a space between the
placeholder and description was removed because it was printing a
trailing space if the description was empty, but that introduced another
bug, which is not adding the space when the description is empty.
This commit fixes the bug, no printing the placeholder if the
description is empty, otherwise print it with the corresponding blank
space in between the placeholder and the description.
Change-Id: I19c92c3dd7dfb38b8b2a43821bafc726ffad59d7
This commit is contained in:
parent
4620d6d4cc
commit
269dd5602e
@ -35,14 +35,19 @@ func (api *API) generateDocumentation() string {
|
||||
wf := func(format string, args ...any) { _, _ = fmt.Fprintf(&doc, format, args...) }
|
||||
|
||||
wf("# API Docs\n\n")
|
||||
wf("**Description:**%s\n\n", api.Description)
|
||||
wf("**Version:** `%s`\n\n", api.Version)
|
||||
if api.Description != "" {
|
||||
wf("**Description:** %s\n\n", api.Description)
|
||||
}
|
||||
|
||||
if api.Version != "" {
|
||||
wf("**Version:** `%s`\n\n", api.Version)
|
||||
}
|
||||
|
||||
wf("<h2 id='list-of-endpoints'>List of Endpoints</h2>\n\n")
|
||||
getEndpointLink := func(group, endpoint string) string {
|
||||
fullName := group + "-" + endpoint
|
||||
fullName = strings.ReplaceAll(fullName, " ", "-")
|
||||
var nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9-]+`)
|
||||
nonAlphanumericRegex := regexp.MustCompile(`[^a-zA-Z0-9-]+`)
|
||||
fullName = nonAlphanumericRegex.ReplaceAllString(fullName, "")
|
||||
return strings.ToLower(fullName)
|
||||
}
|
||||
@ -56,7 +61,11 @@ func (api *API) generateDocumentation() string {
|
||||
|
||||
for _, group := range api.EndpointGroups {
|
||||
for _, endpoint := range group.endpoints {
|
||||
wf("<h3 id='%s'>%s (<a href='#list-of-endpoints'>go to full list</a>)</h3>\n\n", getEndpointLink(group.Name, endpoint.Name), endpoint.Name)
|
||||
wf(
|
||||
"<h3 id='%s'>%s (<a href='#list-of-endpoints'>go to full list</a>)</h3>\n\n",
|
||||
getEndpointLink(group.Name, endpoint.Name),
|
||||
endpoint.Name,
|
||||
)
|
||||
wf("%s\n\n", endpoint.Description)
|
||||
wf("`%s %s/%s%s`\n\n", endpoint.Method, api.endpointBasePath(), group.Prefix, endpoint.Path)
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
# API Docs
|
||||
|
||||
**Description:**
|
||||
|
||||
**Version:** `v0`
|
||||
|
||||
<h2 id='list-of-endpoints'>List of Endpoints</h2>
|
||||
|
@ -1,7 +1,5 @@
|
||||
# API Docs
|
||||
|
||||
**Description:**
|
||||
|
||||
**Version:** `v1`
|
||||
|
||||
<h2 id='list-of-endpoints'>List of Endpoints</h2>
|
||||
|
@ -1,6 +1,6 @@
|
||||
# API Docs
|
||||
|
||||
**Description:** Interacts with projects
|
||||
**Description: **Interacts with projects
|
||||
|
||||
**Version:** `v0`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user