@@ -46,29 +46,34 @@ var CodeUtil = {
46
46
line = lines [ i ] . trim ( ) ;
47
47
48
48
//每一种都要提取:左边的key
49
- index = line . indexOf ( ': ' ) ; //可能是 ' 或 ",所以不好用 ': , ": 判断
49
+ index = line == null ? - 1 : line . indexOf ( ': ' ) ; //可能是 ' 或 ",所以不好用 ': , ": 判断
50
50
if ( index < 0 ) {
51
51
continue ;
52
52
}
53
-
54
- key = line . substring ( 1 , index - 1 ) ;
55
-
56
- if ( line . endsWith ( '{' ) ) { //对象,判断是不是Table,再加对应的注释
57
- depth ++ ;
58
- names [ depth ] = key ;
59
- comment = CodeUtil . getComment4Request ( tableList , names [ depth ] , key , null ) ;
60
- }
61
- else if ( line . endsWith ( '[' ) ) { //数组,判断是不是 key{}
62
- depth ++ ;
63
- names [ depth ] = key ;
64
- comment = CodeUtil . getComment4Request ( tableList , names [ depth ] , key , null ) ;
53
+ if ( index == 0 ) { // ":user": value 不合法
54
+ // throw new Error('不允许将 : 作为key的第一个字符!');
55
+ comment = ' ! 不允许将 : 作为key的第一个字符!' ;
65
56
}
66
- else if ( line . endsWith ( '}' ) || line . endsWith ( ']' ) ) {
67
- depth -- ;
68
- }
69
- else { //其它,直接在后面加上注释
70
- value = line . substring ( index + 2 ) ;
71
- comment = CodeUtil . getComment4Request ( tableList , names [ depth ] , key , value ) ;
57
+ else {
58
+ key = line . substring ( 1 , index - 1 ) ;
59
+
60
+ if ( line . endsWith ( '{' ) ) { //对象,判断是不是Table,再加对应的注释
61
+ depth ++ ;
62
+ names [ depth ] = key ;
63
+ comment = CodeUtil . getComment4Request ( tableList , names [ depth ] , key , null ) ;
64
+ }
65
+ else if ( line . endsWith ( '[' ) ) { //数组,判断是不是 key{}
66
+ depth ++ ;
67
+ names [ depth ] = key ;
68
+ comment = CodeUtil . getComment4Request ( tableList , names [ depth ] , key , null ) ;
69
+ }
70
+ else if ( line . endsWith ( '}' ) || line . endsWith ( ']' ) ) {
71
+ depth -- ;
72
+ }
73
+ else { //其它,直接在后面加上注释
74
+ value = line . substring ( index + 2 ) ;
75
+ comment = CodeUtil . getComment4Request ( tableList , names [ depth ] , key , value ) ;
76
+ }
72
77
}
73
78
74
79
//maxLength = maxLineLength - lines[i].length;
@@ -734,7 +739,22 @@ var CodeUtil = {
734
739
return id . toLowerCase ( ) == 'id' ;
735
740
} ,
736
741
742
+
743
+
737
744
QUERY_TYPES : [ '数据' , '数量' , '全部' ] ,
745
+ REQUEST_ROLES : {
746
+ UNKNOWN : '未登录' ,
747
+
748
+ LOGIN : '已登录' ,
749
+
750
+ CONTACT : '联系人' ,
751
+
752
+ CIRCLE : '圈子成员' ,
753
+
754
+ OWNER : '拥有者' ,
755
+
756
+ ADMIN : '管理员'
757
+ } ,
738
758
739
759
/**获取请求JSON的注释
740
760
* @param tableList
@@ -792,13 +812,24 @@ var CodeUtil = {
792
812
case '@correct' :
793
813
return CodeUtil . getComment ( '字段校正' , false , ' ' ) ;
794
814
case '@role' :
795
- return CodeUtil . getComment ( '登录角色' , false , ' ' ) ;
815
+ return CodeUtil . getComment ( '登录角色:' + CodeUtil . REQUEST_ROLES [ value . toLowerCase ( ) ] , false , ' ' ) ;
796
816
}
797
817
return '' ;
798
818
}
799
819
return CodeUtil . getComment ( CodeUtil . getCommentFromDoc ( tableList , name , key ) , false , ' ' ) ;
800
820
}
801
821
822
+ if ( StringUtil . isEmpty ( name ) ) {
823
+ switch ( key ) {
824
+ case 'tag' :
825
+ return '请求密钥' ;
826
+ case 'version' :
827
+ return '版本号' ;
828
+ case '@role' :
829
+ return '默认角色:' + CodeUtil . REQUEST_ROLES [ value . toLowerCase ( ) ] ;
830
+ }
831
+ }
832
+
802
833
return '' ;
803
834
} ,
804
835
0 commit comments