@@ -46,29 +46,34 @@ var CodeUtil = {
4646 line = lines [ i ] . trim ( ) ;
4747
4848 //每一种都要提取:左边的key
49- index = line . indexOf ( ': ' ) ; //可能是 ' 或 ",所以不好用 ': , ": 判断
49+ index = line == null ? - 1 : line . indexOf ( ': ' ) ; //可能是 ' 或 ",所以不好用 ': , ": 判断
5050 if ( index < 0 ) {
5151 continue ;
5252 }
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的第一个字符!' ;
6556 }
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+ }
7277 }
7378
7479 //maxLength = maxLineLength - lines[i].length;
@@ -734,7 +739,22 @@ var CodeUtil = {
734739 return id . toLowerCase ( ) == 'id' ;
735740 } ,
736741
742+ 743+ 737744 QUERY_TYPES : [ '数据' , '数量' , '全部' ] ,
745+ REQUEST_ROLES : {
746+ UNKNOWN : '未登录' ,
747+ 748+ LOGIN : '已登录' ,
749+ 750+ CONTACT : '联系人' ,
751+ 752+ CIRCLE : '圈子成员' ,
753+ 754+ OWNER : '拥有者' ,
755+ 756+ ADMIN : '管理员'
757+ } ,
738758
739759 /**获取请求JSON的注释
740760 * @param tableList
@@ -792,13 +812,24 @@ var CodeUtil = {
792812 case '@correct' :
793813 return CodeUtil . getComment ( '字段校正' , false , ' ' ) ;
794814 case '@role' :
795- return CodeUtil . getComment ( '登录角色' , false , ' ' ) ;
815+ return CodeUtil . getComment ( '登录角色:' + CodeUtil . REQUEST_ROLES [ value . toLowerCase ( ) ] , false , ' ' ) ;
796816 }
797817 return '' ;
798818 }
799819 return CodeUtil . getComment ( CodeUtil . getCommentFromDoc ( tableList , name , key ) , false , ' ' ) ;
800820 }
801821
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+ 802833 return '' ;
803834 } ,
804835
0 commit comments