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:
@@ -4,22 +4,24 @@ import 'package:koi_swagger_parser/koi_swagger_parser.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
Future<void> main() async {
|
||||
final packageRoot = Directory.current.path;
|
||||
final tempDir = await Directory.systemTemp.createTemp(
|
||||
'koi_swagger_parser_example_',
|
||||
);
|
||||
final configFile = File(p.join(tempDir.path, 'koi_swagger_parser.yaml'));
|
||||
await configFile.writeAsString('''
|
||||
try {
|
||||
final exampleDirectory = _findExampleDirectory();
|
||||
final openApiPath = p.join(exampleDirectory.path, 'openapi.yaml');
|
||||
final outputDirectory = p.join(tempDir.path, 'generated');
|
||||
final configFile = File(p.join(tempDir.path, 'koi_swagger_parser.yaml'));
|
||||
await configFile.writeAsString('''
|
||||
input:
|
||||
swagger_urls:
|
||||
- url: ${p.join(packageRoot, 'test', 'fixtures', 'dba_openapi.json')}
|
||||
enabled: true
|
||||
- ${_yamlString(openApiPath)}
|
||||
|
||||
output:
|
||||
base_dir: ${p.join(tempDir.path, 'lib', 'src')}
|
||||
included_tags:
|
||||
- stores
|
||||
- materials
|
||||
base_dir: ${_yamlString(outputDirectory)}
|
||||
api_dir: ${_yamlString(p.join(outputDirectory, 'api'))}
|
||||
models_dir: ${_yamlString(p.join(outputDirectory, 'models'))}
|
||||
manifest_path: ${_yamlString(p.join(tempDir.path, 'manifest.json'))}
|
||||
|
||||
generation:
|
||||
api:
|
||||
@@ -27,17 +29,39 @@ generation:
|
||||
mode: passthrough
|
||||
|
||||
formatting:
|
||||
run_dart_format: false
|
||||
run_dart_format: true
|
||||
''');
|
||||
|
||||
final result = await const KoiSwaggerParser().generate(
|
||||
configPath: configFile.path,
|
||||
dryRun: true,
|
||||
);
|
||||
final result = await const KoiSwaggerParser().generate(
|
||||
configPath: configFile.path,
|
||||
);
|
||||
|
||||
print(
|
||||
'loaded ${result.sourceDocuments.length} source(s), '
|
||||
'parsed ${result.operationsCount} operation(s), '
|
||||
'rendered ${result.modelsCount} model(s).',
|
||||
print(
|
||||
'Loaded ${result.sourceDocuments.length} source(s), '
|
||||
'parsed ${result.operationsCount} operation(s), and '
|
||||
'generated ${result.writtenFiles.length} file(s) for '
|
||||
'${result.modelsCount} model(s):',
|
||||
);
|
||||
for (final file in result.writtenFiles) {
|
||||
print(' ${p.relative(file, from: outputDirectory)}');
|
||||
}
|
||||
} finally {
|
||||
await tempDir.delete(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
Directory _findExampleDirectory() {
|
||||
final scriptDirectory = File.fromUri(Platform.script).parent;
|
||||
final workingDirectory = Directory(p.join(Directory.current.path, 'example'));
|
||||
for (final directory in <Directory>[scriptDirectory, workingDirectory]) {
|
||||
if (File(p.join(directory.path, 'openapi.yaml')).existsSync()) {
|
||||
return directory;
|
||||
}
|
||||
}
|
||||
throw StateError(
|
||||
'Could not find example/openapi.yaml. Run this example from the package '
|
||||
'root with "dart run example/koi_swagger_parser_example.dart".',
|
||||
);
|
||||
}
|
||||
|
||||
String _yamlString(String value) => "'${value.replaceAll("'", "''")}'";
|
||||
|
||||
Reference in New Issue
Block a user