Skip to content

Commit

Permalink
Add js-beautify support to JS generator (OpenAPITools#961)
Browse files Browse the repository at this point in the history
* add js-beautify support to JS generator

* replace tab with space

* update samples without JS_BEAUTIFY_PATH
  • Loading branch information
wing328 authored Sep 8, 2018
1 parent 3f6c98b commit 3923160
Show file tree
Hide file tree
Showing 93 changed files with 124 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.io.FilenameUtils;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenConstants;
Expand All @@ -47,7 +48,6 @@
import java.util.Locale;
import java.util.Map;


public class JavascriptClientCodegen extends DefaultCodegen implements CodegenConfig {
@SuppressWarnings("hiding")
private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptClientCodegen.class);
Expand Down Expand Up @@ -232,6 +232,10 @@ public void processOpts() {
}
super.processOpts();

if (StringUtils.isEmpty(System.getenv("JS_BEAUTIFY_PATH"))) {
LOGGER.info("Environment variable JS_BEAUTIFY_PATH not defined so the JS code may not be properly formatted. To define it, try 'export JS_BEAUTIFY_PATH=/usr/local/bin/js-beautify' (Linux/Mac)");
}

if (additionalProperties.containsKey(PROJECT_NAME)) {
setProjectName(((String) additionalProperties.get(PROJECT_NAME)));
}
Expand Down Expand Up @@ -1157,4 +1161,31 @@ public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "*_/").replace("/*", "/_*");
}

@Override
public void postProcessFile(File file, String fileType) {
if (file == null) {
return;
}

String jsBeautifyPath = System.getenv("JS_BEAUTIFY_PATH");
if (StringUtils.isEmpty(jsBeautifyPath)) {
return; // skip if JS_BEAUTIFY_PATH env variable is not defined
}

// only process files with js extension
if ("js".equals(FilenameUtils.getExtension(file.toString()))) {
String command = jsBeautifyPath + " -r -f " + file.toString();
try {
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
if (p.exitValue() != 0) {
LOGGER.error("Error running the command ({}): {}", command, p.exitValue());
}
} catch (Exception e) {
LOGGER.error("Error running the command ({}): {}", command, e.getMessage());
}
LOGGER.info("Successfully executed: " + command);
}
}

}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3-SNAPSHOT
3.3.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3-SNAPSHOT
3.3.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3-SNAPSHOT
3.3.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/javascript-promise/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
*
* OpenAPI Generator version: 3.2.3-SNAPSHOT
* OpenAPI Generator version: 3.3.0-SNAPSHOT
*
* Do not edit the class manually.
*
Expand Down
Loading

0 comments on commit 3923160

Please sign in to comment.