Skip to content

Commit 6c4381a

Browse files
Merge branch 'master' into python-empty-payload
2 parents e112145 + a35ca36 commit 6c4381a

File tree

39 files changed

+275
-175
lines changed

39 files changed

+275
-175
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavascriptClientCodegen.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,11 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
10511051

10521052
// Provide access to all property models.
10531053
for (CodegenModel cgModel : new HashSet<CodegenModel>(cgModels.values())) {
1054+
detectRecursiveModel(cgModel.allVars, cgModel.classname, cgModels);
10541055
postProcessProperties(cgModel.vars, cgModels);
1055-
if (cgModel.allVars != cgModel.vars)
1056+
if (cgModel.allVars != cgModel.vars) {
10561057
postProcessProperties(cgModel.allVars, cgModels);
1058+
}
10571059
}
10581060

10591061
return objs;
@@ -1305,6 +1307,27 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
13051307
return objs;
13061308
}
13071309

1310+
public void detectRecursiveModel(List<CodegenProperty> allVars, String className, Map<String, CodegenModel> allModels) {
1311+
if (allVars == null || allVars.isEmpty()) {
1312+
return;
1313+
}
1314+
for (CodegenProperty codegenProperty : allVars) {
1315+
if (codegenProperty.isPrimitiveType) {
1316+
continue;
1317+
}
1318+
if (codegenProperty.isListContainer || codegenProperty.isMapContainer) {
1319+
if (className.equalsIgnoreCase(codegenProperty.items.datatype)) {
1320+
codegenProperty.items.vendorExtensions.put("x-is-recursive-model", Boolean.TRUE);
1321+
continue;
1322+
}
1323+
}
1324+
if (className.equalsIgnoreCase(codegenProperty.datatype)) {
1325+
codegenProperty.vendorExtensions.put("x-is-recursive-model", Boolean.TRUE);
1326+
continue;
1327+
}
1328+
}
1329+
}
1330+
13081331
@Override
13091332
protected boolean needToImport(String type) {
13101333
return !defaultIncludes.contains(type)

modules/swagger-codegen/src/main/resources/Javascript/api-test-response-property.mustache

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
}}{{^loadTestDataFromFile}}{{>api-test-property}}{{/loadTestDataFromFile}});
1515
{{/isPrimitiveType}}
1616
{{^isPrimitiveType}}
17-
{{#vendorExtensions.x-indent}}
18-
{{#vendorExtensions.x-indent}}
17+
{{^vendorExtensions.x-is-recursive-model}}
18+
{{#vendorExtensions.x-indent}}
19+
{{#vendorExtensions.x-indent}}
1920
{{>api-test-response-complex}}{{!
20-
}}{{/vendorExtensions.x-indent}}{{!
21-
}}{{/vendorExtensions.x-indent}}{{!
21+
}}{{/vendorExtensions.x-indent}}{{!
22+
}}{{/vendorExtensions.x-indent}}
23+
{{/vendorExtensions.x-is-recursive-model}}{{!
2224
}}{{/isPrimitiveType}}{{!
2325
}} }
2426
{{/items}}

modules/swagger-codegen/src/main/resources/go/api.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
{{>partial_header}}
23
package {{packageName}}
34

@@ -25,19 +26,19 @@ type {{classname}}Service service
2526
{{notes}}{{/notes}}
2627
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
2728
{{#allParams}}{{#required}} * @param {{paramName}}{{#description}} {{.}}{{/description}}
28-
{{/required}}{{/allParams}}{{#hasOptionalParams}} * @param optional nil or *{{{nickname}}}Opts - Optional Parameters:
29+
{{/required}}{{/allParams}}{{#hasOptionalParams}} * @param optional nil or *{{{classname}}}{{{nickname}}}Opts - Optional Parameters:
2930
{{#allParams}}{{^required}} * @param "{{vendorExtensions.x-exportParamName}}" ({{#isPrimitiveType}}optional.{{vendorExtensions.x-optionalDataType}}{{/isPrimitiveType}}{{^isPrimitiveType}}optional.Interface of {{dataType}}{{/isPrimitiveType}}) - {{#description}} {{.}}{{/description}}
3031
{{/required}}{{/allParams}}{{/hasOptionalParams}}
3132
{{#returnType}}@return {{{returnType}}}{{/returnType}}
3233
*/
3334
{{#hasOptionalParams}}
3435

35-
type {{{nickname}}}Opts struct { {{#allParams}}{{^required}}
36+
type {{{classname}}}{{{nickname}}}Opts struct { {{#allParams}}{{^required}}
3637
{{#isPrimitiveType}} {{vendorExtensions.x-exportParamName}} optional.{{vendorExtensions.x-optionalDataType}}{{/isPrimitiveType}}{{^isPrimitiveType}} {{vendorExtensions.x-exportParamName}} optional.Interface{{/isPrimitiveType}}{{/required}}{{/allParams}}
3738
}
3839

3940
{{/hasOptionalParams}}
40-
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
41+
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{classname}}}{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
4142
var (
4243
localVarHttpMethod = strings.ToUpper("{{httpMethod}}")
4344
localVarPostBody interface{}
@@ -148,8 +149,11 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
148149
{{#hasFormParams}}
149150
{{#formParams}}
150151
{{#isFile}}
151-
var localVarFile {{dataType}}
152+
{{#required}}
153+
localVarFile := {{paramName}}
154+
{{/required}}
152155
{{^required}}
156+
var localVarFile {{dataType}}
153157
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
154158
localVarFileOk := false
155159
localVarFile, localVarFileOk = localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value().({{dataType}})

modules/swagger-codegen/src/main/resources/go/api_doc.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Name | Type | Description | Notes
2222
------------- | ------------- | ------------- | -------------
2323
**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc.{{/-last}}{{/allParams}}{{#allParams}}{{#required}}
2424
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
25-
**optional** | ***{{{nickname}}}Opts** | optional parameters | nil if no parameters
25+
**optional** | ***{{{classname}}}{{{nickname}}}Opts** | optional parameters | nil if no parameters
2626

2727
### Optional Parameters
28-
Optional parameters are passed through a pointer to a {{{nickname}}}Opts struct
28+
Optional parameters are passed through a pointer to a {{{classname}}}{{{nickname}}}Opts struct
2929
{{#allParams}}{{#-last}}
3030
Name | Type | Description | Notes
3131
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}

modules/swagger-codegen/src/test/java/io/swagger/codegen/javascript/JavascriptClientCodegenTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package io.swagger.codegen.javascript;
22

3+
import io.swagger.codegen.ClientOptInput;
4+
import io.swagger.codegen.DefaultGenerator;
5+
import io.swagger.codegen.config.CodegenConfigurator;
6+
import org.junit.rules.TemporaryFolder;
37
import org.testng.Assert;
48
import org.testng.annotations.Test;
59

610
import io.swagger.codegen.CodegenConstants;
711
import io.swagger.codegen.languages.JavascriptClientCodegen;
812

13+
import java.io.File;
14+
import java.io.IOException;
15+
916
public class JavascriptClientCodegenTest {
1017

1118
@Test
@@ -43,4 +50,26 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
4350
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
4451
}
4552

53+
@Test
54+
public void testRecursiveModel() throws IOException {
55+
final TemporaryFolder folder = new TemporaryFolder();
56+
57+
folder.create();
58+
final File output = folder.getRoot();
59+
60+
final CodegenConfigurator configurator = new CodegenConfigurator()
61+
.setLang("javascript")
62+
.setInputSpec("src/test/resources/2_0/recursive_model.yaml")
63+
.setOutputDir(output.getAbsolutePath());
64+
65+
final ClientOptInput clientOptInput = configurator.toClientOptInput();
66+
new DefaultGenerator().opts(clientOptInput).generate();
67+
68+
final File orderFile = new File(output, "src/api/TestClassApi.js");
69+
Assert.assertTrue(orderFile.exists());
70+
71+
folder.delete();
72+
73+
}
74+
4675
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
swagger: '2.0'
2+
info:
3+
title: My API
4+
version: v1
5+
paths:
6+
/api/test:
7+
get:
8+
tags:
9+
- TestClass
10+
produces:
11+
- text/plain
12+
- application/json
13+
- text/json
14+
responses:
15+
'200':
16+
description: Success
17+
schema:
18+
type: array
19+
items:
20+
$ref: '#/definitions/TestClass'
21+
definitions:
22+
TestClass:
23+
type: object
24+
properties:
25+
name:
26+
type: string
27+
children:
28+
type: array
29+
items:
30+
$ref: '#/definitions/TestClass'

pom.xml.jenkins

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@
868868
<module>samples/client/petstore/akka-scala</module>
869869
<module>samples/client/petstore/scala</module>
870870
<!--<module>samples/client/petstore/scalaz</module>-->
871-
<module>samples/client/petstore/clojure</module>
871+
<!--<module>samples/client/petstore/clojure</module>-->
872872
<module>samples/client/petstore/java/feign</module>
873873
<module>samples/client/petstore/java/jersey1</module>
874874
<module>samples/client/petstore/java/jersey2</module>
@@ -882,12 +882,12 @@
882882
<module>samples/client/petstore/java/vertx</module>
883883
<module>samples/client/petstore/java/resteasy</module>
884884
<module>samples/client/petstore/java/google-api-client</module>
885-
<module>samples/client/petstore/java/rest-assured</module>
885+
<!--module>samples/client/petstore/java/rest-assured</module removed until errors found on #10120 be fixed -->
886886
<module>samples/client/petstore/kotlin/</module>
887887
<module>samples/client/petstore/kotlin-threetenbp/</module>
888888
<module>samples/client/petstore/kotlin-string/</module>
889889
<!-- test non-java projects -->
890-
<module>samples/client/petstore/go</module>
890+
<!-- module>samples/client/petstore/go</module removed until errors found on #10120 be fixed -->
891891
<!-- servers -->
892892
<module>samples/server/petstore/java-vertx/rx</module>
893893
<module>samples/server/petstore/java-vertx/async</module>

pom.xml.jenkins.java7

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@
821821
<!-- test java-related projects -->
822822
<module>samples/client/petstore/akka-scala</module>
823823
<module>samples/client/petstore/scala</module>
824-
<module>samples/client/petstore/clojure</module>
824+
<!--<module>samples/client/petstore/clojure</module>-->
825825
<module>samples/client/petstore/java/feign</module>
826826
<module>samples/client/petstore/java/jersey1</module>
827827
<module>samples/client/petstore/java/jersey2</module>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.3-SNAPSHOT
1+
2.4.6-SNAPSHOT

samples/client/petstore/go/go-petstore-withXml/api/swagger.yaml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ paths:
107107
type: "array"
108108
items:
109109
type: "string"
110+
default: "available"
110111
enum:
111112
- "available"
112113
- "pending"
113114
- "sold"
114-
default: "available"
115115
collectionFormat: "csv"
116116
x-exportParamName: "Status"
117117
responses:
@@ -639,10 +639,10 @@ paths:
639639
type: "array"
640640
items:
641641
type: "string"
642+
default: "$"
642643
enum:
643644
- ">"
644645
- "$"
645-
default: "$"
646646
x-exportParamName: "EnumFormStringArray"
647647
- name: "enum_form_string"
648648
in: "formData"
@@ -663,10 +663,10 @@ paths:
663663
type: "array"
664664
items:
665665
type: "string"
666+
default: "$"
666667
enum:
667668
- ">"
668669
- "$"
669-
default: "$"
670670
x-exportParamName: "EnumHeaderStringArray"
671671
- name: "enum_header_string"
672672
in: "header"
@@ -687,10 +687,10 @@ paths:
687687
type: "array"
688688
items:
689689
type: "string"
690+
default: "$"
690691
enum:
691692
- ">"
692693
- "$"
693-
default: "$"
694694
x-exportParamName: "EnumQueryStringArray"
695695
- name: "enum_query_string"
696696
in: "query"
@@ -1108,12 +1108,12 @@ definitions:
11081108
xml:
11091109
name: "Order"
11101110
example:
1111-
id: 0
11121111
petId: 6
1113-
complete: false
1114-
status: "placed"
11151112
quantity: 1
1113+
id: 0
11161114
shipDate: "2000-01-23T04:56:07.000+00:00"
1115+
complete: false
1116+
status: "placed"
11171117
Category:
11181118
type: "object"
11191119
properties:
@@ -1125,8 +1125,8 @@ definitions:
11251125
xml:
11261126
name: "Category"
11271127
example:
1128-
id: 6
11291128
name: "name"
1129+
id: 6
11301130
User:
11311131
type: "object"
11321132
properties:
@@ -1153,14 +1153,14 @@ definitions:
11531153
xml:
11541154
name: "User"
11551155
example:
1156-
id: 0
1156+
firstName: "firstName"
11571157
lastName: "lastName"
1158+
password: "password"
1159+
userStatus: 6
11581160
phone: "phone"
1159-
username: "username"
1161+
id: 0
11601162
email: "email"
1161-
userStatus: 6
1162-
firstName: "firstName"
1163-
password: "password"
1163+
username: "username"
11641164
Tag:
11651165
type: "object"
11661166
properties:
@@ -1172,8 +1172,8 @@ definitions:
11721172
xml:
11731173
name: "Tag"
11741174
example:
1175-
id: 1
11761175
name: "name"
1176+
id: 1
11771177
Pet:
11781178
type: "object"
11791179
required:
@@ -1213,20 +1213,20 @@ definitions:
12131213
xml:
12141214
name: "Pet"
12151215
example:
1216-
tags:
1217-
- id: 1
1218-
name: "name"
1219-
- id: 1
1220-
name: "name"
1216+
photoUrls:
1217+
- "photoUrls"
1218+
- "photoUrls"
1219+
name: "doggie"
12211220
id: 0
12221221
category:
1223-
id: 6
12241222
name: "name"
1223+
id: 6
1224+
tags:
1225+
- name: "name"
1226+
id: 1
1227+
- name: "name"
1228+
id: 1
12251229
status: "available"
1226-
name: "doggie"
1227-
photoUrls:
1228-
- "photoUrls"
1229-
- "photoUrls"
12301230
ApiResponse:
12311231
type: "object"
12321232
properties:
@@ -1238,9 +1238,9 @@ definitions:
12381238
message:
12391239
type: "string"
12401240
example:
1241-
message: "message"
12421241
code: 0
12431242
type: "type"
1243+
message: "message"
12441244
$special[model.name]:
12451245
properties:
12461246
$special[property.name]:
@@ -1574,8 +1574,8 @@ definitions:
15741574
my_boolean:
15751575
$ref: "#/definitions/OuterBoolean"
15761576
example:
1577-
my_number: {}
15781577
my_string: {}
1578+
my_number: {}
15791579
my_boolean: {}
15801580
OuterNumber:
15811581
type: "number"

0 commit comments

Comments
 (0)