3232
3333import java .io .File ;
3434import java .util .HashMap ;
35+ import java .util .HashSet ;
3536import java .util .List ;
3637import java .util .Map ;
38+ import java .util .Set ;
3739
3840import static io .swagger .codegen .plugin .AdditionalParams .*;
3941
@@ -155,40 +157,36 @@ public void execute() throws MojoExecutionException {
155157 if (null != invokerPackage ) {
156158 config .additionalProperties ().put (INVOKER_PACKAGE_PARAM , invokerPackage );
157159 }
158-
160+
161+ Set <String > definedOptions = new HashSet <String >();
162+ for (CliOption langCliOption : config .cliOptions ()) {
163+ definedOptions .add (langCliOption .getOpt ());
164+ }
165+
159166 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- }
166167 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 ());
168169 config .importMapping ().putAll (mappings );
169170 }
170171
171172 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 ());
173174 config .typeMapping ().putAll (mappings );
174175 }
175176
176177 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 ());
178179 config .instantiationTypes ().putAll (mappings );
179180 }
181+ addAdditionalProperties (config , definedOptions , configOptions );
180182 }
181183
182184 if (null != configurationFile ) {
183185 Config genConfig = ConfigParser .read (configurationFile );
184186 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 ());
190188 } else {
191- throw new RuntimeException ("Unable to read configuration file" );
189+ throw new RuntimeException ("Unable to read configuration file" );
192190 }
193191 }
194192
@@ -207,8 +205,8 @@ public void execute() throws MojoExecutionException {
207205 new DefaultGenerator ().opts (input ).generate ();
208206 } catch (Exception e ) {
209207 // 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:
212210 getLog ().error (e );
213211 throw new MojoExecutionException ("Code generation failed. See above for the full exception." );
214212 }
@@ -217,6 +215,15 @@ public void execute() throws MojoExecutionException {
217215 project .addCompileSourceRoot (output .toString ());
218216 }
219217 }
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+ }
220227
221228 private static Map <String , String > createMapFromKeyValuePairs (String commaSeparatedKVPairs ) {
222229 final List <Pair <String , String >> pairs = OptionUtils .parseCommaSeparatedTuples (commaSeparatedKVPairs );
0 commit comments