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:
@@ -0,0 +1,69 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:koi_swagger_parser/koi_swagger_parser.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('e2e fixture generated file hashes match the reviewed golden', () async {
|
||||
final tempDirectory = await Directory.systemTemp.createTemp(
|
||||
'koi_swagger_parser_golden_',
|
||||
);
|
||||
addTearDown(() => tempDirectory.delete(recursive: true));
|
||||
final root = Directory.current.path;
|
||||
final fixture = p.join(root, 'test', 'fixtures', 'e2e_openapi.json');
|
||||
final output = p.join(tempDirectory.path, 'lib', 'src');
|
||||
final config = File(p.join(tempDirectory.path, 'koi_swagger_parser.yaml'));
|
||||
await config.writeAsString('''
|
||||
input:
|
||||
swagger_urls:
|
||||
- url: $fixture
|
||||
output:
|
||||
base_dir: $output
|
||||
api_dir: ${p.join(output, 'api')}
|
||||
models_dir: ${p.join(output, 'models')}
|
||||
manifest_path: ${p.join(tempDirectory.path, '.generated', 'manifest.json')}
|
||||
generation:
|
||||
api:
|
||||
response_mode: http_response
|
||||
binary_response_mode: bytes
|
||||
cancel_token_support: true
|
||||
response_wrapper:
|
||||
mode: passthrough
|
||||
models:
|
||||
class_prefix: Koi
|
||||
enum_unknown_fallback: true
|
||||
formatting:
|
||||
run_dart_format: false
|
||||
''');
|
||||
|
||||
final result = await const KoiSwaggerParser().generate(
|
||||
configPath: config.path,
|
||||
);
|
||||
final actual = <String, String>{};
|
||||
for (final path in result.generatedFiles) {
|
||||
final relative = p.relative(path, from: output).replaceAll('\\', '/');
|
||||
actual[relative] = sha256
|
||||
.convert(await File(path).readAsBytes())
|
||||
.toString();
|
||||
}
|
||||
final sortedActual = <String, String>{
|
||||
for (final key in (actual.keys.toList()..sort())) key: actual[key]!,
|
||||
};
|
||||
final goldenFile = File(
|
||||
p.join(root, 'test', 'goldens', 'e2e_generated_files.sha256.json'),
|
||||
);
|
||||
final expected = (jsonDecode(await goldenFile.readAsString()) as Map)
|
||||
.cast<String, dynamic>();
|
||||
|
||||
expect(
|
||||
sortedActual,
|
||||
expected,
|
||||
reason:
|
||||
'If this output change is intentional, review generated Dart first '
|
||||
'and then update the golden hashes.',
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user