mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 18:59:14 +00:00
Rename environment variable for Go to post-process file (#1091)
* renmae Go post process file env variable * add back samples/client/petstore/c/libcurl.licence * keep go samples up-to-date * update go petstore samples * update go samples without formatting
This commit is contained in:
@@ -115,6 +115,15 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("GO_POST_PROCESS_FILE"))) {
|
||||
LOGGER.info("Environment variable GO_POST_PROCESS_FILE not defined so Go code may not be properly formatted. To define it, try `export GO_POST_PROCESS_FILE=\"/usr/local/bin/gofmt -w\"` (Linux/Mac)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reserved words
|
||||
@@ -613,9 +622,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
return;
|
||||
}
|
||||
|
||||
String goFmtPath = System.getenv("GO_FMT_PATH");
|
||||
if (StringUtils.isEmpty(goFmtPath)) {
|
||||
return; // skip if GO_FMT_PATH env variable is not defined
|
||||
String goPostProcessFile = System.getenv("GO_POST_PROCESS_FILE");
|
||||
if (StringUtils.isEmpty(goPostProcessFile)) {
|
||||
return; // skip if GO_POST_PROCESS_FILE env variable is not defined
|
||||
}
|
||||
|
||||
// only procees the following type (or we can simply rely on the file extension to check if it's a Go file)
|
||||
@@ -632,16 +641,17 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
// only process files with go extension
|
||||
if ("go".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||
// currently only support "gofmt -w yourcode.go"
|
||||
// another way is "go fmt path/to/your/package"
|
||||
String command = goFmtPath + " -w " + file.toString();
|
||||
// e.g. "gofmt -w yourcode.go"
|
||||
// e.g. "go fmt path/to/your/package"
|
||||
String command = goPostProcessFile + " " + file.toString();
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
if (p.exitValue() != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, p.exitValue());
|
||||
int exitValue = p.waitFor();
|
||||
if (exitValue != 0) {
|
||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
|
||||
} else {
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
}
|
||||
LOGGER.info("Successfully executed: " + command);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||
}
|
||||
|
||||
@@ -71,10 +71,6 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("GO_FMT_PATH"))) {
|
||||
LOGGER.info("Environment variable GO_FMT_PATH not defined so Go code may not be properly formatted. To define it, try 'export GO_FMT_PATH=/usr/local/bin/gofmt' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
|
||||
@@ -106,10 +106,6 @@ public class GoGinServerCodegen extends AbstractGoCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("GO_FMT_PATH"))) {
|
||||
LOGGER.info("Environment variable GO_FMT_PATH not defined so Go code may not be properly formatted. To define it, try 'export GO_FMT_PATH=/usr/local/bin/gofmt' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
|
||||
@@ -90,10 +90,6 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (StringUtils.isEmpty(System.getenv("GO_FMT_PATH"))) {
|
||||
LOGGER.info("Environment variable GO_FMT_PATH not defined so Go code may not be properly formatted. To define it, try 'export GO_FMT_PATH=/usr/local/bin/gofmt' (Linux/Mac)");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user