Skip to content

Commit

Permalink
added capability to work with language argument options on generator …
Browse files Browse the repository at this point in the history
…service.
  • Loading branch information
HugoMario committed Jun 27, 2019
1 parent dfffa89 commit 6732f1e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class CodegenArgument {

private String option;
private String generatorOption;
private String shortOption;
private String description;
private String type;
Expand All @@ -22,6 +23,19 @@ public CodegenArgument option(String option) {
return this;
}

public String getGeneratorOption() {
return generatorOption;
}

public void setGeneratorOption(String generatorOption) {
this.generatorOption = generatorOption;
}

public CodegenArgument generatorOption(String generatorOption) {
this.generatorOption = generatorOption;
return this;
}

public String getShortOption() {
return shortOption;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.codegen.CodegenConfigLoader;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.v3.ClientOptInput;
import io.swagger.codegen.v3.CodegenArgument;
import io.swagger.codegen.v3.config.CodegenConfigurator;
import io.swagger.codegen.v3.service.exception.BadRequestException;
import io.swagger.models.Swagger;
Expand Down Expand Up @@ -198,6 +199,7 @@ public static ClientOptInput getClientOptInput(GenerationRequest generationReque

if (isNotEmpty(lang)) {
configurator.setLang(lang);
readCodegenArguments(configurator, options);
}
if (isNotEmpty(options.getAuth())) {
configurator.setAuth(options.getAuth());
Expand Down Expand Up @@ -286,4 +288,26 @@ public static ClientOptInput getClientOptInput(GenerationRequest generationReque
LOGGER.debug("getClientOptInput - end");
return configurator.toClientOptInput();
}

private static void readCodegenArguments(CodegenConfigurator configurator, Options options) {
if (options == null) {
return;
}
io.swagger.codegen.v3.CodegenConfig config = io.swagger.codegen.v3.CodegenConfigLoader.forName(configurator.getLang());
if (config == null) {
return;
}
final List<CodegenArgument> arguments = config.readLanguageArguments();
if (arguments == null || arguments.isEmpty()) {
return;
}
for (CodegenArgument codegenArgument : arguments) {
final Object value = options.get(codegenArgument.getGeneratorOption());
if (value == null) {
continue;
}
codegenArgument.setValue(value.toString());
}
configurator.setCodegenArguments(arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.Map;

public class Options {
public class Options extends LinkedHashMap {

private String auth;
private AuthorizationValue authorizationValue = null;
Expand Down

0 comments on commit 6732f1e

Please sign in to comment.