Skip to content

Commit 99f6bec

Browse files
committed
fix(cli): Fixed additionalCommands in config not appending to generator commands
1 parent a4a8e56 commit 99f6bec

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

openapi-generator-cli/bin/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ Future<void> runMain({
209209

210210
// Prepare additional arguments, excluding the --config flag and its value
211211
final filteredArguments = <String>[
212-
...additionalCommands.split(' '),
213212
...arguments.where((arg) => arg != '--config' && arg != configFilePath),
213+
additionalCommands,
214214
];
215215

216216
// Execute with classpath

openapi-generator-cli/test/openapi_generator_cli_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,50 @@ void main() {
203203
expect(exitCode, equals(1));
204204
expect(logBuffer.toString(), contains('Error: FileSystemException'));
205205
});
206+
207+
// New Test: Check execution of additional commands from config
208+
test(
209+
'additional commands in config are appended to end of generation command.',
210+
() async {
211+
final mockCommands = 'validate generate';
212+
final configData = {
213+
ConfigKeys.openapiGeneratorVersion: '5.0.0',
214+
ConfigKeys.additionalCommands: mockCommands,
215+
ConfigKeys.jarCachePath: '.dart_tool/openapi_generator_cache',
216+
};
217+
218+
var executedCommands = <String>[];
219+
Future<void> mockExecuteWithClasspath(
220+
List<String> jarPaths, List<String> args) async {
221+
executedCommands.addAll(args);
222+
}
223+
224+
await runMain(
225+
arguments: ['gen'],
226+
loadConfig: (p0) async => configData,
227+
downloadJar: (p0, p1) async {},
228+
executeWithClasspath: mockExecuteWithClasspath,
229+
log: (p0) => print(p0),
230+
);
231+
232+
// Verify commands executed from config
233+
expect(executedCommands, equals(['gen', 'validate generate']));
234+
});
235+
236+
test('ProcessRunner run method executes and prints out dart version',
237+
() async {
238+
// Define the expected input arguments
239+
const executable = 'dart';
240+
final arguments = ['--version'];
241+
242+
// Create an instance of ProcessRunner
243+
final processRunner = ProcessRunner();
244+
245+
// Execute the run method and verify the result
246+
final result = await processRunner.run(executable, arguments);
247+
expect(result.stdout, contains('Dart SDK version'));
248+
expect(result.exitCode, equals(0));
249+
});
206250
}
207251

208252
class TestProcessRunner extends ProcessRunner {

0 commit comments

Comments
 (0)