@@ -226,8 +226,8 @@ $lines
226
226
227
227
test ('simple return type' , () async {
228
228
final newInputContent = inputContent
229
- .replaceAll ('void ' , 'int ' )
230
- .replaceAll ('<void>' , '<int >' );
229
+ .replaceAll ('void ' , 'Map<String, dynamic> ' )
230
+ .replaceAll ('<void>' , '<Map<String, dynamic> >' );
231
231
232
232
await _testItems (
233
233
newInputContent,
@@ -266,48 +266,8 @@ $lines
266
266
267
267
test ('JSON return type' , () async {
268
268
final newInputContent = inputContent
269
- .replaceAll ('void ' , 'int ' )
270
- .replaceAll ('<void>' , '<int>' );
271
-
272
- await _testItems (
273
- newInputContent,
274
- [
275
- 'syncFunction' ,
276
- 'asyncFunction' ,
277
- 'futureOrFunction' ,
278
- 'extraParam' ,
279
- 'optionalParam' ,
280
- ],
281
- (e) => """
282
- case '$e ':
283
- return JsonFunctionTarget(
284
- function_library.$e ,
285
- (json) {
286
- if (json is Map<String, dynamic>) {
287
- try {
288
- return function_library.JsonType.fromJson(json);
289
- } catch (e, stack) {
290
- throw BadRequestException(
291
- 400,
292
- 'There was an error parsing the provided JSON data.',
293
- innerError: e,
294
- innerStack: stack,
295
- );
296
- }
297
- }
298
- throw BadRequestException(
299
- 400,
300
- 'The provided JSON is not the expected type '
301
- '`Map<String, dynamic>`.',
302
- );
303
- },
304
- );""" );
305
- });
306
-
307
- test ('complex return type' , () async {
308
- final newInputContent = inputContent
309
- .replaceAll ('void ' , 'Map<String, List<JsonType>> ' )
310
- .replaceAll ('<void>' , '<Map<String, List<JsonType>>>' );
269
+ .replaceAll ('void ' , 'Map<String, dynamic> ' )
270
+ .replaceAll ('<void>' , '<Map<String, dynamic>>' );
311
271
312
272
await _testItems (
313
273
newInputContent,
@@ -365,53 +325,22 @@ $lines
365
325
return JsonFunctionTarget.voidResult(
366
326
function_library.$e ,
367
327
(json) {
368
- if (json is num ) {
328
+ if (json is Map<String, dynamic> ) {
369
329
return json;
370
330
}
371
331
throw BadRequestException(
372
332
400,
373
333
'The provided JSON is not the expected type '
374
- '`num `.',
334
+ '`Map<String, dynamic> `.',
375
335
);
376
336
},
377
337
);""" );
378
338
});
379
339
380
340
test ('simple return type' , () async {
381
341
final newInputContent = inputContent
382
- .replaceAll ('void ' , 'int ' )
383
- .replaceAll ('<void>' , '<int>' );
384
- await _testItems (
385
- newInputContent,
386
- [
387
- 'syncFunction' ,
388
- 'asyncFunction' ,
389
- 'futureOrFunction' ,
390
- 'extraParam' ,
391
- 'optionalParam' ,
392
- ],
393
- (e) => """
394
- case '$e ':
395
- return JsonFunctionTarget(
396
- function_library.$e ,
397
- (json) {
398
- if (json is num) {
399
- return json;
400
- }
401
- throw BadRequestException(
402
- 400,
403
- 'The provided JSON is not the expected type '
404
- '`num`.',
405
- );
406
- },
407
- );""" );
408
- });
409
-
410
- test ('complex return type' , () async {
411
- final newInputContent = inputContent
412
- .replaceAll ('void ' , 'Map<String, List<bool>> ' )
413
- .replaceAll ('<void>' , '<Map<String, List<bool>>>' );
414
-
342
+ .replaceAll ('void ' , 'Map<String, dynamic> ' )
343
+ .replaceAll ('<void>' , '<Map<String, dynamic>>' );
415
344
await _testItems (
416
345
newInputContent,
417
346
[
@@ -426,13 +355,13 @@ $lines
426
355
return JsonFunctionTarget(
427
356
function_library.$e ,
428
357
(json) {
429
- if (json is num ) {
358
+ if (json is Map<String, dynamic> ) {
430
359
return json;
431
360
}
432
361
throw BadRequestException(
433
362
400,
434
363
'The provided JSON is not the expected type '
435
- '`num `.',
364
+ '`Map<String, dynamic> `.',
436
365
);
437
366
},
438
367
);""" );
@@ -441,8 +370,8 @@ $lines
441
370
test ('void with context' , () async {
442
371
final newInputContent = inputContent
443
372
.replaceAll (
444
- '(num request)' ,
445
- '(num request, RequestContext context)' ,
373
+ '(Map<String, dynamic> request)' ,
374
+ '(Map<String, dynamic> request, RequestContext context)' ,
446
375
)
447
376
.replaceAll (
448
377
'int? other' ,
@@ -463,13 +392,13 @@ $lines
463
392
return JsonWithContextFunctionTarget.voidResult(
464
393
function_library.$e ,
465
394
(json) {
466
- if (json is num ) {
395
+ if (json is Map<String, dynamic> ) {
467
396
return json;
468
397
}
469
398
throw BadRequestException(
470
399
400,
471
400
'The provided JSON is not the expected type '
472
- '`num `.',
401
+ '`Map<String, dynamic> `.',
473
402
);
474
403
},
475
404
);""" );
@@ -556,6 +485,21 @@ package:$_pkgName/functions.dart:8:10
556
485
// Custom and JSON event types
557
486
//
558
487
'Duration handleGet(DateTime request) => null;' : notCompatibleMatcher,
488
+
489
+ //
490
+ // dart:core types that aren't `Map<String, dynamic>`
491
+ //
492
+ // Map param is under-specified
493
+ 'Map<String, dynamic> handleGet(Map request) => null;' :
494
+ notCompatibleMatcher,
495
+ 'int handleGet(Map<String, dynamic> request) => null;' :
496
+ notCompatibleMatcher,
497
+ 'Map<String, dynamic> handleGet(int request) => null;' :
498
+ notCompatibleMatcher,
499
+ // Map return type is under-specified
500
+ 'Map handleGet(Map<String, dynamic> request) => null;' :
501
+ notCompatibleMatcher,
502
+ 'int handleGet(int request) => null;' : notCompatibleMatcher,
559
503
};
560
504
561
505
for (var shape in invalidShapes.entries) {
0 commit comments