Release 0.2.0
Complete OpenAPI 3.0/3.1 generation, diagnostics, lifecycle safety, enum and naming mappings, bilingual documentation, examples, and pub.dev release validation.
This commit is contained in:
@@ -72,5 +72,127 @@ formatting:
|
||||
expect(config.generation.models.classPrefix, 'Koi');
|
||||
expect(config.generation.formatting.runDartFormat, isFalse);
|
||||
});
|
||||
|
||||
test('解析生命周期、过滤与 build_runner 配置', () async {
|
||||
final tempDir = await Directory.systemTemp.createTemp(
|
||||
'koi_swagger_parser_config_lifecycle_',
|
||||
);
|
||||
addTearDown(() => tempDir.delete(recursive: true));
|
||||
await File(p.join(tempDir.path, 'koi_swagger_parser.yaml')).writeAsString(
|
||||
'''
|
||||
input:
|
||||
swagger_urls:
|
||||
- ./openapi.json
|
||||
output:
|
||||
included_paths:
|
||||
- /api/**
|
||||
excluded_operations:
|
||||
- regex:^DELETE\\s
|
||||
included_models:
|
||||
- '*Response'
|
||||
clean_stale_files: false
|
||||
skip_if_unchanged: false
|
||||
manifest_path: ./.generated/koi.json
|
||||
generation:
|
||||
api:
|
||||
enabled: true
|
||||
models:
|
||||
enabled: true
|
||||
formatting:
|
||||
run_dart_format: false
|
||||
run_build_runner: true
|
||||
build_runner_mode: watch
|
||||
delete_conflicting_outputs: false
|
||||
''',
|
||||
);
|
||||
|
||||
final config = await KoiSwaggerConfig.load(
|
||||
workingDirectory: tempDir.path,
|
||||
);
|
||||
|
||||
expect(config.output.includedPaths, <String>['/api/**']);
|
||||
expect(config.output.excludedOperations, <String>[r'regex:^DELETE\s']);
|
||||
expect(config.output.includedModels, <String>['*Response']);
|
||||
expect(config.output.cleanStaleFiles, isFalse);
|
||||
expect(config.output.skipIfUnchanged, isFalse);
|
||||
expect(
|
||||
config.output.manifestPath,
|
||||
p.join(tempDir.path, '.generated', 'koi.json'),
|
||||
);
|
||||
expect(config.generation.formatting.runBuildRunner, isTrue);
|
||||
expect(
|
||||
config.generation.formatting.buildRunnerMode,
|
||||
BuildRunnerMode.watch,
|
||||
);
|
||||
expect(config.generation.formatting.deleteConflictingOutputs, isFalse);
|
||||
});
|
||||
|
||||
test('错误标量类型和无效 regex 产生结构化诊断', () async {
|
||||
final tempDir = await Directory.systemTemp.createTemp(
|
||||
'koi_swagger_parser_config_invalid_',
|
||||
);
|
||||
addTearDown(() => tempDir.delete(recursive: true));
|
||||
final configFile = File(p.join(tempDir.path, 'koi_swagger_parser.yaml'));
|
||||
await configFile.writeAsString('''
|
||||
input:
|
||||
swagger_urls:
|
||||
- url: ./openapi.json
|
||||
enabled: yes
|
||||
output:
|
||||
split_by_tags: wrong
|
||||
included_paths:
|
||||
- regex:[
|
||||
generation:
|
||||
api:
|
||||
enabled: true
|
||||
models:
|
||||
enabled: true
|
||||
''');
|
||||
|
||||
await expectLater(
|
||||
KoiSwaggerConfig.load(workingDirectory: tempDir.path),
|
||||
throwsA(
|
||||
isA<KoiDiagnosticException>().having(
|
||||
(error) => error.diagnostics.map((item) => item.code),
|
||||
'diagnostic codes',
|
||||
containsAll(<String>[
|
||||
'config.invalid_boolean',
|
||||
'config.invalid_filter_regex',
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('API enabled 时明确拒绝未实现的非 Retrofit renderer', () async {
|
||||
final tempDir = await Directory.systemTemp.createTemp(
|
||||
'koi_swagger_parser_config_renderer_',
|
||||
);
|
||||
addTearDown(() => tempDir.delete(recursive: true));
|
||||
await File(p.join(tempDir.path, 'koi_swagger_parser.yaml')).writeAsString(
|
||||
'''
|
||||
input:
|
||||
swagger_urls:
|
||||
- ./openapi.json
|
||||
generation:
|
||||
api:
|
||||
enabled: true
|
||||
use_retrofit: false
|
||||
models:
|
||||
enabled: true
|
||||
''',
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
KoiSwaggerConfig.load(workingDirectory: tempDir.path),
|
||||
throwsA(
|
||||
isA<KoiDiagnosticException>().having(
|
||||
(error) => error.diagnostics.map((item) => item.code),
|
||||
'diagnostic codes',
|
||||
contains('config.unsupported_api_renderer'),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user