|
1 | 1 | package io.swagger.codegen.cmd;
|
2 | 2 |
|
3 |
| -import io.airlift.airline.Command; |
4 |
| -import io.airlift.airline.Option; |
5 | 3 | import io.swagger.codegen.ClientOptInput;
|
6 |
| -import io.swagger.codegen.CodegenConstants; |
7 | 4 | import io.swagger.codegen.DefaultGenerator;
|
8 | 5 | import io.swagger.codegen.config.CodegenConfigurator;
|
9 | 6 | import org.slf4j.Logger;
|
10 | 7 | import org.slf4j.LoggerFactory;
|
11 | 8 |
|
12 |
| -import static io.swagger.codegen.config.CodegenConfiguratorUtils.*; |
13 |
| -import static org.apache.commons.lang3.StringUtils.isNotEmpty; |
14 |
| - |
15 | 9 | import java.util.ArrayList;
|
16 | 10 | import java.util.List;
|
17 | 11 |
|
| 12 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList; |
| 13 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvpList; |
| 14 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvpList; |
| 15 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsvList; |
| 16 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvpList; |
| 17 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applySystemPropertiesKvpList; |
| 18 | +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyTypeMappingsKvpList; |
| 19 | +import static org.apache.commons.lang3.StringUtils.isNotEmpty; |
| 20 | + |
18 | 21 | /**
|
19 | 22 | * User: lanwen Date: 24.03.15 Time: 20:22
|
20 | 23 | */
|
21 | 24 |
|
22 |
| -@Command(name = "generate", description = "Generate code with chosen lang") |
23 | 25 | public class Generate implements Runnable {
|
24 | 26 |
|
25 | 27 | public static final Logger LOG = LoggerFactory.getLogger(Generate.class);
|
26 | 28 |
|
27 |
| - @Option(name = {"-v", "--verbose"}, description = "verbose mode") |
28 | 29 | private Boolean verbose;
|
29 |
| - |
30 |
| - @Option(name = {"-l", "--lang"}, title = "language", required = true, |
31 |
| - description = "client language to generate (maybe class name in classpath, required)") |
32 | 30 | private String lang;
|
33 |
| - |
34 |
| - @Option(name = {"-o", "--output"}, title = "output directory", |
35 |
| - description = "where to write the generated files (current dir by default)") |
36 | 31 | private String output = "";
|
37 |
| - |
38 |
| - @Option(name = {"-i", "--input-spec"}, title = "spec file", required = true, |
39 |
| - description = "location of the swagger spec, as URL or file (required)") |
40 | 32 | private String spec;
|
41 |
| - |
42 |
| - @Option(name = {"-t", "--template-dir"}, title = "template directory", |
43 |
| - description = "folder containing the template files") |
44 | 33 | private String templateDir;
|
45 |
| - |
46 |
| - @Option( |
47 |
| - name = {"-a", "--auth"}, |
48 |
| - title = "authorization", |
49 |
| - description = "adds authorization headers when fetching the swagger definitions remotely. " |
50 |
| - + "Pass in a URL-encoded string of name:header with a comma separating multiple values") |
51 | 34 | private String auth;
|
52 |
| - |
53 |
| - @Option( |
54 |
| - name = {"-D"}, |
55 |
| - title = "system properties", |
56 |
| - description = "sets specified system properties in " |
57 |
| - + "the format of name=value,name=value (or multiple options, each with name=value)") |
58 | 35 | private List<String> systemProperties = new ArrayList<>();
|
59 |
| - |
60 |
| - @Option( |
61 |
| - name = {"-c", "--config"}, |
62 |
| - title = "configuration file", |
63 |
| - description = "Path to json configuration file. " |
64 |
| - + "File content should be in a json format {\"optionKey\":\"optionValue\", \"optionKey1\":\"optionValue1\"...} " |
65 |
| - + "Supported options can be different for each language. Run config-help -l {lang} command for language specific config options.") |
66 | 36 | private String configFile;
|
67 |
| - |
68 |
| - @Option(name = {"-s", "--skip-overwrite"}, title = "skip overwrite", |
69 |
| - description = "specifies if the existing files should be " |
70 |
| - + "overwritten during the generation.") |
71 | 37 | private Boolean skipOverwrite;
|
72 |
| - |
73 |
| - @Option(name = {"--api-package"}, title = "api package", |
74 |
| - description = CodegenConstants.API_PACKAGE_DESC) |
75 | 38 | private String apiPackage;
|
76 |
| - |
77 |
| - @Option(name = {"--model-package"}, title = "model package", |
78 |
| - description = CodegenConstants.MODEL_PACKAGE_DESC) |
79 | 39 | private String modelPackage;
|
80 |
| - |
81 |
| - @Option(name = {"--model-name-prefix"}, title = "model name prefix", |
82 |
| - description = CodegenConstants.MODEL_NAME_PREFIX_DESC) |
83 | 40 | private String modelNamePrefix;
|
84 |
| - |
85 |
| - @Option(name = {"--model-name-suffix"}, title = "model name suffix", |
86 |
| - description = CodegenConstants.MODEL_NAME_SUFFIX_DESC) |
87 | 41 | private String modelNameSuffix;
|
88 |
| - |
89 |
| - @Option( |
90 |
| - name = {"--instantiation-types"}, |
91 |
| - title = "instantiation types", |
92 |
| - description = "sets instantiation type mappings in the format of type=instantiatedType,type=instantiatedType." |
93 |
| - + "For example (in Java): array=ArrayList,map=HashMap. In other words array types will get instantiated as ArrayList in generated code." |
94 |
| - + " You can also have multiple occurrences of this option.") |
95 | 42 | private List<String> instantiationTypes = new ArrayList<>();
|
96 |
| - |
97 |
| - @Option( |
98 |
| - name = {"--type-mappings"}, |
99 |
| - title = "type mappings", |
100 |
| - description = "sets mappings between swagger spec types and generated code types " |
101 |
| - + "in the format of swaggerType=generatedType,swaggerType=generatedType. For example: array=List,map=Map,string=String." |
102 |
| - + " You can also have multiple occurrences of this option.") |
103 | 43 | private List<String> typeMappings = new ArrayList<>();
|
104 |
| - |
105 |
| - @Option( |
106 |
| - name = {"--additional-properties"}, |
107 |
| - title = "additional properties", |
108 |
| - description = "sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value." |
109 |
| - + " You can also have multiple occurrences of this option.") |
110 | 44 | private List<String> additionalProperties = new ArrayList<>();
|
111 |
| - |
112 |
| - @Option( |
113 |
| - name = {"--language-specific-primitives"}, |
114 |
| - title = "language specific primitives", |
115 |
| - description = "specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double." |
116 |
| - + " You can also have multiple occurrences of this option.") |
117 | 45 | private List<String> languageSpecificPrimitives = new ArrayList<>();
|
118 |
| - |
119 |
| - @Option( |
120 |
| - name = {"--import-mappings"}, |
121 |
| - title = "import mappings", |
122 |
| - description = "specifies mappings between a given class and the import that should be used for that class in the format of type=import,type=import." |
123 |
| - + " You can also have multiple occurrences of this option.") |
124 | 46 | private List<String> importMappings = new ArrayList<>();
|
125 |
| - |
126 |
| - @Option(name = {"--invoker-package"}, title = "invoker package", |
127 |
| - description = CodegenConstants.INVOKER_PACKAGE_DESC) |
128 | 47 | private String invokerPackage;
|
129 |
| - |
130 |
| - @Option(name = {"--group-id"}, title = "group id", description = CodegenConstants.GROUP_ID_DESC) |
131 | 48 | private String groupId;
|
132 |
| - |
133 |
| - @Option(name = {"--artifact-id"}, title = "artifact id", |
134 |
| - description = CodegenConstants.ARTIFACT_ID_DESC) |
135 | 49 | private String artifactId;
|
136 |
| - |
137 |
| - @Option(name = {"--artifact-version"}, title = "artifact version", |
138 |
| - description = CodegenConstants.ARTIFACT_VERSION_DESC) |
139 | 50 | private String artifactVersion;
|
140 |
| - |
141 |
| - @Option(name = {"--library"}, title = "library", description = CodegenConstants.LIBRARY_DESC) |
142 | 51 | private String library;
|
143 |
| - |
144 |
| - @Option(name = {"--git-user-id"}, title = "git user id", |
145 |
| - description = CodegenConstants.GIT_USER_ID_DESC) |
146 | 52 | private String gitUserId;
|
147 |
| - |
148 |
| - @Option(name = {"--git-repo-id"}, title = "git repo id", |
149 |
| - description = CodegenConstants.GIT_REPO_ID_DESC) |
150 | 53 | private String gitRepoId;
|
151 |
| - |
152 |
| - @Option(name = {"--release-note"}, title = "release note", |
153 |
| - description = CodegenConstants.RELEASE_NOTE_DESC) |
154 | 54 | private String releaseNote;
|
155 |
| - |
156 |
| - @Option(name = {"--http-user-agent"}, title = "http user agent", |
157 |
| - description = CodegenConstants.HTTP_USER_AGENT_DESC) |
158 | 55 | private String httpUserAgent;
|
159 |
| - |
160 |
| - @Option( |
161 |
| - name = {"--reserved-words-mappings"}, |
162 |
| - title = "reserved word mappings", |
163 |
| - description = "specifies how a reserved name should be escaped to. Otherwise, the default _<name> is used. For example id=identifier." |
164 |
| - + " You can also have multiple occurrences of this option.") |
165 | 56 | private List<String> reservedWordsMappings = new ArrayList<>();
|
166 |
| - |
167 |
| - @Option(name = {"--ignore-file-override"}, title = "ignore file override location", |
168 |
| - description = CodegenConstants.IGNORE_FILE_OVERRIDE_DESC) |
169 | 57 | private String ignoreFileOverride;
|
170 |
| - |
171 |
| - @Option(name = {"--remove-operation-id-prefix"}, title = "remove prefix of the operationId", |
172 |
| - description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC) |
173 | 58 | private Boolean removeOperationIdPrefix;
|
174 | 59 |
|
175 | 60 | @Override
|
|
0 commit comments