|
5 | 5 | import io.swagger.codegen.ClientOpts;
|
6 | 6 | import io.swagger.codegen.Codegen;
|
7 | 7 | import io.swagger.codegen.CodegenConfig;
|
| 8 | +import io.swagger.codegen.CodegenConfigLoader; |
8 | 9 | import io.swagger.generator.exception.ApiException;
|
9 | 10 | import io.swagger.generator.exception.BadRequestException;
|
10 | 11 | import io.swagger.generator.model.GeneratorInput;
|
|
16 | 17 | import org.slf4j.Logger;
|
17 | 18 | import org.slf4j.LoggerFactory;
|
18 | 19 |
|
| 20 | +import static org.apache.commons.lang3.StringUtils.isNotEmpty; |
| 21 | + |
19 | 22 | import java.io.File;
|
20 | 23 | import java.util.ArrayList;
|
21 | 24 | import java.util.List;
|
@@ -52,10 +55,24 @@ public static String generateClient(String language, GeneratorInput opts) throws
|
52 | 55 | .opts(clientOpts)
|
53 | 56 | .swagger(swagger);
|
54 | 57 |
|
55 |
| - CodegenConfig codegenConfig = Codegen.getConfig(language); |
56 |
| - if (codegenConfig == null) { |
| 58 | + CodegenConfig codegenConfig=null; |
| 59 | + try { |
| 60 | + codegenConfig = CodegenConfigLoader.forName(language); |
| 61 | + } catch(RuntimeException e) { |
57 | 62 | throw new BadRequestException(400, "Unsupported target " + language + " supplied");
|
58 | 63 | }
|
| 64 | + |
| 65 | + if (opts.getOptions() != null) { |
| 66 | + for(String key : new String[]{"apiPackage", "modelPackage", "invokerPackage", "groupId", "artifactId", "artifactVersion"}) { |
| 67 | + if(isNotEmpty(opts.getOptions().get(key))) { |
| 68 | + codegenConfig.additionalProperties().put(key , opts.getOptions().get(key)); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if (isNotEmpty(opts.getOptions().get("library"))) { |
| 73 | + codegenConfig.setLibrary(opts.getOptions().get("library")); |
| 74 | + } |
| 75 | + } |
59 | 76 |
|
60 | 77 | codegenConfig.setOutputDir(outputFolder);
|
61 | 78 |
|
|
0 commit comments