Skip to content

Commit e44d3db

Browse files
committed
merge File content function added
1 parent 6718e2d commit e44d3db

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/AbstractGenerator.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ public File writeToFile(String filename, String contents) throws IOException {
4848
return output;
4949
}
5050

51+
public String mergeFileContent(String fileName, String content) throws IOException {
52+
53+
File f1 = new File(fileName);
54+
55+
if(!f1.exists()){
56+
return content;
57+
}
58+
59+
FileReader fileReader = new FileReader(f1);
60+
BufferedReader bufferedReader = new BufferedReader(fileReader);
61+
String line,existingContent = "";
62+
63+
while((line = bufferedReader.readLine()) != null) {
64+
if(existingContent=="")
65+
existingContent = line;
66+
else
67+
existingContent += System.lineSeparator() + line;
68+
}
69+
70+
if(!existingContent.isEmpty()) {
71+
content = existingContent + System.lineSeparator() + content;
72+
}
73+
return content;
74+
}
75+
5176
public String readTemplate(String name) {
5277
try {
5378
Reader reader = getTemplateReader(name);

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,11 @@ public Reader getTemplate(String name) {
712712
.defaultValue("")
713713
.compile(template);
714714

715-
writeToFile(outputFilename, tmpl.execute(bundle));
715+
String contents = tmpl.execute(bundle);
716+
if(support.merge)
717+
contents = mergeFileContent(outputFilename, contents);
718+
writeToFile(outputFilename, contents);
719+
716720
File written = new File(outputFilename);
717721
files.add(written);
718722
if (config.isEnablePostProcessFile()) {

0 commit comments

Comments
 (0)