@@ -39,7 +39,8 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
39
39
protected String hostEnvironmentVariable ;
40
40
protected String basicAuthEnvironmentVariable ;
41
41
protected String apiKeyAuthEnvironmentVariable ;
42
-
42
+ protected String apiDocPath = "docs/" ;
43
+ protected String modelDocPath = "docs/" ;
43
44
44
45
public static final String CURL_OPTIONS = "curlOptions" ;
45
46
public static final String PROCESS_MARKDOWN = "processMarkdown" ;
@@ -105,6 +106,13 @@ public BashClientCodegen() {
105
106
apiTemplateFiles .clear ();
106
107
107
108
109
+ /**
110
+ * docs files.
111
+ */
112
+ modelDocTemplateFiles .put ("model_doc.mustache" , ".md" );
113
+ apiDocTemplateFiles .put ("api_doc.mustache" , ".md" );
114
+
115
+
108
116
/**
109
117
* Templates location for client script and bash completion template.
110
118
*/
@@ -169,6 +177,7 @@ public BashClientCodegen() {
169
177
typeMapping .put ("int" , "integer" );
170
178
typeMapping .put ("float" , "float" );
171
179
typeMapping .put ("number" , "integer" );
180
+ typeMapping .put ("date" , "string" );
172
181
typeMapping .put ("DateTime" , "string" );
173
182
typeMapping .put ("long" , "integer" );
174
183
typeMapping .put ("short" , "integer" );
@@ -185,12 +194,22 @@ public BashClientCodegen() {
185
194
* are available in models, apis, and supporting files.
186
195
*/
187
196
additionalProperties .put ("apiVersion" , apiVersion );
197
+ // make api and model doc path available in mustache template
198
+ additionalProperties .put ("apiDocPath" , apiDocPath );
199
+ additionalProperties .put ("modelDocPath" , modelDocPath );
188
200
189
201
/**
190
202
* Language Specific Primitives. These types will not trigger imports by
191
203
* the client generator
192
204
*/
193
- languageSpecificPrimitives = new HashSet <String >();
205
+ languageSpecificPrimitives .clear ();
206
+ languageSpecificPrimitives .add ("array" );
207
+ languageSpecificPrimitives .add ("map" );
208
+ languageSpecificPrimitives .add ("boolean" );
209
+ languageSpecificPrimitives .add ("integer" );
210
+ languageSpecificPrimitives .add ("float" );
211
+ languageSpecificPrimitives .add ("string" );
212
+ languageSpecificPrimitives .add ("binary" );
194
213
}
195
214
196
215
@@ -239,15 +258,15 @@ public void processOpts() {
239
258
}
240
259
241
260
supportingFiles .add (new SupportingFile (
242
- "client.mustache" , "" , scriptName ));
261
+ "client.mustache" , "" , scriptName ));
243
262
supportingFiles .add (new SupportingFile (
244
- "bash-completion.mustache" , "" , scriptName +".bash-completion" ));
263
+ "bash-completion.mustache" , "" , scriptName +".bash-completion" ));
245
264
supportingFiles .add (new SupportingFile (
246
- "zsh-completion.mustache" , "" , "_" +scriptName ));
265
+ "zsh-completion.mustache" , "" , "_" +scriptName ));
247
266
supportingFiles .add (new SupportingFile (
248
- "README.mustache" , "" , "README.md" ));
267
+ "README.mustache" , "" , "README.md" ));
249
268
supportingFiles .add (new SupportingFile (
250
- "Dockerfile.mustache" , "" , "Dockerfile" ));
269
+ "Dockerfile.mustache" , "" , "Dockerfile" ));
251
270
}
252
271
253
272
public void setCurlOptions (String curlOptions ) {
@@ -314,6 +333,25 @@ public String apiFileFolder() {
314
333
return outputFolder ;
315
334
}
316
335
336
+ @ Override
337
+ public String apiDocFileFolder () {
338
+ return (outputFolder + "/" + apiDocPath );
339
+ }
340
+
341
+ @ Override
342
+ public String modelDocFileFolder () {
343
+ return (outputFolder + "/" + modelDocPath );
344
+ }
345
+
346
+ @ Override
347
+ public String toModelDocFilename (String name ) {
348
+ return toModelName (name );
349
+ }
350
+
351
+ @ Override
352
+ public String toApiDocFilename (String name ) {
353
+ return toApiName (name );
354
+ }
317
355
318
356
/**
319
357
* Optional - type declaration. This is a String which is used by the
@@ -355,8 +393,9 @@ public String getSwaggerType(Property p) {
355
393
if (languageSpecificPrimitives .contains (type ))
356
394
return type ;
357
395
}
358
- else
396
+ else {
359
397
type = swaggerType ;
398
+ }
360
399
return toModelName (type );
361
400
}
362
401
@@ -656,4 +695,69 @@ public void preprocessSwagger(Swagger swagger) {
656
695
657
696
}
658
697
698
+ @ Override
699
+ public void setParameterExampleValue (CodegenParameter p ) {
700
+ String example ;
701
+
702
+ if (p .defaultValue == null ) {
703
+ example = p .example ;
704
+ } else {
705
+ example = p .defaultValue ;
706
+ }
707
+
708
+ String type = p .baseType ;
709
+ if (type == null ) {
710
+ type = p .dataType ;
711
+ }
712
+
713
+ if ("string" .equalsIgnoreCase (type )) {
714
+ if (example == null ) {
715
+ example = p .paramName + "_example" ;
716
+ }
717
+ example = "'" + escapeText (example ) + "'" ;
718
+ } else if ("integer" .equals (type )) {
719
+ if (example == null ) {
720
+ example = "56" ;
721
+ }
722
+ } else if ("float" .equalsIgnoreCase (type )) {
723
+ if (example == null ) {
724
+ example = "3.4" ;
725
+ }
726
+ } else if ("boolean" .equalsIgnoreCase (type )) {
727
+ if (example == null ) {
728
+ example = "True" ;
729
+ }
730
+ } else if ("file" .equalsIgnoreCase (type )) {
731
+ if (example == null ) {
732
+ example = "/path/to/file" ;
733
+ }
734
+ example = "'" + escapeText (example ) + "'" ;
735
+ } else if ("date" .equalsIgnoreCase (type )) {
736
+ if (example == null ) {
737
+ example = "2013-10-20" ;
738
+ }
739
+ example = "'" + escapeText (example ) + "'" ;
740
+ } else if ("datetime" .equalsIgnoreCase (type )) {
741
+ if (example == null ) {
742
+ example = "2013-10-20T19:20:30+01:00" ;
743
+ }
744
+ example = "'" + escapeText (example ) + "'" ;
745
+ } else if (!languageSpecificPrimitives .contains (type )) {
746
+ // type is a model class, e.g. User
747
+ example = type ;
748
+ } else {
749
+ LOGGER .warn ("Type " + type + " not handled properly in setParameterExampleValue" );
750
+ }
751
+
752
+ if (example == null ) {
753
+ example = "NULL" ;
754
+ } else if (Boolean .TRUE .equals (p .isListContainer )) {
755
+ example = "[" + example + "]" ;
756
+ } else if (Boolean .TRUE .equals (p .isMapContainer )) {
757
+ example = "{'key': " + example + "}" ;
758
+ }
759
+
760
+ p .example = example ;
761
+ }
762
+
659
763
}
0 commit comments