32
32
33
33
import java .io .File ;
34
34
import java .util .HashMap ;
35
+ import java .util .HashSet ;
35
36
import java .util .List ;
36
37
import java .util .Map ;
38
+ import java .util .Set ;
37
39
38
40
import static io .swagger .codegen .plugin .AdditionalParams .*;
39
41
@@ -155,40 +157,36 @@ public void execute() throws MojoExecutionException {
155
157
if (null != invokerPackage ) {
156
158
config .additionalProperties ().put (INVOKER_PACKAGE_PARAM , invokerPackage );
157
159
}
158
-
160
+
161
+ Set <String > definedOptions = new HashSet <String >();
162
+ for (CliOption langCliOption : config .cliOptions ()) {
163
+ definedOptions .add (langCliOption .getOpt ());
164
+ }
165
+
159
166
if (configOptions != null ) {
160
- for (CliOption langCliOption : config .cliOptions ()) {
161
- if (configOptions .containsKey (langCliOption .getOpt ())) {
162
- config .additionalProperties ().put (langCliOption .getOpt (),
163
- configOptions .get (langCliOption .getOpt ()));
164
- }
165
- }
166
167
if (configOptions .containsKey ("import-mappings" )) {
167
- Map <String , String > mappings = createMapFromKeyValuePairs (configOptions .get ("import-mappings" ).toString ());
168
+ Map <String , String > mappings = createMapFromKeyValuePairs (configOptions .remove ("import-mappings" ).toString ());
168
169
config .importMapping ().putAll (mappings );
169
170
}
170
171
171
172
if (configOptions .containsKey ("type-mappings" )) {
172
- Map <String , String > mappings = createMapFromKeyValuePairs (configOptions .get ("type-mappings" ).toString ());
173
+ Map <String , String > mappings = createMapFromKeyValuePairs (configOptions .remove ("type-mappings" ).toString ());
173
174
config .typeMapping ().putAll (mappings );
174
175
}
175
176
176
177
if (configOptions .containsKey ("instantiation-types" )) {
177
- Map <String , String > mappings = createMapFromKeyValuePairs (configOptions .get ("instantiation-types" ).toString ());
178
+ Map <String , String > mappings = createMapFromKeyValuePairs (configOptions .remove ("instantiation-types" ).toString ());
178
179
config .instantiationTypes ().putAll (mappings );
179
180
}
181
+ addAdditionalProperties (config , definedOptions , configOptions );
180
182
}
181
183
182
184
if (null != configurationFile ) {
183
185
Config genConfig = ConfigParser .read (configurationFile );
184
186
if (null != genConfig ) {
185
- for (CliOption langCliOption : config .cliOptions ()) {
186
- if (genConfig .hasOption (langCliOption .getOpt ())) {
187
- config .additionalProperties ().put (langCliOption .getOpt (), genConfig .getOption (langCliOption .getOpt ()));
188
- }
189
- }
187
+ addAdditionalProperties (config , definedOptions , genConfig .getOptions ());
190
188
} else {
191
- throw new RuntimeException ("Unable to read configuration file" );
189
+ throw new RuntimeException ("Unable to read configuration file" );
192
190
}
193
191
}
194
192
@@ -207,8 +205,8 @@ public void execute() throws MojoExecutionException {
207
205
new DefaultGenerator ().opts (input ).generate ();
208
206
} catch (Exception e ) {
209
207
// Maven logs exceptions thrown by plugins only if invoked with -e
210
- // I find it annoying to jump through hoops to get basic diagnostic information,
211
- // so let's log it in any case:
208
+ // I find it annoying to jump through hoops to get basic diagnostic information,
209
+ // so let's log it in any case:
212
210
getLog ().error (e );
213
211
throw new MojoExecutionException ("Code generation failed. See above for the full exception." );
214
212
}
@@ -217,6 +215,15 @@ public void execute() throws MojoExecutionException {
217
215
project .addCompileSourceRoot (output .toString ());
218
216
}
219
217
}
218
+
219
+ private void addAdditionalProperties (CodegenConfig config , Set <String > definedOptions , Map <?,?> configOptions ) {
220
+ for (Map .Entry <?, ?> configEntry : configOptions .entrySet ()) {
221
+ config .additionalProperties ().put (configEntry .getKey ().toString (), configEntry .getValue ());
222
+ if (!definedOptions .contains (configEntry .getKey ())) {
223
+ getLog ().warn ("Additional property: " + configEntry .getKey () + " is not defined for this language." );
224
+ }
225
+ }
226
+ }
220
227
221
228
private static Map <String , String > createMapFromKeyValuePairs (String commaSeparatedKVPairs ) {
222
229
final List <Pair <String , String >> pairs = OptionUtils .parseCommaSeparatedTuples (commaSeparatedKVPairs );
0 commit comments