92 lines
2.7 KiB
Dart
92 lines
2.7 KiB
Dart
// 测试枚举参数生成
|
|
// ignore_for_file: avoid_print
|
|
|
|
import 'package:swagger_generator_flutter/pipeline/parse/swagger_data_parser.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
group('枚举参数生成测试', () {
|
|
test('TaskTypeEnum 应该生成为 int 类型而不是 String', () async {
|
|
// 模拟 swagger_v3.json 中的结构
|
|
final swaggerJson = {
|
|
'openapi': '3.0.1',
|
|
'info': {
|
|
'title': 'Test API',
|
|
'version': '1.0',
|
|
},
|
|
'paths': {
|
|
'/api/v3/WorkStatistics/CloudSchoolWorkDataStatistics': {
|
|
'get': {
|
|
'tags': ['WorkStatistics'],
|
|
'summary': '各云校统计',
|
|
'parameters': [
|
|
{
|
|
'name': 'TaskTypeEnum',
|
|
'in': 'query',
|
|
'description': '任务类型枚举',
|
|
'schema': {
|
|
r'$ref': '#/components/schemas/SysTaskTypeEnums',
|
|
},
|
|
},
|
|
],
|
|
'responses': {
|
|
'200': {
|
|
'description': 'Success',
|
|
'content': {
|
|
'application/json': {
|
|
'schema': {
|
|
'type': 'object',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
'components': {
|
|
'schemas': {
|
|
'SysTaskTypeEnums': {
|
|
'enum': [1, 2, 3, 4, 5],
|
|
'type': 'integer',
|
|
'description': '任务类型枚举',
|
|
'format': 'int32',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
// 解析 Swagger 文档
|
|
final parser = SwaggerDataParser();
|
|
final document = await parser.parseSwaggerDocument(
|
|
swaggerJson,
|
|
'test.json',
|
|
);
|
|
|
|
// 验证参数解析
|
|
final path = document.paths.values.first;
|
|
expect(path.parameters.length, 1);
|
|
|
|
final param = path.parameters.first;
|
|
expect(param.name, 'TaskTypeEnum');
|
|
expect(param.schemaRef, '#/components/schemas/SysTaskTypeEnums');
|
|
|
|
// 打印调试信息
|
|
print('Available models: ${document.models.keys.toList()}');
|
|
|
|
// 验证 SysTaskTypeEnums 模型
|
|
final enumModel = document.models['SysTaskTypeEnums'];
|
|
if (enumModel != null) {
|
|
print('EnumModel type: ${enumModel.type}');
|
|
print('EnumModel isEnum: ${enumModel.isEnum}');
|
|
print('EnumModel enumValues: ${enumModel.enumValues}');
|
|
expect(enumModel.type, 'integer');
|
|
expect(enumModel.isEnum, true);
|
|
expect(enumModel.enumValues, [1, 2, 3, 4, 5]);
|
|
} else {
|
|
print('WARNING: SysTaskTypeEnums model not found!');
|
|
}
|
|
});
|
|
});
|
|
}
|