Skip to content

Commit c2c6074

Browse files
authored
Merge pull request #9532 from swagger-api/read_arguments_on_service
added capability to work with language argument options on service
2 parents dfffa89 + d799225 commit c2c6074

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/service/GeneratorUtil.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.swagger.codegen.CodegenConfigLoader;
77
import io.swagger.codegen.CodegenConstants;
88
import io.swagger.codegen.v3.ClientOptInput;
9+
import io.swagger.codegen.v3.CodegenArgument;
910
import io.swagger.codegen.v3.config.CodegenConfigurator;
1011
import io.swagger.codegen.v3.service.exception.BadRequestException;
1112
import io.swagger.models.Swagger;
@@ -198,6 +199,7 @@ public static ClientOptInput getClientOptInput(GenerationRequest generationReque
198199

199200
if (isNotEmpty(lang)) {
200201
configurator.setLang(lang);
202+
readCodegenArguments(configurator, options);
201203
}
202204
if (isNotEmpty(options.getAuth())) {
203205
configurator.setAuth(options.getAuth());
@@ -286,4 +288,26 @@ public static ClientOptInput getClientOptInput(GenerationRequest generationReque
286288
LOGGER.debug("getClientOptInput - end");
287289
return configurator.toClientOptInput();
288290
}
291+
292+
private static void readCodegenArguments(CodegenConfigurator configurator, Options options) {
293+
if (options == null) {
294+
return;
295+
}
296+
io.swagger.codegen.v3.CodegenConfig config = io.swagger.codegen.v3.CodegenConfigLoader.forName(configurator.getLang());
297+
if (config == null) {
298+
return;
299+
}
300+
final List<CodegenArgument> arguments = config.readLanguageArguments();
301+
if (arguments == null || arguments.isEmpty()) {
302+
return;
303+
}
304+
for (CodegenArgument codegenArgument : arguments) {
305+
final String value = options.getCodegenArguments().get(codegenArgument.getOption().substring(2));
306+
if (value == null) {
307+
continue;
308+
}
309+
codegenArgument.setValue(value);
310+
}
311+
configurator.setCodegenArguments(arguments);
312+
}
289313
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/service/Options.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class Options {
3737
private Boolean skipOverride;
3838
private String outputDir = "";
3939

40+
private Map<String, String> codegenArguments = new LinkedHashMap<>();
41+
4042
public Options authorizationValue(AuthorizationValue authorizationValue) {
4143
this.authorizationValue = authorizationValue;
4244
return this;
@@ -211,6 +213,25 @@ public Options addImportMapping(String key, String value) {
211213
return this;
212214
}
213215

216+
public Options codegenArguments(Map<String, String> codegenArguments) {
217+
this.codegenArguments = codegenArguments;
218+
return this;
219+
}
220+
221+
public Map<String, String> getCodegenArguments() {
222+
return codegenArguments;
223+
}
224+
225+
public void setCodegenArguments(Map<String, String> codegenArguments) {
226+
this.codegenArguments = codegenArguments;
227+
}
228+
229+
public Options addCodegenArgument(String key, String value) {
230+
this.codegenArguments.put(key, value);
231+
return this;
232+
}
233+
234+
214235
public Options invokerPackage(String invokerPackage) {
215236
this.invokerPackage = invokerPackage;
216237
return this;

0 commit comments

Comments
 (0)