Permalink
Browse files

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
  • Loading branch information...
wing328 committed Oct 1, 2018
1 parent dcc0b5e commit 2b87b309ad5675a4e16d66b0bfe5866d5ba3196a
Showing with 437 additions and 361 deletions.
  1. +2 −1 CI/circle_parallel.sh
  2. +3 −2 README.md
  3. +1 −0 bin/utils/ensure-up-to-date
  4. +37 −0 docs/generators/dart-jaguar.md
  5. +37 −0 docs/generators/typescript-axios.md
  6. +20 −10 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java
  7. +0 −4 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java
  8. +0 −4 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoGinServerCodegen.java
  9. +0 −4 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java
  10. +10 −10 samples/client/petstore/go/go-petstore/api_another_fake.go
  11. +89 −89 samples/client/petstore/go/go-petstore/api_fake.go
  12. +10 −10 samples/client/petstore/go/go-petstore/api_fake_classname_tags123.go
  13. +69 −69 samples/client/petstore/go/go-petstore/api_pet.go
  14. +33 −33 samples/client/petstore/go/go-petstore/api_store.go
  15. +33 −33 samples/client/petstore/go/go-petstore/api_user.go
  16. +11 −11 samples/client/petstore/go/go-petstore/client.go
  17. +1 −1 samples/client/petstore/go/go-petstore/model_200_response.go
  18. +1 −1 samples/client/petstore/go/go-petstore/model_additional_properties_class.go
  19. +1 −1 samples/client/petstore/go/go-petstore/model_animal.go
  20. +2 −2 samples/client/petstore/go/go-petstore/model_api_response.go
  21. +3 −3 samples/client/petstore/go/go-petstore/model_array_test_.go
  22. +5 −5 samples/client/petstore/go/go-petstore/model_capitalization.go
  23. +2 −2 samples/client/petstore/go/go-petstore/model_cat.go
  24. +1 −1 samples/client/petstore/go/go-petstore/model_category.go
  25. +2 −2 samples/client/petstore/go/go-petstore/model_dog.go
  26. +2 −2 samples/client/petstore/go/go-petstore/model_enum_arrays.go
  27. +1 −2 samples/client/petstore/go/go-petstore/model_enum_class.go
  28. +5 −5 samples/client/petstore/go/go-petstore/model_enum_test_.go
  29. +1 −1 samples/client/petstore/go/go-petstore/model_file_schema_test_class.go
  30. +12 −13 samples/client/petstore/go/go-petstore/model_format_test_.go
  31. +4 −4 samples/client/petstore/go/go-petstore/model_map_test_.go
  32. +3 −4 samples/client/petstore/go/go-petstore/model_mixed_properties_and_additional_properties_class.go
  33. +4 −4 samples/client/petstore/go/go-petstore/model_name.go
  34. +5 −6 samples/client/petstore/go/go-petstore/model_order.go
  35. +3 −3 samples/client/petstore/go/go-petstore/model_outer_composite.go
  36. +3 −4 samples/client/petstore/go/go-petstore/model_outer_enum.go
  37. +4 −4 samples/client/petstore/go/go-petstore/model_pet.go
  38. +1 −1 samples/client/petstore/go/go-petstore/model_tag.go
  39. +6 −6 samples/client/petstore/go/go-petstore/model_user.go
  40. +1 −1 samples/server/petstore/go-api-server/.openapi-generator/VERSION
  41. +1 −0 samples/server/petstore/go-gin-api-server/go/model_api_response.go
  42. +1 −0 samples/server/petstore/go-gin-api-server/go/model_category.go
  43. +1 −0 samples/server/petstore/go-gin-api-server/go/model_order.go
  44. +1 −0 samples/server/petstore/go-gin-api-server/go/model_pet.go
  45. +1 −0 samples/server/petstore/go-gin-api-server/go/model_tag.go
  46. +1 −0 samples/server/petstore/go-gin-api-server/go/model_user.go
  47. +3 −3 samples/server/petstore/go-gin-api-server/go/routers.go
View
@@ -10,7 +10,8 @@ if [ "$NODE_INDEX" = "1" ]; then
mvn --quiet verify -Psamples
elif [ "$NODE_INDEX" = "2" ]; then
echo "Running node $NODE_INDEX to test ensure-up-to-date"
export GO_FMT_PATH=`which gofmt`
#export GO_POST_PROCESS_FILE="/usr/local/bin/gofmt -w"
# not formatting the code as different go versions may format the code a bit different
./bin/utils/ensure-up-to-date
else
echo "Running node $NODE_INDEX to test CI/pom.xml.circleci.java7 ..."
View
@@ -43,7 +43,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
| | Languages/Frameworks |
|-|-|
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C#** (.net 2.0, 3.5 or later), **C++** (cpprest, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 6.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node)
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go**, **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), Scalatra)
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed), **Erlang**, **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), Scalatra)
**API documentation generators** | **HTML**, **Confluence Wiki**
**Configuration files** | [**Apache2**](https://httpd.apache.org/)
**Others** | **JMeter**, **MySQL Schema**
@@ -577,6 +577,7 @@ Here is a list of template creators:
* C++ Restbed: @stkrwork
* Erlang Server: @galaxie
* Go Server: @guohuang
* Go (Gin) Server: @kemokemo
* Haskell Servant: @algas
* Java MSF4J: @sanjeewa-malalgoda
* Java Spring Boot: @diyfr
@@ -650,7 +651,7 @@ If you want to join the committee, please kindly apply by sending an email to te
| Elixir | |
| Elm | @trenneman (2018/09) |
| Erlang | @tsloughter (2017/11) |
| Go | @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) |
| Go | @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09 |
| Groovy | |
| Haskell | |
| Java | @bbdouglas (2017/07) @JFCote (2017/08) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) |
@@ -35,6 +35,7 @@ sleep 5
./bin/csharp-petstore.sh > /dev/null 2>&1
./bin/meta-codegen.sh > /dev/null 2>&1
./bin/utils/export_docs_generators.sh > /dev/null 2>&1
./bin/go-petstore.sh > /dev/null 2>&1
./bin/go-gin-petstore-server.sh > /dev/null 2>&1
# Check:
@@ -0,0 +1,37 @@
CONFIG OPTIONS for dart-jaguar
sortParamsByRequiredFlag
Sort method arguments to place required parameters before optional parameters. (Default: true)
ensureUniqueParams
Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)
allowUnicodeIdentifiers
boolean, toggles whether unicode identifiers are allowed in names or not, default is false (Default: false)
prependFormOrBodyParameters
Add form or body parameters to the beginning of the parameter list. (Default: false)
browserClient
Is the client browser based
pubName
Name in generated pubspec
pubVersion
Version in generated pubspec
pubDescription
Description in generated pubspec
useEnumExtension
Allow the 'x-enum-values' extension for enums
sourceFolder
source folder for generated code
supportDart2
support dart2 (Default: true)
Back to the [generators list](README.md)
@@ -0,0 +1,37 @@
CONFIG OPTIONS for typescript-axios
sortParamsByRequiredFlag
Sort method arguments to place required parameters before optional parameters. (Default: true)
ensureUniqueParams
Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)
allowUnicodeIdentifiers
boolean, toggles whether unicode identifiers are allowed in names or not, default is false (Default: false)
prependFormOrBodyParameters
Add form or body parameters to the beginning of the parameter list. (Default: false)
modelPropertyNaming
Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name (Default: camelCase)
supportsES6
Generate code that conforms to ES6. (Default: false)
npmName
The name under which you want to publish generated npm package
npmVersion
The version of your npm package
npmRepository
Use this property to set an url your private npmRepo in the package.json
snapshot
When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm (Default: false)
withInterfaces
Setting this property to true will generate interfaces next to the default class implementations. (Default: false)
Back to the [generators list](README.md)
@@ -115,6 +115,15 @@ public AbstractGoCodegen() {
.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 void postProcessFile(File file, String fileType) {
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 void postProcessFile(File file, String fileType) {
// 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 GoClientCodegen() {
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 GoGinServerCodegen() {
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 GoServerCodegen() {
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 {
@@ -33,12 +33,12 @@ To test special tags and operation ID starting with number
*/
func (a *AnotherFakeApiService) Call123TestSpecialTags(ctx context.Context, client Client) (Client, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Patch")
localVarHttpMethod = strings.ToUpper("Patch")
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
localVarFileBytes []byte
localVarReturnValue Client
localVarReturnValue Client
)
// create path and map variables
@@ -85,26 +85,26 @@ func (a *AnotherFakeApiService) Call123TestSpecialTags(ctx context.Context, clie
if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
}
if localVarHttpResponse.StatusCode >= 300 {
newErr := GenericOpenAPIError{
body: localVarBody,
body: localVarBody,
error: localVarHttpResponse.Status,
}
if localVarHttpResponse.StatusCode == 200 {
var v Client
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHttpResponse, newErr
}
return localVarReturnValue, localVarHttpResponse, newErr
}
Oops, something went wrong.

0 comments on commit 2b87b30

Please sign in to comment.