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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
c3047f34
Commit
c3047f34
authored
3 years ago
by
Johan de Klerk
Browse files
Options
Downloads
Patches
Plain Diff
docs - get array info
parent
27579923
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api_documentation/api_documentation.go
+8
-3
8 additions, 3 deletions
api_documentation/api_documentation.go
with
8 additions
and
3 deletions
api_documentation/api_documentation.go
+
8
−
3
View file @
c3047f34
...
...
@@ -102,7 +102,7 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}, corePath string
docMethod
.
RequestBody
=
&
requestBody
if
handler
.
RequestBodyType
.
Kind
()
==
reflect
.
Struct
&&
handler
.
RequestBodyType
.
NumField
()
>
0
{
schema
,
err
:=
StructSchema
(
handler
.
RequestBodyType
.
Field
(
0
)
.
Type
)
schema
,
err
:=
StructSchema
(
handler
.
RequestBodyType
)
if
err
!=
nil
{
return
Docs
{},
err
}
...
...
@@ -115,7 +115,7 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}, corePath string
response
,
responseBodyTypeString
:=
GetResponse
(
handler
)
docMethod
.
Responses
=
&
response
if
handler
.
ResponseType
.
Kind
()
==
reflect
.
Struct
&&
handler
.
ResponseType
.
NumField
()
>
0
{
schema
,
err
:=
StructSchema
(
handler
.
ResponseType
.
Field
(
0
)
.
Type
)
schema
,
err
:=
StructSchema
(
handler
.
ResponseType
)
if
err
!=
nil
{
return
Docs
{},
err
}
...
...
@@ -289,7 +289,12 @@ func StructSchema(t reflect.Type) (interface{}, error) {
schema
[
"type"
]
=
"object"
case
reflect
.
Slice
:
schema
[
"type"
]
=
"array"
schema
[
"items"
]
=
t
.
Elem
()
element
:=
reflect
.
TypeOf
(
t
)
.
Elem
()
items
,
err
:=
StructSchema
(
element
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"failed to document"
)
}
schema
[
"items"
]
=
items
default
:
return
nil
,
errors
.
Errorf
(
"cannot generate schema for %v kind=%v"
,
t
,
t
.
Kind
())
}
...
...
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