Skip to content
Snippets Groups Projects
Commit 7bc39420 authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Docs: Response content

parent 42bbb105
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,6 @@ import (
type NoParams struct{}
type DocPath map[string]DocMethodInfo
type Docs struct {
Paths map[string]DocPath `json:"paths"`
Components DocSchemas `json:"components"`
......@@ -36,7 +35,6 @@ type DocRequestBody struct {
Content map[string]interface{} `json:"content"`
}
type DocParam struct {
Name string `json:"name"`
In string `json:"in"`
......@@ -44,14 +42,13 @@ type DocParam struct {
Schema interface{} `json:"schema"`
}
type DocSchema struct {
Ref string `json:"$ref"`
}
type DocResponseValue struct {
Description string `json:"description"`
Content map[string]interface{} `json:"content"`
Content *map[string]interface{} `json:"content,omitempty"`
}
type DocSchemaResponse struct {
......@@ -59,7 +56,6 @@ type DocSchemaResponse struct {
Items DocSchema `json:"items"`
}
func GetDocs(endpointHandlers map[string]map[string]interface{}) (Docs, error) {
docs := Docs{
Paths: map[string]DocPath{},
......@@ -71,7 +67,6 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}) (Docs, error) {
return Docs{}, validationError
}
for path, methods := range endpointHandlers {
docPath := DocPath{}
for method, methodHandler := range methods {
......@@ -99,7 +94,6 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}) (Docs, error) {
return Docs{}, err
}
parameter := DocParam{
Name: name,
In: "query",
......@@ -115,7 +109,6 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}) (Docs, error) {
body := reflect.New(handler.RequestBodyType).Interface()
bodyTypeString := getType(body)
docMethod.RequestBody = &DocRequestBody{
Description: "Some description",
Required: true,
......@@ -141,13 +134,17 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}) (Docs, error) {
responseBody := reflect.New(handler.ResponseType).Interface()
responseBodyTypeString := getType(responseBody)
responses["200"] = DocResponseValue{
response := DocResponseValue{
Description: "Some description",
Content: map[string]interface{} {
}
responses["200"] = response
if responseBodyTypeString != "" {
response.Content = &map[string]interface{}{
"application/json": map[string]interface{}{
"schema": DocSchema{Ref: "#/components/schemas/" + responseBodyTypeString},
},
},
}
}
docMethod.Responses = &responses
......@@ -167,7 +164,6 @@ func GetDocs(endpointHandlers map[string]map[string]interface{}) (Docs, error) {
docs.Paths[path] = docPath
}
return docs, nil
}
......@@ -185,10 +181,8 @@ func StructSchema(t reflect.Type) (interface{}, error) {
}
schema := map[string]interface{}{}
description := ""
if t.Kind() == reflect.Ptr {
// schema["optional"] = true
t = t.Elem()
......@@ -235,8 +229,6 @@ func StructSchema(t reflect.Type) (interface{}, error) {
}
fieldName = strings.Replace(fieldName, ",omitempty", "", -1)
var err error
fieldDesc := f.Tag.Get("doc")
if fieldDesc == "" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment