Skip to content

Commit

Permalink
feat: support generate TypeScript data JSON only
Browse files Browse the repository at this point in the history
  • Loading branch information
yangqianjun committed Nov 2, 2020
1 parent 69ea9a2 commit 6fd3e0a
Showing 1 changed file with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,11 @@ private Model getParent(Model model) {
LOGGER.info("Skipped overwriting " + filename);
continue;
}
File written = processTemplateToFile(models, templateName, filename);
if (written != null) {
files.add(written);
if (System.getProperty("typeScriptDataFile") == null) {
File written = processTemplateToFile(models, templateName, filename);
if (written != null) {
files.add(written);
}
}
}
if(isGenerateModelTests) {
Expand Down Expand Up @@ -524,9 +526,11 @@ public int compare(CodegenOperation one, CodegenOperation another) {
continue;
}

File written = processTemplateToFile(operation, templateName, filename);
if (written != null) {
files.add(written);
if (System.getProperty("typeScriptDataFile") == null) {
File written = processTemplateToFile(operation, templateName, filename);
if (written != null) {
files.add(written);
}
}
}

Expand All @@ -541,8 +545,10 @@ public int compare(CodegenOperation one, CodegenOperation another) {
}

File written = processTemplateToFile(operation, templateName, filename);
if (written != null) {
files.add(written);
if (System.getProperty("typeScriptDataFile") == null) {
if (written != null) {
files.add(written);
}
}
}
}
Expand All @@ -558,8 +564,10 @@ public int compare(CodegenOperation one, CodegenOperation another) {
}

File written = processTemplateToFile(operation, templateName, filename);
if (written != null) {
files.add(written);
if (System.getProperty("typeScriptDataFile") == null) {
if (written != null) {
files.add(written);
}
}
}
}
Expand Down Expand Up @@ -781,6 +789,18 @@ public List<File> generate() {
Map<String, Object> bundle = buildSupportFileBundle(allOperations, allModels);
generateSupportingFiles(files, bundle);
config.processSwagger(swagger);

String typeScriptDataFile = System.getProperty("typeScriptDataFile") != null && System.getProperty("typeScriptDataFile").isEmpty() ? "TypeScriptData.json" : System.getProperty("typeScriptDataFile");

if (typeScriptDataFile != null) {
try {
String modelsString = Json.pretty(allModels);
String operationsString = Json.pretty(allOperations);
writeToFile(config.outputFolder() + File.separator + typeScriptDataFile, "{\"models\": " + modelsString + ", \"operations\": " + operationsString + "}");
} catch (IOException e) {
throw new RuntimeException("Could not generate supporting file '" + typeScriptDataFile + "'", e);
}
}
return files;
}

Expand Down

0 comments on commit 6fd3e0a

Please sign in to comment.