Skip to content

Commit 28579ce

Browse files
committed
Merge pull request #1135 from restlet/fix/nodejs_server_swagger_invalid_json
[Node.js] fix invalid JSON being generated in swagger.json
2 parents e3c6cc3 + d434b7c commit 28579ce

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,14 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
207207
}
208208

209209
@SuppressWarnings("unchecked")
210-
private Map<String, Object> getOperations(Map<String, Object> objs) {
210+
private List<Map<String, Object>> getOperations(Map<String, Object> objs) {
211+
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
211212
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
212213
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
213-
Map<String, Object> api = apis.get(0);
214-
return (Map<String, Object>) api.get("operations");
214+
for (Map<String, Object> api : apis) {
215+
result.add((Map<String, Object>) api.get("operations"));
216+
}
217+
return result;
215218
}
216219

217220
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
@@ -221,7 +224,7 @@ private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> op
221224
opsByPath.put(op.path, op);
222225
}
223226

224-
List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>();
227+
List<Map<String, Object>> opsByPathList = new ArrayList<Map<String, Object>>();
225228
for (Entry<String, Collection<CodegenOperation>> entry : opsByPath.asMap().entrySet()) {
226229
Map<String, Object> opsByPathEntry = new HashMap<String, Object>();
227230
opsByPathList.add(opsByPathEntry);
@@ -239,16 +242,13 @@ private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> op
239242

240243
@Override
241244
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
242-
Map<String, Object> operations = getOperations(objs);
243-
244-
if (operations != null) {
245+
for (Map<String, Object> operations : getOperations(objs)) {
245246
@SuppressWarnings("unchecked")
246247
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
247248

248249
List<Map<String, Object>> opsByPathList = sortOperationsByPath(ops);
249250
operations.put("operationsByPath", opsByPathList);
250251
}
251-
252252
return super.postProcessSupportingFileData(objs);
253253
}
254254
}

modules/swagger-codegen/src/main/resources/nodejs/swagger.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{#operations}}
1515
{{#operationsByPath}}
1616
"{{{path}}}": {
17-
{{#operation}}
17+
{{#operation}}
1818
"{{httpMethod}}": {
1919
"summary": "{{summary}}",
2020
"description":"{{notes}}",
@@ -34,7 +34,6 @@
3434
{{/operation}}
3535
} {{#hasMore}},{{/hasMore}}
3636
{{/operationsByPath}}
37-
{{#hasMore}},{{/hasMore}}
3837
{{/operations}}
3938
{{/apis}}
4039
{{/apiInfo}}

0 commit comments

Comments
 (0)