@@ -226,8 +226,8 @@ $lines
226226
227227 test ('simple return type' , () async {
228228 final newInputContent = inputContent
229- .replaceAll ('void ' , 'int ' )
230- .replaceAll ('<void>' , '<int >' );
229+ .replaceAll ('void ' , 'Map<String, dynamic> ' )
230+ .replaceAll ('<void>' , '<Map<String, dynamic> >' );
231231
232232 await _testItems (
233233 newInputContent,
@@ -266,48 +266,8 @@ $lines
266266
267267 test ('JSON return type' , () async {
268268 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>>' );
311271
312272 await _testItems (
313273 newInputContent,
@@ -365,53 +325,22 @@ $lines
365325 return JsonFunctionTarget.voidResult(
366326 function_library.$e ,
367327 (json) {
368- if (json is num ) {
328+ if (json is Map<String, dynamic> ) {
369329 return json;
370330 }
371331 throw BadRequestException(
372332 400,
373333 'The provided JSON is not the expected type '
374- '`num `.',
334+ '`Map<String, dynamic> `.',
375335 );
376336 },
377337 );""" );
378338 });
379339
380340 test ('simple return type' , () async {
381341 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>>' );
415344 await _testItems (
416345 newInputContent,
417346 [
@@ -426,13 +355,13 @@ $lines
426355 return JsonFunctionTarget(
427356 function_library.$e ,
428357 (json) {
429- if (json is num ) {
358+ if (json is Map<String, dynamic> ) {
430359 return json;
431360 }
432361 throw BadRequestException(
433362 400,
434363 'The provided JSON is not the expected type '
435- '`num `.',
364+ '`Map<String, dynamic> `.',
436365 );
437366 },
438367 );""" );
@@ -441,8 +370,8 @@ $lines
441370 test ('void with context' , () async {
442371 final newInputContent = inputContent
443372 .replaceAll (
444- '(num request)' ,
445- '(num request, RequestContext context)' ,
373+ '(Map<String, dynamic> request)' ,
374+ '(Map<String, dynamic> request, RequestContext context)' ,
446375 )
447376 .replaceAll (
448377 'int? other' ,
@@ -463,13 +392,13 @@ $lines
463392 return JsonWithContextFunctionTarget.voidResult(
464393 function_library.$e ,
465394 (json) {
466- if (json is num ) {
395+ if (json is Map<String, dynamic> ) {
467396 return json;
468397 }
469398 throw BadRequestException(
470399 400,
471400 'The provided JSON is not the expected type '
472- '`num `.',
401+ '`Map<String, dynamic> `.',
473402 );
474403 },
475404 );""" );
@@ -556,6 +485,21 @@ package:$_pkgName/functions.dart:8:10
556485 // Custom and JSON event types
557486 //
558487 '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,
559503 };
560504
561505 for (var shape in invalidShapes.entries) {
0 commit comments