From 534ff3607f3a4b88040a98b848303217746fb347 Mon Sep 17 00:00:00 2001 From: Jacob Weber Date: Mon, 18 Feb 2019 05:30:56 -0800 Subject: [PATCH 1/3] okhttp-gson: allow array parameters in path using collectionFormat (#2137) * okhttp-gson: allow array parameters in path using collectionFormat * run bin/java-petstore-okhttp-gson-parcelable.sh --- .../libraries/okhttp-gson/ApiClient.mustache | 34 +++++++++++++++++++ .../Java/libraries/okhttp-gson/api.mustache | 2 +- .../org/openapitools/client/ApiClient.java | 34 +++++++++++++++++++ .../org/openapitools/client/ApiClient.java | 34 +++++++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index f6f9c774762..c998ecde892 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -671,6 +671,40 @@ public class ApiClient { return params; } + /** + * Formats the specified collection path parameter to a string value. + * + * @param collectionFormat The collection format of the parameter. + * @param value The value of the parameter. + * @return String representation of the parameter + */ + public String collectionPathParameterToString(String collectionFormat, Collection value) { + // create the value based on the collection format + if ("multi".equals(collectionFormat)) { + // not valid for path params + return parameterToString(value); + } + + // collectionFormat is assumed to be "csv" by default + String delimiter = ","; + + if ("ssv".equals(collectionFormat)) { + delimiter = " "; + } else if ("tsv".equals(collectionFormat)) { + delimiter = "\t"; + } else if ("pipes".equals(collectionFormat)) { + delimiter = "|"; + } + + StringBuilder sb = new StringBuilder() ; + for (Object item : value) { + sb.append(delimiter); + sb.append(parameterToString(item)); + } + + return sb.substring(delimiter.length()); + } + /** * Sanitize filename by removing path. * e.g. ../../sun.gif becomes sun.gif diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/api.mustache index 6e2c3714c0e..a06c2e35d59 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/api.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/api.mustache @@ -86,7 +86,7 @@ public class {{classname}} { // create path and map variables String localVarPath = "{{{path}}}"{{#pathParams}} - .replaceAll("\\{" + "{{baseName}}" + "\\}", localVarApiClient.escapeString({{{paramName}}}.toString())){{/pathParams}}; + .replaceAll("\\{" + "{{baseName}}" + "\\}", localVarApiClient.escapeString({{#collectionFormat}}localVarApiClient.collectionPathParameterToString("{{{collectionFormat}}}", {{{paramName}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.toString(){{/collectionFormat}})){{/pathParams}}; {{javaUtilPrefix}}List localVarQueryParams = new {{javaUtilPrefix}}ArrayList(); {{javaUtilPrefix}}List localVarCollectionQueryParams = new {{javaUtilPrefix}}ArrayList(); diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java index 970b2a690c7..a9fe469fe71 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/ApiClient.java @@ -637,6 +637,40 @@ public class ApiClient { return params; } + /** + * Formats the specified collection path parameter to a string value. + * + * @param collectionFormat The collection format of the parameter. + * @param value The value of the parameter. + * @return String representation of the parameter + */ + public String collectionPathParameterToString(String collectionFormat, Collection value) { + // create the value based on the collection format + if ("multi".equals(collectionFormat)) { + // not valid for path params + return parameterToString(value); + } + + // collectionFormat is assumed to be "csv" by default + String delimiter = ","; + + if ("ssv".equals(collectionFormat)) { + delimiter = " "; + } else if ("tsv".equals(collectionFormat)) { + delimiter = "\t"; + } else if ("pipes".equals(collectionFormat)) { + delimiter = "|"; + } + + StringBuilder sb = new StringBuilder() ; + for (Object item : value) { + sb.append(delimiter); + sb.append(parameterToString(item)); + } + + return sb.substring(delimiter.length()); + } + /** * Sanitize filename by removing path. * e.g. ../../sun.gif becomes sun.gif diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java index 970b2a690c7..a9fe469fe71 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/ApiClient.java @@ -637,6 +637,40 @@ public class ApiClient { return params; } + /** + * Formats the specified collection path parameter to a string value. + * + * @param collectionFormat The collection format of the parameter. + * @param value The value of the parameter. + * @return String representation of the parameter + */ + public String collectionPathParameterToString(String collectionFormat, Collection value) { + // create the value based on the collection format + if ("multi".equals(collectionFormat)) { + // not valid for path params + return parameterToString(value); + } + + // collectionFormat is assumed to be "csv" by default + String delimiter = ","; + + if ("ssv".equals(collectionFormat)) { + delimiter = " "; + } else if ("tsv".equals(collectionFormat)) { + delimiter = "\t"; + } else if ("pipes".equals(collectionFormat)) { + delimiter = "|"; + } + + StringBuilder sb = new StringBuilder() ; + for (Object item : value) { + sb.append(delimiter); + sb.append(parameterToString(item)); + } + + return sb.substring(delimiter.length()); + } + /** * Sanitize filename by removing path. * e.g. ../../sun.gif becomes sun.gif From b4c36425c2b048ee230d230226757b1dca98c7a5 Mon Sep 17 00:00:00 2001 From: MBcom <27956078+MBcom@users.noreply.github.com> Date: Mon, 18 Feb 2019 14:32:30 +0100 Subject: [PATCH 2/3] =?UTF-8?q?changed=20the=20package=20install=20instruc?= =?UTF-8?q?tions=20to=20install=20the=20.tgz=20package=20=E2=80=A6=20(#198?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * changed the package install instructions to install the .tgz package instead of symlinking the package - otherwise you'll get trouble with links on windows * samples added * added samples --- .../src/main/resources/typescript-angular/README.mustache | 6 ++++-- .../src/main/resources/typescript-angular/package.mustache | 3 +-- .../petstore-security-test/typescript-angular/README.md | 4 +++- .../client/petstore/typescript-angular-v2/default/README.md | 4 +++- samples/client/petstore/typescript-angular-v2/npm/README.md | 4 +++- .../client/petstore/typescript-angular-v2/npm/package.json | 3 +-- .../typescript-angular-v2/with-interfaces/README.md | 4 +++- .../client/petstore/typescript-angular-v4.3/npm/README.md | 4 +++- samples/client/petstore/typescript-angular-v4/npm/README.md | 4 +++- .../builds/default/README.md | 4 +++- .../builds/with-npm/README.md | 4 +++- .../builds/default/README.md | 4 +++- .../builds/with-npm/README.md | 4 +++- .../builds/default/README.md | 4 +++- .../builds/with-npm/README.md | 4 +++- .../builds/default/README.md | 4 +++- .../builds/with-npm/README.md | 4 +++- 17 files changed, 48 insertions(+), 20 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache index ad56f190c41..9778346d6d4 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache @@ -31,13 +31,15 @@ _without publishing (not recommended):_ ``` {{#useNgPackagr}} -npm install PATH_TO_GENERATED_PACKAGE/dist --save +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save {{/useNgPackagr}} {{^useNgPackagr}} -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/{{npmName}}-{{npmVersion}}.tgz --save {{/useNgPackagr}} ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ {{#useNgPackagr}} diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/package.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/package.mustache index c2642d8f6f9..d57ec62e8d8 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/package.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/package.mustache @@ -18,8 +18,7 @@ "module": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { - "build": "ngc", - "postinstall": "npm run build" + "build": "ngc && npm pack" }, {{/useNgPackagr}} "peerDependencies": { diff --git a/samples/client/petstore-security-test/typescript-angular/README.md b/samples/client/petstore-security-test/typescript-angular/README.md index b6c812a56ef..6fdf5e362fe 100644 --- a/samples/client/petstore-security-test/typescript-angular/README.md +++ b/samples/client/petstore-security-test/typescript-angular/README.md @@ -25,9 +25,11 @@ npm install @ --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v2/default/README.md b/samples/client/petstore/typescript-angular-v2/default/README.md index ae7f5c307e4..c84c27deaba 100644 --- a/samples/client/petstore/typescript-angular-v2/default/README.md +++ b/samples/client/petstore/typescript-angular-v2/default/README.md @@ -25,9 +25,11 @@ npm install @ --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v2/npm/README.md b/samples/client/petstore/typescript-angular-v2/npm/README.md index 0239b2b8e0b..a994f6c32fc 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/README.md +++ b/samples/client/petstore/typescript-angular-v2/npm/README.md @@ -25,9 +25,11 @@ npm install @swagger/angular2-typescript-petstore@0.0.1 --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/@swagger/angular2-typescript-petstore-0.0.1.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v2/npm/package.json b/samples/client/petstore/typescript-angular-v2/npm/package.json index faed92258ca..23f4a985d13 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/package.json +++ b/samples/client/petstore/typescript-angular-v2/npm/package.json @@ -12,8 +12,7 @@ "module": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { - "build": "ngc", - "postinstall": "npm run build" + "build": "ngc && npm pack" }, "peerDependencies": { "@angular/core": "^2.0.0", diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md b/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md index ae7f5c307e4..c84c27deaba 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/README.md @@ -25,9 +25,11 @@ npm install @ --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/README.md b/samples/client/petstore/typescript-angular-v4.3/npm/README.md index 64246348157..5c6afb247f9 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/README.md +++ b/samples/client/petstore/typescript-angular-v4.3/npm/README.md @@ -25,9 +25,11 @@ npm install @swagger/angular2-typescript-petstore@0.0.1 --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE/dist --save +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE/dist: diff --git a/samples/client/petstore/typescript-angular-v4/npm/README.md b/samples/client/petstore/typescript-angular-v4/npm/README.md index 867df4b48fb..e19758a3a85 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/README.md +++ b/samples/client/petstore/typescript-angular-v4/npm/README.md @@ -25,9 +25,11 @@ npm install @swagger/angular2-typescript-petstore@0.0.1 --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE/dist --save +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE/dist: diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/README.md b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/README.md index b6c812a56ef..6fdf5e362fe 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/README.md +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/README.md @@ -25,9 +25,11 @@ npm install @ --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/README.md b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/README.md index a1d8a9592d8..cc77efb8f00 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/README.md +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/README.md @@ -25,9 +25,11 @@ npm install @swagger/typescript-angular-petstore@1.0.0 --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE/dist --save +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE/dist: diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/README.md b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/README.md index b6c812a56ef..6fdf5e362fe 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/README.md +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/README.md @@ -25,9 +25,11 @@ npm install @ --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/README.md b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/README.md index a1d8a9592d8..cc77efb8f00 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/README.md +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/README.md @@ -25,9 +25,11 @@ npm install @swagger/typescript-angular-petstore@1.0.0 --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE/dist --save +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE/dist: diff --git a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/README.md b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/README.md index b6c812a56ef..6fdf5e362fe 100644 --- a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/README.md +++ b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/README.md @@ -25,9 +25,11 @@ npm install @ --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/README.md b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/README.md index a1d8a9592d8..cc77efb8f00 100644 --- a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/README.md +++ b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/README.md @@ -25,9 +25,11 @@ npm install @swagger/typescript-angular-petstore@1.0.0 --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE/dist --save +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE/dist: diff --git a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/README.md b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/README.md index b6c812a56ef..6fdf5e362fe 100644 --- a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/README.md +++ b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/README.md @@ -25,9 +25,11 @@ npm install @ --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE --save +npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE: diff --git a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/README.md b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/README.md index a1d8a9592d8..cc77efb8f00 100644 --- a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/README.md +++ b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/README.md @@ -25,9 +25,11 @@ npm install @swagger/typescript-angular-petstore@1.0.0 --save _without publishing (not recommended):_ ``` -npm install PATH_TO_GENERATED_PACKAGE/dist --save +npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save ``` +_It's important to take the tgz file, otherwise you'll get trouble with links on windows_ + _using `npm link`:_ In PATH_TO_GENERATED_PACKAGE/dist: From cd1885d29e194f17640c60919f00a7a46a8745d9 Mon Sep 17 00:00:00 2001 From: Diego Mascialino Date: Mon, 18 Feb 2019 10:51:31 -0300 Subject: [PATCH 3/3] Remove API Key Authentication code for go when cookie is used. (#1601) --- modules/openapi-generator/src/main/resources/go/api.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/go/api.mustache b/modules/openapi-generator/src/main/resources/go/api.mustache index 175962642dd..fe72ace87e7 100644 --- a/modules/openapi-generator/src/main/resources/go/api.mustache +++ b/modules/openapi-generator/src/main/resources/go/api.mustache @@ -236,6 +236,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams} {{/hasBodyParam}} {{#authMethods}} {{#isApiKey}} +{{^isKeyInCookie}} if ctx != nil { // API Key Authentication if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { @@ -253,7 +254,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams} {{/isKeyInQuery}} } } - +{{/isKeyInCookie}} {{/isApiKey}} {{/authMethods}} r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)