feat: update version 增加判断
/// 检查是否是简单的成功响应(没有具体数据)
bool _isSimpleSuccessResponse(ApiPath path) {
This commit is contained in:
parent
78fe013ab2
commit
8785687ee4
|
|
@ -350,6 +350,11 @@ class RetrofitApiGenerator extends BaseGenerator {
|
|||
return 'BaseResult<void>';
|
||||
}
|
||||
|
||||
// 检查是否只是简单的成功响应(没有具体数据)
|
||||
if (_isSimpleSuccessResponse(path)) {
|
||||
return 'BaseResult';
|
||||
}
|
||||
|
||||
// 如果没有明确的 schema 定义,使用通用类型
|
||||
// 这通常表示后端文档不完整,应该要求后端完善 swagger 文档
|
||||
return 'BaseResult<Map<String, dynamic>>';
|
||||
|
|
@ -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<ApiPath> paths) {
|
||||
for (final path in paths) {
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
||||
Loading…
Reference in New Issue