43 lines
1.1 KiB
Dart
43 lines
1.1 KiB
Dart
// 测试参数 schema $ref 解析
|
|
import 'package:swagger_generator_flutter/core/models.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
group(r'ApiParameter $ref 解析测试', () {
|
|
test(r'应该正确解析带有 $ref 的参数', () {
|
|
final json = {
|
|
'name': 'TaskTypeEnum',
|
|
'in': 'query',
|
|
'description': '任务类型枚举',
|
|
'schema': {
|
|
r'$ref': '#/components/schemas/SysTaskTypeEnums',
|
|
},
|
|
};
|
|
|
|
final param = ApiParameter.fromJson(json);
|
|
|
|
expect(param.name, 'TaskTypeEnum');
|
|
expect(param.schemaRef, '#/components/schemas/SysTaskTypeEnums');
|
|
expect(param.description, '任务类型枚举');
|
|
});
|
|
|
|
test(r'应该正确解析没有 $ref 的普通参数', () {
|
|
final json = {
|
|
'name': 'pageSize',
|
|
'in': 'query',
|
|
'description': '页面大小',
|
|
'schema': {
|
|
'type': 'integer',
|
|
'format': 'int32',
|
|
},
|
|
};
|
|
|
|
final param = ApiParameter.fromJson(json);
|
|
|
|
expect(param.name, 'pageSize');
|
|
expect(param.schemaRef, isNull);
|
|
expect(param.type, PropertyType.integer);
|
|
});
|
|
});
|
|
}
|