|
18 | 18 |
|
19 | 19 | import io.swagger.v3.oas.models.media.ArraySchema;
|
20 | 20 | import io.swagger.v3.oas.models.media.Schema;
|
| 21 | +import org.apache.commons.io.FilenameUtils; |
21 | 22 | import org.apache.commons.lang3.StringUtils;
|
22 | 23 | import org.openapitools.codegen.*;
|
23 | 24 | import org.openapitools.codegen.meta.GeneratorMetadata;
|
@@ -537,6 +538,11 @@ public void setPowershellGalleryUrl(String powershellGalleryUrl) {
|
537 | 538 | public void processOpts() {
|
538 | 539 | super.processOpts();
|
539 | 540 |
|
| 541 | + if (StringUtils.isEmpty(System.getenv("POWERSHELL_POST_PROCESS_FILE"))) { |
| 542 | + LOGGER.info("Environment variable POWERSHELL_POST_PROCESS_FILE not defined so the PowerShell code may not be properly formatted. To define it, try 'export POWERSHELL_POST_PROCESS_FILE=\"Edit-DTWBeautifyScript\"'"); |
| 543 | + LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI)."); |
| 544 | + } |
| 545 | + |
540 | 546 | if (additionalProperties.containsKey("powershellGalleryUrl")) {
|
541 | 547 | setPowershellGalleryUrl((String) additionalProperties.get("powershellGalleryUrl"));
|
542 | 548 | } else {
|
@@ -1036,6 +1042,34 @@ private String toMethodName(String operationId) {
|
1036 | 1042 | return "Invoke-" + apiNamePrefix + methodName;
|
1037 | 1043 | }
|
1038 | 1044 |
|
| 1045 | + @Override |
| 1046 | + public void postProcessFile(File file, String fileType) { |
| 1047 | + if (file == null) { |
| 1048 | + return; |
| 1049 | + } |
| 1050 | + String powershellPostProcessFile = System.getenv("POWERSHELL_POST_PROCESS_FILE"); |
| 1051 | + if (StringUtils.isEmpty(powershellPostProcessFile)) { |
| 1052 | + return; // skip if POWERSHELL_POST_PROCESS_FILE env variable is not defined |
| 1053 | + } |
| 1054 | + |
| 1055 | + // only process files with ps extension |
| 1056 | + if ("ps".equals(FilenameUtils.getExtension(file.toString()))) { |
| 1057 | + String command = powershellPostProcessFile + " " + file.toString(); |
| 1058 | + try { |
| 1059 | + Process p = Runtime.getRuntime().exec(command); |
| 1060 | + int exitValue = p.waitFor(); |
| 1061 | + if (exitValue != 0) { |
| 1062 | + LOGGER.error("Error running the command ({}). Exit value: {}", command, exitValue); |
| 1063 | + } else { |
| 1064 | + LOGGER.info("Successfully executed: " + command); |
| 1065 | + } |
| 1066 | + } catch (Exception e) { |
| 1067 | + LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage()); |
| 1068 | + } |
| 1069 | + } |
| 1070 | + |
| 1071 | + } |
| 1072 | + |
1039 | 1073 | @Override
|
1040 | 1074 | public String toRegularExpression(String pattern) {
|
1041 | 1075 | return escapeText(pattern);
|
|
0 commit comments