generates nested types in doc (#2201)
Co-authored-by: Link_Zhao <Link_Zhao@epam.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"html/template"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -35,12 +36,12 @@ func genDoc(api *spec.ApiSpec, dir, filename string) error {
|
||||
routeComment = "N/A"
|
||||
}
|
||||
|
||||
requestContent, err := buildDoc(route.RequestType)
|
||||
requestContent, err := buildDoc(route.RequestType, api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
responseContent, err := buildDoc(route.ResponseType)
|
||||
responseContent, err := buildDoc(route.ResponseType, api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -60,7 +61,6 @@ func genDoc(api *spec.ApiSpec, dir, filename string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
builder.Write(tmplBytes.Bytes())
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func genDoc(api *spec.ApiSpec, dir, filename string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func buildDoc(route spec.Type) (string, error) {
|
||||
func buildDoc(route spec.Type, api *spec.ApiSpec) (string, error) {
|
||||
if route == nil || len(route.Name()) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
@@ -78,12 +78,15 @@ func buildDoc(route spec.Type) (string, error) {
|
||||
if definedType, ok := route.(spec.DefineStruct); ok {
|
||||
associatedTypes(definedType, &tps)
|
||||
}
|
||||
value, err := gogen.BuildTypes(tps)
|
||||
value, err := gogen.BuildTypes(tps, api)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("\n\n```golang\n%s\n```\n", value), nil
|
||||
formatted, err := format.Source([]byte(value))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("\n\n```golang\n%s\n```\n", string(formatted)), nil
|
||||
}
|
||||
|
||||
func associatedTypes(tp spec.DefineStruct, tps *[]spec.Type) {
|
||||
|
||||
Reference in New Issue
Block a user