|
@@ -76,14 +76,22 @@ func (p parser) fillInfo() {
|
|
|
|
|
|
func (p parser) fillSyntax() {
|
|
func (p parser) fillSyntax() {
|
|
if p.ast.Syntax != nil {
|
|
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() {
|
|
func (p parser) fillImport() {
|
|
if len(p.ast.Import) > 0 {
|
|
if len(p.ast.Import) > 0 {
|
|
for _, item := range p.ast.Import {
|
|
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:
|
|
case *ast.Literal:
|
|
raw := v.Literal.Text()
|
|
raw := v.Literal.Text()
|
|
if api.IsBasicType(raw) {
|
|
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:
|
|
case *ast.Interface:
|
|
return spec.InterfaceType{RawName: v.Literal.Text()}
|
|
return spec.InterfaceType{RawName: v.Literal.Text()}
|
|
case *ast.Map:
|
|
case *ast.Map:
|
|
@@ -198,6 +210,9 @@ func (p parser) astTypeToSpec(in ast.DataType) spec.Type {
|
|
func (p parser) stringExprs(docs []ast.Expr) []string {
|
|
func (p parser) stringExprs(docs []ast.Expr) []string {
|
|
var result []string
|
|
var result []string
|
|
for _, item := range docs {
|
|
for _, item := range docs {
|
|
|
|
+ if item == nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
result = append(result, item.Text())
|
|
result = append(result, item.Text())
|
|
}
|
|
}
|
|
return result
|
|
return result
|
|
@@ -222,9 +237,13 @@ func (p parser) fillService() error {
|
|
AtServerAnnotation: spec.Annotation{},
|
|
AtServerAnnotation: spec.Annotation{},
|
|
Method: astRoute.Route.Method.Text(),
|
|
Method: astRoute.Route.Method.Text(),
|
|
Path: astRoute.Route.Path.Text(),
|
|
Path: astRoute.Route.Path.Text(),
|
|
|
|
+ Doc: p.stringExprs(astRoute.Route.DocExpr),
|
|
|
|
+ Comment: p.stringExprs([]ast.Expr{astRoute.Route.CommentExpr}),
|
|
}
|
|
}
|
|
if astRoute.AtHandler != nil {
|
|
if astRoute.AtHandler != nil {
|
|
route.Handler = astRoute.AtHandler.Name.Text()
|
|
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)
|
|
err := p.fillRouteAtServer(astRoute, &route)
|