Add document & comment for spec (#703)
* Add document & comment for spec * remove duplicate field * use alias
This commit is contained in:
@@ -76,14 +76,22 @@ func (p parser) fillInfo() {
|
||||
|
||||
func (p parser) fillSyntax() {
|
||||
if p.ast.Syntax != nil {
|
||||
p.spec.Syntax = spec.ApiSyntax{Version: p.ast.Syntax.Version.Text()}
|
||||
p.spec.Syntax = spec.ApiSyntax{
|
||||
Version: p.ast.Syntax.Version.Text(),
|
||||
Doc: p.stringExprs(p.ast.Syntax.DocExpr),
|
||||
Comment: p.stringExprs([]ast.Expr{p.ast.Syntax.CommentExpr}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p parser) fillImport() {
|
||||
if len(p.ast.Import) > 0 {
|
||||
for _, item := range p.ast.Import {
|
||||
p.spec.Imports = append(p.spec.Imports, spec.Import{Value: item.Value.Text()})
|
||||
p.spec.Imports = append(p.spec.Imports, spec.Import{
|
||||
Value: item.Value.Text(),
|
||||
Doc: p.stringExprs(item.DocExpr),
|
||||
Comment: p.stringExprs([]ast.Expr{item.CommentExpr}),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,10 +181,14 @@ func (p parser) astTypeToSpec(in ast.DataType) spec.Type {
|
||||
case *ast.Literal:
|
||||
raw := v.Literal.Text()
|
||||
if api.IsBasicType(raw) {
|
||||
return spec.PrimitiveType{RawName: raw}
|
||||
return spec.PrimitiveType{
|
||||
RawName: raw,
|
||||
}
|
||||
}
|
||||
|
||||
return spec.DefineStruct{RawName: raw}
|
||||
return spec.DefineStruct{
|
||||
RawName: raw,
|
||||
}
|
||||
case *ast.Interface:
|
||||
return spec.InterfaceType{RawName: v.Literal.Text()}
|
||||
case *ast.Map:
|
||||
@@ -198,6 +210,9 @@ func (p parser) astTypeToSpec(in ast.DataType) spec.Type {
|
||||
func (p parser) stringExprs(docs []ast.Expr) []string {
|
||||
var result []string
|
||||
for _, item := range docs {
|
||||
if item == nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, item.Text())
|
||||
}
|
||||
return result
|
||||
@@ -222,9 +237,13 @@ func (p parser) fillService() error {
|
||||
AtServerAnnotation: spec.Annotation{},
|
||||
Method: astRoute.Route.Method.Text(),
|
||||
Path: astRoute.Route.Path.Text(),
|
||||
Doc: p.stringExprs(astRoute.Route.DocExpr),
|
||||
Comment: p.stringExprs([]ast.Expr{astRoute.Route.CommentExpr}),
|
||||
}
|
||||
if astRoute.AtHandler != nil {
|
||||
route.Handler = astRoute.AtHandler.Name.Text()
|
||||
route.HandlerDoc = append(route.HandlerDoc, p.stringExprs(astRoute.AtHandler.DocExpr)...)
|
||||
route.HandlerComment = append(route.HandlerComment, p.stringExprs([]ast.Expr{astRoute.AtHandler.CommentExpr})...)
|
||||
}
|
||||
|
||||
err := p.fillRouteAtServer(astRoute, &route)
|
||||
|
||||
Reference in New Issue
Block a user