Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
9f9f2840
Commit
9f9f2840
authored
3 years ago
by
Johan de Klerk
Browse files
Options
Downloads
Patches
Plain Diff
docs - added summary
parent
da5c234b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api_documentation/api_documentation.go
+27
-2
27 additions, 2 deletions
api_documentation/api_documentation.go
string_utils/string_utils.go
+19
-2
19 additions, 2 deletions
string_utils/string_utils.go
with
46 additions
and
4 deletions
api_documentation/api_documentation.go
+
27
−
2
View file @
9f9f2840
...
...
@@ -3,6 +3,7 @@ package api_documentation
import
(
"fmt"
"gitlab.com/uafrica/go-utils/logs"
"gitlab.com/uafrica/go-utils/string_utils"
"go/doc"
"go/parser"
"go/token"
...
...
@@ -30,6 +31,7 @@ type DocSchemas struct {
type
DocMethodInfo
struct
{
Description
string
`json:"description"`
Summary
string
`json:"summary"`
Tags
[]
string
`json:"tags"`
RequestBody
*
DocRequestBody
`json:"requestBody,omitempty"`
Parameters
[]
DocParam
`json:"parameters,omitempty"`
...
...
@@ -92,6 +94,7 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}, corePath string
// Meta data
functionName
:=
GetFunctionName
(
handler
.
FuncValue
.
Interface
())
docMethod
.
Description
=
functionDocs
[
functionName
]
docMethod
.
Summary
=
functionNameToSummary
(
functionName
,
method
)
docMethod
.
Tags
=
[]
string
{
path
}
// Parameters
...
...
@@ -138,6 +141,29 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}, corePath string
return
docs
,
nil
}
func
functionNameToSummary
(
name
string
,
method
string
)
string
{
name
=
string_utils
.
ReplaceCaseInsensitive
(
name
,
"GET"
,
""
)
name
=
string_utils
.
ReplaceCaseInsensitive
(
name
,
"POST"
,
""
)
name
=
string_utils
.
ReplaceCaseInsensitive
(
name
,
"PATCH"
,
""
)
name
=
string_utils
.
ReplaceCaseInsensitive
(
name
,
"DELETE"
,
""
)
var
cleanMethod
string
if
method
==
"GET"
{
cleanMethod
=
"Fetch"
}
else
if
method
==
"POST"
{
cleanMethod
=
"Create"
}
else
if
method
==
"DELETE"
{
cleanMethod
=
"Delete"
}
else
if
method
==
"PATCH"
{
cleanMethod
=
"Update"
}
summary
:=
string_utils
.
PascalCaseToSentence
(
name
)
summary
=
cleanMethod
+
" "
+
strings
.
ToLower
(
summary
)
return
summary
}
func
addDefaultSchemas
(
docs
Docs
)
{
docs
.
Components
.
Schemas
[
"error"
]
=
map
[
string
]
string
{
"type"
:
"string"
,
...
...
@@ -365,8 +391,7 @@ func GetStructDocs(corePath string) map[string]string {
return
nil
}
for
k
,
f
:=
range
d
{
fmt
.
Println
(
"package"
,
k
)
for
_
,
f
:=
range
d
{
p
:=
doc
.
New
(
f
,
"./"
,
2
)
for
_
,
objectTypes
:=
range
p
.
Types
{
...
...
This diff is collapsed.
Click to expand it.
string_utils/string_utils.go
+
19
−
2
View file @
9f9f2840
...
...
@@ -234,10 +234,10 @@ func KeyToHumanReadable(s string) string {
re
:=
regexp
.
MustCompile
(
"(_|-)"
)
s
=
re
.
ReplaceAllString
(
s
,
" "
)
return
s
entenceCase
(
string
(
s
))
return
S
entenceCase
(
string
(
s
))
}
func
s
entenceCase
(
str
string
)
string
{
func
S
entenceCase
(
str
string
)
string
{
for
i
,
v
:=
range
str
{
return
string
(
unicode
.
ToUpper
(
v
))
+
str
[
i
+
1
:
]
}
...
...
@@ -311,3 +311,20 @@ func IsValidEmail(email string) bool {
isValidEmail
:=
regex
.
MatchString
(
email
)
return
isValidEmail
}
func
PascalCaseToSentence
(
pascal
string
)
string
{
var
parts
[]
string
start
:=
0
for
end
,
r
:=
range
pascal
{
if
end
!=
0
&&
unicode
.
IsUpper
(
r
)
{
parts
=
append
(
parts
,
pascal
[
start
:
end
])
start
=
end
}
}
if
start
!=
len
(
pascal
)
{
parts
=
append
(
parts
,
pascal
[
start
:
])
}
sentence
:=
strings
.
Join
(
parts
,
" "
)
return
sentence
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment