File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change 943
943
*/
944
944
guessOptionsType : function ( schema )
945
945
{
946
- var type = null ;
946
+ // check if it has format defined
947
+ if ( schema . format && Alpaca . defaultFormatFieldMapping [ schema . format ] )
948
+ {
949
+ return Alpaca . defaultFormatFieldMapping [ schema . format ] ;
950
+ }
947
951
948
952
if ( schema && typeof ( schema [ "enum" ] ) !== "undefined" )
949
953
{
950
954
if ( schema [ "enum" ] . length > 3 )
951
955
{
952
- type = "select" ;
956
+ return "select" ;
953
957
}
954
958
else
955
959
{
956
- type = "radio" ;
960
+ return "radio" ;
957
961
}
958
962
}
959
- else
960
- {
961
- type = Alpaca . defaultSchemaFieldMapping [ schema . type ] ;
962
- }
963
963
964
- // check if it has format defined
965
- if ( schema . format && Alpaca . defaultFormatFieldMapping [ schema . format ] )
966
- {
967
- type = Alpaca . defaultFormatFieldMapping [ schema . format ] ;
964
+ // type: ["string", "null"] is a valid way of defining an optional
965
+ // field that can be either a string, or null. Use the first non-null type.
966
+ var schemaType = schema . type
967
+ if ( Alpaca . isArray ( schemaType ) ) {
968
+ for ( var i = 0 ; i < schemaType . length ; i ++ ) {
969
+ if ( schemaType [ i ] === 'null' ) continue ;
970
+ schemaType = schemaType [ i ] ;
971
+ break ;
972
+ }
968
973
}
969
974
970
- return type ;
975
+ return Alpaca . defaultSchemaFieldMapping [ schemaType ] ;
971
976
} ,
972
977
973
978
/**
You can’t perform that action at this time.
0 commit comments