Skip to content

Commit

Permalink
Extract schemas from url (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarProxima authored Jan 9, 2024
1 parent b2d2203 commit 2931877
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
22 changes: 22 additions & 0 deletions swagger_parser/bin/extract_schemas_from_url.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:swagger_parser/src/config/yaml_config.dart';
import 'package:swagger_parser/src/utils/utils.dart';
import 'package:swagger_parser/swagger_parser.dart';

/// Used for run `dart run swagger_parser`
Future<void> main(List<String> arguments) async {
introMessage();
try {
/// Run generate from YAML config
final configs = YamlConfig.parseConfigsFromYamlFile(arguments);

generateMessage();
for (final config in configs) {
final generator = Generator.fromYamlConfig(config);
await generator.fetchSchemaContent();
}

doneExtractMessage();
} on Exception catch (e) {
exitWithError('Failed to extract schemas from url.\n$e');
}
}
6 changes: 3 additions & 3 deletions swagger_parser/lib/src/generator/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ final class Generator {
Future<(OpenApiInfo, GenerationStatistics)> generateFiles() async {
final stopwatch = Stopwatch()..start();

await _fetchSchemaContent();
await fetchSchemaContent();
_parseOpenApiDefinitionFile();
await _generateFiles();

Expand All @@ -219,12 +219,12 @@ final class Generator {
/// Generates content of files based on OpenApi definition file
/// and return list of [GeneratedFile]
Future<List<GeneratedFile>> generateContent() async {
await _fetchSchemaContent();
await fetchSchemaContent();
_parseOpenApiDefinitionFile();
return _fillContent();
}

Future<void> _fetchSchemaContent() async {
Future<void> fetchSchemaContent() async {
final url = _schemaUrl;
final path = _schemaPath;

Expand Down
4 changes: 4 additions & 0 deletions swagger_parser/lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ void doneMessage({
}
}

void doneExtractMessage() {
stdout.writeln('${_green}The extraction was completed successfully.$_reset');
}

void exitWithError(String message) {
stderr.writeln('${_red}ERROR: $message$_reset');
exit(2);
Expand Down

0 comments on commit 2931877

Please sign in to comment.