@@ -69,6 +69,8 @@ public class DefaultCodegen {
69
69
protected Map <String , String > modelTemplateFiles = new HashMap <String , String >();
70
70
protected Map <String , String > apiTestTemplateFiles = new HashMap <String , String >();
71
71
protected Map <String , String > modelTestTemplateFiles = new HashMap <String , String >();
72
+ protected Map <String , String > apiDocTemplateFiles = new HashMap <String , String >();
73
+ protected Map <String , String > modelDocTemplateFiles = new HashMap <String , String >();
72
74
protected String templateDir ;
73
75
protected String embeddedTemplateDir ;
74
76
protected Map <String , Object > additionalProperties = new HashMap <String , Object >();
@@ -228,6 +230,14 @@ public String embeddedTemplateDir() {
228
230
}
229
231
}
230
232
233
+ public Map <String , String > apiDocTemplateFiles () {
234
+ return apiDocTemplateFiles ;
235
+ }
236
+
237
+ public Map <String , String > modelDocTemplateFiles () {
238
+ return modelDocTemplateFiles ;
239
+ }
240
+
231
241
public Map <String , String > apiTestTemplateFiles () {
232
242
return apiTestTemplateFiles ;
233
243
}
@@ -260,6 +270,14 @@ public String modelTestFileFolder() {
260
270
return outputFolder + "/" + testPackage ().replace ('.' , '/' );
261
271
}
262
272
273
+ public String apiDocFileFolder () {
274
+ return outputFolder ;
275
+ }
276
+
277
+ public String modelDocFileFolder () {
278
+ return outputFolder ;
279
+ }
280
+
263
281
public Map <String , Object > additionalProperties () {
264
282
return additionalProperties ;
265
283
}
@@ -322,6 +340,16 @@ public String toApiFilename(String name) {
322
340
return toApiName (name );
323
341
}
324
342
343
+ /**
344
+ * Return the file name of the Api Documentation
345
+ *
346
+ * @param name the file name of the Api
347
+ * @return the file name of the Api
348
+ */
349
+ public String toApiDocFilename (String name ) {
350
+ return toApiName (name );
351
+ }
352
+
325
353
/**
326
354
* Return the file name of the Api Test
327
355
*
@@ -362,6 +390,16 @@ public String toModelTestFilename(String name) {
362
390
return initialCaps (name ) + "Test" ;
363
391
}
364
392
393
+ /**
394
+ * Return the capitalized file name of the model documentation
395
+ *
396
+ * @param name the model name
397
+ * @return the file name of the model
398
+ */
399
+ public String toModelDocFilename (String name ) {
400
+ return initialCaps (name );
401
+ }
402
+
365
403
/**
366
404
* Return the operation ID (method name)
367
405
*
@@ -614,13 +652,21 @@ public String toInstantiationType(Property p) {
614
652
}
615
653
}
616
654
655
+ /**
656
+ * Return the example value of the parameter.
657
+ *
658
+ * @param p Swagger property object
659
+ */
660
+ public void setParameterExampleValue (CodegenParameter p ) {
661
+
662
+ }
663
+
617
664
/**
618
665
* Return the example value of the property
619
666
*
620
667
* @param p Swagger property object
621
668
* @return string presentation of the example value of the property
622
669
*/
623
- @ SuppressWarnings ("static-method" )
624
670
public String toExampleValue (Property p ) {
625
671
if (p .getExample () != null ) {
626
672
return p .getExample ().toString ();
@@ -1452,6 +1498,14 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
1452
1498
}
1453
1499
}
1454
1500
}
1501
+
1502
+ // set isPrimitiveType and baseType for allParams
1503
+ /*if (languageSpecificPrimitives.contains(p.baseType)) {
1504
+ p.isPrimitiveType = true;
1505
+ p.baseType = getSwaggerType(p);
1506
+ }*/
1507
+
1508
+
1455
1509
allParams .add (p );
1456
1510
if (param instanceof QueryParameter ) {
1457
1511
p .isQueryParam = new Boolean (true );
@@ -1723,7 +1777,9 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
1723
1777
prop .setRequired (bp .getRequired ());
1724
1778
CodegenProperty cp = fromProperty ("property" , prop );
1725
1779
if (cp != null ) {
1780
+ p .baseType = cp .baseType ;
1726
1781
p .dataType = cp .datatype ;
1782
+ p .isPrimitiveType = cp .isPrimitiveType ;
1727
1783
p .isBinary = cp .datatype .toLowerCase ().startsWith ("byte" );
1728
1784
}
1729
1785
@@ -1743,6 +1799,8 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
1743
1799
}
1744
1800
imports .add (cp .baseType );
1745
1801
p .dataType = cp .datatype ;
1802
+ p .baseType = cp .complexType ;
1803
+ p .isPrimitiveType = cp .isPrimitiveType ;
1746
1804
p .isContainer = true ;
1747
1805
p .isListContainer = true ;
1748
1806
@@ -1763,11 +1821,47 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
1763
1821
name = getTypeDeclaration (name );
1764
1822
}
1765
1823
p .dataType = name ;
1824
+ p .baseType = name ;
1766
1825
}
1767
1826
}
1768
1827
p .paramName = toParamName (bp .getName ());
1769
1828
}
1770
1829
1830
+ // set the example value
1831
+ // if not specified in x-example, generate a default value
1832
+ if (p .vendorExtensions .containsKey ("x-example" )) {
1833
+ p .example = (String ) p .vendorExtensions .get ("x-example" );
1834
+ } else if (Boolean .TRUE .equals (p .isString )) {
1835
+ p .example = p .paramName + "_example" ;
1836
+ } else if (Boolean .TRUE .equals (p .isBoolean )) {
1837
+ p .example = new String ("true" );
1838
+ } else if (Boolean .TRUE .equals (p .isLong )) {
1839
+ p .example = new String ("789" );
1840
+ } else if (Boolean .TRUE .equals (p .isInteger )) {
1841
+ p .example = new String ("56" );
1842
+ } else if (Boolean .TRUE .equals (p .isFloat )) {
1843
+ p .example = new String ("3.4" );
1844
+ } else if (Boolean .TRUE .equals (p .isDouble )) {
1845
+ p .example = new String ("1.2" );
1846
+ } else if (Boolean .TRUE .equals (p .isBinary )) {
1847
+ p .example = new String ("BINARY_DATA_HERE" );
1848
+ } else if (Boolean .TRUE .equals (p .isByteArray )) {
1849
+ p .example = new String ("B" );
1850
+ } else if (Boolean .TRUE .equals (p .isDate )) {
1851
+ p .example = new String ("2013-10-20" );
1852
+ } else if (Boolean .TRUE .equals (p .isDateTime )) {
1853
+ p .example = new String ("2013-10-20T19:20:30+01:00" );
1854
+ } else if (param instanceof FormParameter &&
1855
+ ("file" .equalsIgnoreCase (((FormParameter ) param ).getType ()) ||
1856
+ "file" .equals (p .baseType ))) {
1857
+ p .isFile = true ;
1858
+ p .example = new String ("/path/to/file.txt" );
1859
+ }
1860
+
1861
+ // set the parameter excample value
1862
+ // should be overridden by lang codegen
1863
+ setParameterExampleValue (p );
1864
+
1771
1865
postProcessParameter (p );
1772
1866
return p ;
1773
1867
}
@@ -2196,6 +2290,19 @@ public String apiFilename(String templateName, String tag) {
2196
2290
return apiFileFolder () + '/' + toApiFilename (tag ) + suffix ;
2197
2291
}
2198
2292
2293
+ /**
2294
+ * Return the full path and API documentation file
2295
+ *
2296
+ * @param templateName template name
2297
+ * @param tag tag
2298
+ *
2299
+ * @return the API documentation file name with full path
2300
+ */
2301
+ public String apiDocFilename (String templateName , String tag ) {
2302
+ String suffix = apiDocTemplateFiles ().get (templateName );
2303
+ return apiDocFileFolder () + '/' + toApiDocFilename (tag ) + suffix ;
2304
+ }
2305
+
2199
2306
/**
2200
2307
* Return the full path and API test file
2201
2308
*
@@ -2361,24 +2468,34 @@ public void setParameterBooleanFlagWithCodegenProperty(CodegenParameter paramete
2361
2468
2362
2469
if (Boolean .TRUE .equals (property .isString )) {
2363
2470
parameter .isString = true ;
2471
+ parameter .isPrimitiveType = true ;
2364
2472
} else if (Boolean .TRUE .equals (property .isBoolean )) {
2365
2473
parameter .isBoolean = true ;
2474
+ parameter .isPrimitiveType = true ;
2366
2475
} else if (Boolean .TRUE .equals (property .isLong )) {
2367
2476
parameter .isLong = true ;
2477
+ parameter .isPrimitiveType = true ;
2368
2478
} else if (Boolean .TRUE .equals (property .isInteger )) {
2369
2479
parameter .isInteger = true ;
2480
+ parameter .isPrimitiveType = true ;
2370
2481
} else if (Boolean .TRUE .equals (property .isDouble )) {
2371
2482
parameter .isDouble = true ;
2483
+ parameter .isPrimitiveType = true ;
2372
2484
} else if (Boolean .TRUE .equals (property .isFloat )) {
2373
2485
parameter .isFloat = true ;
2486
+ parameter .isPrimitiveType = true ;
2374
2487
} else if (Boolean .TRUE .equals (property .isByteArray )) {
2375
2488
parameter .isByteArray = true ;
2489
+ parameter .isPrimitiveType = true ;
2376
2490
} else if (Boolean .TRUE .equals (property .isBinary )) {
2377
2491
parameter .isByteArray = true ;
2492
+ parameter .isPrimitiveType = true ;
2378
2493
} else if (Boolean .TRUE .equals (property .isDate )) {
2379
2494
parameter .isDate = true ;
2495
+ parameter .isPrimitiveType = true ;
2380
2496
} else if (Boolean .TRUE .equals (property .isDateTime )) {
2381
2497
parameter .isDateTime = true ;
2498
+ parameter .isPrimitiveType = true ;
2382
2499
} else {
2383
2500
LOGGER .debug ("Property type is not primitive: " + property .datatype );
2384
2501
}
0 commit comments