diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/NodeJSServerCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/NodeJSServerCodegen.java index b2f8249898..c213c68697 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/NodeJSServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/NodeJSServerCodegen.java @@ -1,7 +1,12 @@ package com.wordnik.swagger.codegen.languages; import com.wordnik.swagger.codegen.*; +import com.wordnik.swagger.models.Model; import com.wordnik.swagger.models.properties.*; +import com.wordnik.swagger.util.Json; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.*; import java.util.*; import java.io.File; @@ -56,6 +61,28 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig return "_" + name; } + @Override + public Map postProcessSupportingFileData(Map objs) { + List> o = (List>)objs.get("models"); + + for(Map modelMap : o) { + try { + CodegenModel m = (CodegenModel) modelMap.get("model"); + ObjectNode on = (ObjectNode) Json.mapper().readTree(m.modelJson); + // inject the id field + on.put("id", m.name); + + // remove the definitions qualifier with this nasty hack + m.modelJson = Json.pretty(on).replaceAll("\"#/definitions/", "\""); + } + catch (Exception e) { + e.printStackTrace(); + // skip conversion + } + } + return objs; + } + @Override public String apiFileFolder() { return outputFolder + File.separator + apiPackage().replaceAll("\\.", File.separator);