diff --git a/lib/generators/retrofit_api_generator.dart b/lib/generators/retrofit_api_generator.dart index 544a3f9..1f7dbe0 100644 --- a/lib/generators/retrofit_api_generator.dart +++ b/lib/generators/retrofit_api_generator.dart @@ -350,6 +350,11 @@ class RetrofitApiGenerator extends BaseGenerator { return 'BaseResult'; } + // 检查是否只是简单的成功响应(没有具体数据) + if (_isSimpleSuccessResponse(path)) { + return 'BaseResult'; + } + // 如果没有明确的 schema 定义,使用通用类型 // 这通常表示后端文档不完整,应该要求后端完善 swagger 文档 return 'BaseResult>'; @@ -1440,6 +1445,40 @@ class RetrofitApiGenerator extends BaseGenerator { return false; } + /// 检查是否是简单的成功响应(没有具体数据) + bool _isSimpleSuccessResponse(ApiPath path) { + // 查找成功响应 (200, 201, 202) + final successResponses = ['200', '201', '202']; + + for (final statusCode in successResponses) { + final response = path.responses[statusCode]; + if (response != null) { + // 检查是否只有 description 而没有具体的 content 或 schema + final hasNoContent = response.content.isEmpty; + + if (hasNoContent) { + // 检查特定的接口名称模式或路径模式 + final methodName = _generateSimpleMethodName(path); + final pathLower = path.path.toLowerCase(); + + if (methodName.contains('logOff') || + methodName.contains('register') || + methodName.contains('getUserLoginCode') || + pathLower.contains('logoff') || + pathLower.contains('register') || + pathLower.contains('getuserlogincode') || + methodName.contains('delete') || + methodName.contains('remove') || + methodName.contains('upload')) { + return true; + } + } + } + } + + return false; + } + /// 检查指定路径列表是否需要导入分页相关类型 bool _needsPaginationImport(List paths) { for (final path in paths) { diff --git a/pubspec.yaml b/pubspec.yaml index 41536de..e3a2a2f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: swagger_generator_flutter description: A Flutter project using generated API models -version: 2.0.0+2 +version: 2.0.1+3 environment: sdk: '>=3.0.0 <4.0.0' diff --git a/tests/schema_validator_test.dart b/tests/schema_validator_test.dart index e69de29..8b13789 100644 --- a/tests/schema_validator_test.dart +++ b/tests/schema_validator_test.dart @@ -0,0 +1 @@ +