|
17 | 17 |
|
18 | 18 | package org.openapitools.codegen.languages;
|
19 | 19 |
|
| 20 | +import org.apache.commons.io.FilenameUtils; |
| 21 | +import org.apache.commons.lang3.StringUtils; |
20 | 22 | import io.swagger.v3.oas.models.media.ArraySchema;
|
21 | 23 | import io.swagger.v3.oas.models.media.Schema;
|
22 | 24 | import org.openapitools.codegen.CodegenConfig;
|
|
25 | 27 | import org.slf4j.Logger;
|
26 | 28 | import org.slf4j.LoggerFactory;
|
27 | 29 |
|
| 30 | +import java.io.File; |
28 | 31 | import java.util.Arrays;
|
29 | 32 | import java.util.Locale;
|
30 | 33 |
|
@@ -77,6 +80,15 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf
|
77 | 80 | typeMapping.put("UUID", "String");
|
78 | 81 | }
|
79 | 82 |
|
| 83 | + @Override |
| 84 | + public void processOpts() { |
| 85 | + super.processOpts(); |
| 86 | + |
| 87 | + if (StringUtils.isEmpty(System.getenv("RUBY_POST_PROCESS_FILE"))) { |
| 88 | + LOGGER.info("Hint: Environment variable 'RUBY_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export RUBY_POST_PROCESS_FILE=/usr/local/bin/rubocop -a' (Linux/Mac)"); |
| 89 | + } |
| 90 | + } |
| 91 | + |
80 | 92 | @Override
|
81 | 93 | public String escapeReservedWord(String name) {
|
82 | 94 | if (this.reservedWordsMappings().containsKey(name)) {
|
@@ -162,4 +174,30 @@ public String escapeQuotationMark(String input) {
|
162 | 174 | public String escapeUnsafeCharacters(String input) {
|
163 | 175 | return input.replace("=end", "=_end").replace("=begin", "=_begin");
|
164 | 176 | }
|
| 177 | + |
| 178 | + @Override |
| 179 | + public void postProcessFile(File file, String fileType) { |
| 180 | + if (file == null) { |
| 181 | + return; |
| 182 | + } |
| 183 | + String rubyPostProcessFile = System.getenv("RUBY_POST_PROCESS_FILE"); |
| 184 | + if (StringUtils.isEmpty(rubyPostProcessFile)) { |
| 185 | + return; // skip if RUBY_POST_PROCESS_FILE env variable is not defined |
| 186 | + } |
| 187 | + // only process files with rb extension |
| 188 | + if ("rb".equals(FilenameUtils.getExtension(file.toString()))) { |
| 189 | + String command = rubyPostProcessFile + " " + file.toString(); |
| 190 | + try { |
| 191 | + Process p = Runtime.getRuntime().exec(command); |
| 192 | + int exitValue = p.waitFor(); |
| 193 | + if (exitValue != 0) { |
| 194 | + LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue); |
| 195 | + } else { |
| 196 | + LOGGER.info("Successfully executed: " + command); |
| 197 | + } |
| 198 | + } catch (Exception e) { |
| 199 | + LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage()); |
| 200 | + } |
| 201 | + } |
| 202 | + } |
165 | 203 | }
|
0 commit comments