Skip to content

Commit

Permalink
fix: pb support error on MapSerializable、DartJsonMapper、FlutterCompute (
Browse files Browse the repository at this point in the history
#636)

Co-authored-by: jiechic <[email protected]>
  • Loading branch information
jiechic and jiechic authored Nov 9, 2023
1 parent ddcfd26 commit 5877f30
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 10 deletions.
17 changes: 8 additions & 9 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,14 @@ if (T != dynamic &&
);
break;
}
} else if (_typeChecker(GeneratedMessage).isSuperTypeOf(bodyName.type)) {
if (bodyName.type.nullabilitySuffix != NullabilitySuffix.none) {
log.warning(
"GeneratedMessage body ${_displayString(bodyName.type)} can not be nullable.");
}
blocks.add(declareFinal(dataVar)
.assign(refer("${bodyName.displayName}.writeToBuffer()"))
.statement);
} else if (bodyTypeElement != null &&
_typeChecker(File).isExactly(bodyTypeElement)) {
blocks.add(
Expand Down Expand Up @@ -1614,15 +1622,6 @@ if (T != dynamic &&
).statement,
);
}
} else if (_typeChecker(GeneratedMessage)
.isSuperTypeOf(bodyName.type)) {
if (bodyName.type.nullabilitySuffix != NullabilitySuffix.none) {
log.warning(
"GeneratedMessage body ${_displayString(bodyName.type)} can not be nullable.");
}
blocks.add(declareFinal(dataVar)
.assign(refer("${bodyName.displayName}.writeToBuffer()"))
.statement);
} else {
if (_missingToJson(ele)) {
log.warning(
Expand Down
87 changes: 86 additions & 1 deletion generator/test/src/generator_test_src.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1952,8 +1952,93 @@ abstract class CombineBaseUrls {
'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''',
contains: true,
)
@ShouldGenerate(
'''await compute(Result.fromBuffer, _result.data!);''',
contains: true,
)
@RestApi()
abstract class ProtoSupport {
abstract class ProtoSupportParserJsonSerializable {
@GET('/')
Future<Result> get(@Body() Params params);
}

@ShouldGenerate(
'''final _data = params.writeToBuffer();''',
contains: true,
)
@ShouldGenerate(
'''
r'accept':
'application/x-protobuf; \${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=\${Result.getDefault().info_.qualifiedMessageName}"}'
''',
contains: true,
)
@ShouldGenerate(
'''
contentType:
'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''',
contains: true,
)
@ShouldGenerate(
'''await compute(Result.fromBuffer, _result.data!);''',
contains: true,
)
@RestApi(parser: Parser.DartJsonMapper)
abstract class ProtoSupportParserDartJsonMapper {
@GET('/')
Future<Result> get(@Body() Params params);
}

@ShouldGenerate(
'''final _data = params.writeToBuffer();''',
contains: true,
)
@ShouldGenerate(
'''
r'accept':
'application/x-protobuf; \${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=\${Result.getDefault().info_.qualifiedMessageName}"}'
''',
contains: true,
)
@ShouldGenerate(
'''
contentType:
'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''',
contains: true,
)
@ShouldGenerate(
'''await compute(Result.fromBuffer, _result.data!);''',
contains: true,
)
@RestApi(parser: Parser.MapSerializable)
abstract class ProtoSupportParserMapSerializable {
@GET('/')
Future<Result> get(@Body() Params params);
}

@ShouldGenerate(
'''final _data = params.writeToBuffer();''',
contains: true,
)
@ShouldGenerate(
'''
r'accept':
'application/x-protobuf; \${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=\${Result.getDefault().info_.qualifiedMessageName}"}'
''',
contains: true,
)
@ShouldGenerate(
'''
contentType:
'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''',
contains: true,
)
@ShouldGenerate(
'''await compute(Result.fromBuffer, _result.data!);''',
contains: true,
)
@RestApi(parser: Parser.FlutterCompute)
abstract class ProtoSupportParserFlutterCompute {
@GET('/')
Future<Result> get(@Body() Params params);
}
Expand Down

0 comments on commit 5877f30

Please sign in to comment.