@@ -74,13 +74,14 @@ func parseDocDefinition(t *testing.T, root, path, typ string, field *ast.Field,
7474 def .Important = util.NewType [string ](important [0 ])
7575 }
7676
77- if docs , dep , ok , err := extractNotTags (field ); err != nil {
78- require .Fail (t , fmt .Sprintf ("Error while getting tags for %s: %s" , path , err .Error ()))
79- } else if ! ok {
80- println (def .Path , " is missing documentation!" )
81- } else {
77+ if docs := extractDocumentation (field ); len (docs ) > 0 {
8278 def .Docs = docs
83- def .Deprecated = dep
79+ }
80+
81+ if grade , err := extractGrade (field ); err != nil {
82+ require .Fail (t , fmt .Sprintf ("Error while getting grade for %s: %s" , path , err .Error ()))
83+ } else {
84+ def .Grade = grade
8485 }
8586
8687 file := fs .File (field .Pos ())
@@ -250,40 +251,79 @@ func extract(n *ast.Field, tag string) ([]string, bool) {
250251 return ret , len (ret ) > 0
251252}
252253
253- func extractNotTags (n * ast.Field ) ([]string , []string , bool , error ) {
254- if n .Doc == nil {
255- return nil , nil , false , nil
254+ func extractGrade (n * ast.Field ) (* DocDefinitionGradeDefinition , error ) {
255+ deprecatedGrade , err := extractDeprecated (n )
256+ if err != nil {
257+ return nil , err
256258 }
257259
258- var ret , dep [] string
260+ var grade * DocDefinitionGradeDefinition
259261
260- var deprecated bool
262+ if v , ok := extract (n , "grade" ); ok {
263+ grade , err = NewDocDefinitionGradeDefinition (v ... )
264+ if err != nil {
265+ return nil , err
266+ }
267+ }
268+
269+ if deprecatedGrade != nil && grade != nil {
270+ return nil , errors .Errorf ("Only one way of defining grade should be visible" )
271+ }
261272
273+ if deprecatedGrade != nil {
274+ return deprecatedGrade , nil
275+ }
276+
277+ if grade != nil {
278+ return grade , nil
279+ }
280+
281+ return nil , nil
282+ }
283+
284+ func extractDeprecated (n * ast.Field ) (* DocDefinitionGradeDefinition , error ) {
285+ if n == nil || n .Doc == nil {
286+ return nil , nil
287+ }
262288 for _ , c := range n .Doc .List {
263289 if goStrings .HasPrefix (c .Text , "// " ) {
264290 if goStrings .HasPrefix (c .Text , "// Deprecated" ) {
265291 if ! goStrings .HasPrefix (c .Text , "// Deprecated: " ) {
266- return nil , nil , false , errors .Errorf ("Invalid deprecated field" )
292+ return nil , errors .Errorf ("Invalid deprecated field" )
267293 }
268294 }
269295 if goStrings .HasPrefix (c .Text , "// Deprecated:" ) {
270- deprecated = true
271- dep = append (dep , goStrings .TrimSpace (goStrings .TrimPrefix (c .Text , "// Deprecated:" )))
272- continue
296+ return & DocDefinitionGradeDefinition {
297+ Grade : DocDefinitionGradeDeprecated ,
298+ Message : []string {goStrings .TrimSpace (goStrings .TrimPrefix (c .Text , "// Deprecated:" ))},
299+ }, nil
273300 }
301+ }
302+ }
274303
275- if ! goStrings .HasPrefix (c .Text , "// +doc/" ) {
276- v := goStrings .TrimSpace (goStrings .TrimPrefix (c .Text , "// " ))
277- if deprecated {
278- dep = append (dep , v )
279- } else {
280- ret = append (ret , v )
281- }
304+ return nil , nil
305+ }
306+
307+ func extractDocumentation (n * ast.Field ) []string {
308+ if n .Doc == nil {
309+ return nil
310+ }
311+
312+ var ret []string
313+
314+ for _ , c := range n .Doc .List {
315+ if goStrings .HasPrefix (c .Text , "// " ) {
316+ if goStrings .HasPrefix (c .Text , "// +doc/" ) {
317+ continue
318+ }
319+ if goStrings .HasPrefix (c .Text , "// Deprecated" ) {
320+ continue
282321 }
322+ ret = append (ret , goStrings .TrimSpace (goStrings .TrimPrefix (c .Text , "// " )))
283323 }
284324 }
285325
286- return ret , dep , len ( ret ) > 0 || len ( dep ) > 0 , nil
326+ return ret
287327}
288328
289329// isSimpleType returns the OpenAPI-compatible type name, type format and boolean indicating if this is simple type or not
0 commit comments