|
29 | 29 | import org.openapitools.codegen.utils.ModelUtils; |
30 | 30 | import org.slf4j.Logger; |
31 | 31 | import org.slf4j.LoggerFactory; |
| 32 | + |
32 | 33 | import java.lang.Exception; |
33 | 34 |
|
34 | 35 | import java.io.File; |
@@ -298,7 +299,7 @@ public void processOpts() { |
298 | 299 | } |
299 | 300 |
|
300 | 301 | if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) { |
301 | | - setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING)); |
| 302 | + setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING)); |
302 | 303 | } |
303 | 304 |
|
304 | 305 | // This either updates additionalProperties with the above fixes, or sets the default if the option was not specified. |
@@ -345,49 +346,49 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) { |
345 | 346 | } |
346 | 347 |
|
347 | 348 | /* |
348 | | - * F# does not allow forward declarations, so files must be imported in the correct order. |
349 | | - * Output of CodeGen models must therefore bein dependency order (rather than alphabetical order, which seems to be the default). |
350 | | - * This could probably be made more efficient if absolutely needed. |
351 | | - */ |
| 349 | + * F# does not allow forward declarations, so files must be imported in the correct order. |
| 350 | + * Output of CodeGen models must therefore bein dependency order (rather than alphabetical order, which seems to be the default). |
| 351 | + * This could probably be made more efficient if absolutely needed. |
| 352 | + */ |
352 | 353 | @SuppressWarnings({"unchecked"}) |
353 | | - public Map<String,Object> postProcessDependencyOrders(final Map<String, Object> objs) { |
354 | | - |
355 | | - Map<String,Set<String>> dependencies = new HashMap<String,Set<String>>(); |
356 | | - |
357 | | - List<String> classNames = new ArrayList<String>(); |
358 | | - |
359 | | - for(String k : objs.keySet()) { |
360 | | - CodegenModel model = ModelUtils.getModelByName(k, objs); |
361 | | - if(model == null || model.classname == null) { |
362 | | - throw new RuntimeException("Null model encountered"); |
| 354 | + public Map<String, Object> postProcessDependencyOrders(final Map<String, Object> objs) { |
| 355 | + |
| 356 | + Map<String, Set<String>> dependencies = new HashMap<String, Set<String>>(); |
| 357 | + |
| 358 | + List<String> classNames = new ArrayList<String>(); |
| 359 | + |
| 360 | + for (String k : objs.keySet()) { |
| 361 | + CodegenModel model = ModelUtils.getModelByName(k, objs); |
| 362 | + if (model == null || model.classname == null) { |
| 363 | + throw new RuntimeException("Null model encountered"); |
| 364 | + } |
| 365 | + dependencies.put(model.classname, model.imports); |
| 366 | + |
| 367 | + classNames.add(model.classname); |
| 368 | + } |
| 369 | + |
| 370 | + Object[] sortedKeys = classNames.toArray(); |
| 371 | + |
| 372 | + for (int i1 = 0; i1 < sortedKeys.length; i1++) { |
| 373 | + String k1 = sortedKeys[i1].toString(); |
| 374 | + for (int i2 = i1 + 1; i2 < sortedKeys.length; i2++) { |
| 375 | + String k2 = sortedKeys[i2].toString(); |
| 376 | + if (dependencies.get(k2).contains(k1)) { |
| 377 | + sortedKeys[i2] = k1; |
| 378 | + sortedKeys[i1] = k2; |
| 379 | + i1 = -1; |
| 380 | + break; |
| 381 | + } |
| 382 | + } |
363 | 383 | } |
364 | | - dependencies.put(model.classname, model.imports); |
365 | | - |
366 | | - classNames.add(model.classname); |
367 | | - } |
368 | | - |
369 | | - Object[] sortedKeys = classNames.toArray(); |
370 | | - |
371 | | - for(int i1 = 0 ; i1 < sortedKeys.length; i1++) { |
372 | | - String k1 = sortedKeys[i1].toString(); |
373 | | - for(int i2 = i1 + 1; i2 < sortedKeys.length; i2++) { |
374 | | - String k2 = sortedKeys[i2].toString(); |
375 | | - if(dependencies.get(k2).contains(k1)) { |
376 | | - sortedKeys[i2] = k1; |
377 | | - sortedKeys[i1] = k2; |
378 | | - i1 = -1; |
379 | | - break; |
380 | | - } |
| 384 | + |
| 385 | + Map<String, Object> sorted = new LinkedHashMap<String, Object>(); |
| 386 | + for (int i = sortedKeys.length - 1; i >= 0; i--) { |
| 387 | + Object k = sortedKeys[i]; |
| 388 | + sorted.put(k.toString(), objs.get(k)); |
381 | 389 | } |
382 | | - } |
383 | | - |
384 | | - Map<String,Object> sorted = new LinkedHashMap<String,Object>(); |
385 | | - for(int i = sortedKeys.length - 1; i >= 0; i--) { |
386 | | - Object k = sortedKeys[i]; |
387 | | - sorted.put(k.toString(), objs.get(k)); |
388 | | - } |
389 | | - |
390 | | - return sorted; |
| 390 | + |
| 391 | + return sorted; |
391 | 392 | } |
392 | 393 |
|
393 | 394 | /** |
@@ -656,23 +657,23 @@ public void setModelPropertyNaming(String naming) { |
656 | 657 | } |
657 | 658 | } |
658 | 659 |
|
659 | | - |
| 660 | + |
660 | 661 | public String getNameUsingModelPropertyNaming(String name) { |
661 | | - switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) { |
662 | | - case original: |
663 | | - return name; |
664 | | - case camelCase: |
665 | | - return camelize(name, true); |
666 | | - case PascalCase: |
667 | | - return camelize(name); |
668 | | - case snake_case: |
669 | | - return underscore(name); |
670 | | - default: |
671 | | - throw new IllegalArgumentException("Invalid model property naming '" + |
672 | | - name + "'. Must be 'original', 'camelCase', " + |
673 | | - "'PascalCase' or 'snake_case'"); |
674 | | - } |
675 | | - } |
| 662 | + switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) { |
| 663 | + case original: |
| 664 | + return name; |
| 665 | + case camelCase: |
| 666 | + return camelize(name, true); |
| 667 | + case PascalCase: |
| 668 | + return camelize(name); |
| 669 | + case snake_case: |
| 670 | + return underscore(name); |
| 671 | + default: |
| 672 | + throw new IllegalArgumentException("Invalid model property naming '" + |
| 673 | + name + "'. Must be 'original', 'camelCase', " + |
| 674 | + "'PascalCase' or 'snake_case'"); |
| 675 | + } |
| 676 | + } |
676 | 677 |
|
677 | 678 | @Override |
678 | 679 | public String toVarName(String name) { |
|
0 commit comments