diff --git a/bin/go-petstore.sh b/bin/go-petstore.sh new file mode 100755 index 000000000000..239f31f0d716 --- /dev/null +++ b/bin/go-petstore.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l go -o samples/client/petstore/go" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/go-petstore.bat b/bin/windows/go-petstore.bat new file mode 100755 index 000000000000..050bfd23cc84 --- /dev/null +++ b/bin/windows/go-petstore.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -t modules\swagger-codegen\src\main\resources\go -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l go -o samples\client\petstore\go + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java index a7488983d400..6e15f373864d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java @@ -71,7 +71,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { "byte") ); - instantiationTypes.clear(); + instantiationTypes.clear(); /*instantiationTypes.put("array", "GoArray"); instantiationTypes.put("map", "GoMap");*/ @@ -87,6 +87,9 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("password", "string"); typeMapping.put("File", "*os.File"); typeMapping.put("file", "*os.File"); + // map binary to string as a workaround + // the correct solution is to use []byte + typeMapping.put("binary", "string"); importMapping = new HashMap(); importMapping.put("time.Time", "time"); diff --git a/samples/client/petstore/go/README.md b/samples/client/petstore/go/README.md new file mode 100644 index 000000000000..7ce753fba9fa --- /dev/null +++ b/samples/client/petstore/go/README.md @@ -0,0 +1,12 @@ +# Go API client for swagger + +## Overview +This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client. + + +## Installation +Put the package under your project folder and add the following in import: +``` + "./swagger" +``` +