From 70a7ffaeb48344b0f8b5344f0f6408fc3ceec495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= <20689156+shortcuts@users.noreply.github.com> Date: Mon, 4 Apr 2022 15:25:38 +0200 Subject: [PATCH] fix(generator): handle custom request escaping (#313) --- .github/.cache_version | 2 +- .github/actions/cache/action.yml | 18 +++++++++--------- .github/workflows/check.yml | 10 +++++++++- .../bundlesize.config.json | 12 ------------ openapitools.json | 2 +- .../java/libraries/okhttp-gson/api.mustache | 6 ++++-- templates/javascript/api-single.mustache | 9 +++------ templates/php/api.mustache | 8 ++++---- 8 files changed, 31 insertions(+), 36 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 7f8f011eb7..a8907c025d 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -7 +7.0.2 diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index cd444f6df5..39a012ef40 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -367,7 +367,7 @@ runs: if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} uses: actions/cache@v2 with: - path: clients/algoliasearch-client-php + path: clients/algoliasearch-client-php/lib/Api/SearchApi.php key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( @@ -382,7 +382,7 @@ runs: if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} uses: actions/cache@v2 with: - path: clients/algoliasearch-client-php + path: clients/algoliasearch-client-php/lib/Api/RecommendApi.php key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( @@ -397,7 +397,7 @@ runs: if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} uses: actions/cache@v2 with: - path: clients/algoliasearch-client-php + path: clients/algoliasearch-client-php/lib/Api/PersonalizationApi.php key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( @@ -412,7 +412,7 @@ runs: if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} uses: actions/cache@v2 with: - path: clients/algoliasearch-client-php + path: clients/algoliasearch-client-php/lib/Api/AnalyticsApi.php key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( @@ -427,7 +427,7 @@ runs: if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} uses: actions/cache@v2 with: - path: clients/algoliasearch-client-php + path: clients/algoliasearch-client-php/lib/Api/InsightsApi.php key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( @@ -442,12 +442,12 @@ runs: if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} uses: actions/cache@v2 with: - path: clients/algoliasearch-client-php + path: clients/algoliasearch-client-php/lib/Api/AbtestingApi.php key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-php/lib/Api/AbTestingApi.php', - 'clients/algoliasearch-client-php/lib/Configuration/AbTestingConfig.php', + 'clients/algoliasearch-client-php/lib/Api/AbtestingApi.php', + 'clients/algoliasearch-client-php/lib/Configuration/AbtestingConfig.php', 'specs/bundled/abtesting.yml', 'templates/php/**', 'generators/src/**' @@ -457,7 +457,7 @@ runs: if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} uses: actions/cache@v2 with: - path: clients/algoliasearch-client-php + path: clients/algoliasearch-client-php/lib/Api/QuerySuggestionsApi.php key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e1e445bef8..5fe0f1875e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -263,6 +263,10 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' run: yarn cli build clients java ${{ matrix.client.name }} + - name: Show diff for '${{ matrix.client.name }}' client + if: steps.cache.outputs.cache-hit != 'true' + run: git --no-pager diff + client_php: runs-on: ubuntu-20.04 timeout-minutes: 10 @@ -289,7 +293,7 @@ jobs: id: cache uses: actions/cache@v2 with: - path: ${{ matrix.client.folder }} + path: ${{ format('{0}/lib/Api/{1}.php', matrix.client.folder, matrix.client.api) }} key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( @@ -308,6 +312,10 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' run: yarn cli build clients php ${{ matrix.client.name }} + - name: Show diff for '${{ matrix.client.name }}' client + if: steps.cache.outputs.cache-hit != 'true' + run: git --no-pager diff + client_javascript_tests: runs-on: ubuntu-20.04 timeout-minutes: 10 diff --git a/clients/algoliasearch-client-javascript/bundlesize.config.json b/clients/algoliasearch-client-javascript/bundlesize.config.json index b73ae954b6..af02c71de4 100644 --- a/clients/algoliasearch-client-javascript/bundlesize.config.json +++ b/clients/algoliasearch-client-javascript/bundlesize.config.json @@ -35,18 +35,6 @@ { "path": "packages/recommend/dist/recommend.umd.browser.js", "maxSize": "3.80KB" - }, - { - "path": "packages/client-common/dist/client-common.esm.node.js", - "maxSize": "5.25KB" - }, - { - "path": "packages/requester-browser-xhr/dist/requester-browser-xhr.esm.node.js", - "maxSize": "900B" - }, - { - "path": "packages/requester-node-http/dist/requester-node-http.esm.node.js", - "maxSize": "1.15KB" } ] } diff --git a/openapitools.json b/openapitools.json index 4e23ce7e55..7c303bd421 100644 --- a/openapitools.json +++ b/openapitools.json @@ -366,7 +366,7 @@ "invokerPackage": "Algolia\\AlgoliaSearch", "globalProperty": "apis,supportingFiles", "additionalProperties": { - "configClassname": "AbTestingConfig", + "configClassname": "AbtestingConfig", "hasRegionalHost": true, "allowedRegions": "us-de", "variableNamingConvention": "camelCase", diff --git a/templates/java/libraries/okhttp-gson/api.mustache b/templates/java/libraries/okhttp-gson/api.mustache index 77695f0282..4b0b5a2afa 100644 --- a/templates/java/libraries/okhttp-gson/api.mustache +++ b/templates/java/libraries/okhttp-gson/api.mustache @@ -111,8 +111,10 @@ public class {{classname}} extends ApiClient { Object bodyObj = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; // create path and map variables - String requestPath = "{{{path}}}"{{#pathParams}} - .replaceAll("\\{" + "{{baseName}}" + "\\}", this.escapeString({{{paramName}}}.toString())){{/pathParams}}; + String requestPath = "{{{path}}}"{{#vendorExtensions}}{{#pathParams}}.replaceAll( + {{=<% %>=}}"\\{<%baseName%>\\}"<%={{ }}=%>, + {{#x-is-custom-request}}{{{paramName}}}.toString(){{/x-is-custom-request}}{{^x-is-custom-request}}this.escapeString({{{paramName}}}.toString()){{/x-is-custom-request}} + ){{/pathParams}}{{/vendorExtensions}}; {{javaUtilPrefix}}List queryParams = new {{javaUtilPrefix}}ArrayList(); {{javaUtilPrefix}}Map headers = new {{javaUtilPrefix}}HashMap(); diff --git a/templates/javascript/api-single.mustache b/templates/javascript/api-single.mustache index 140366c126..35e18d6266 100644 --- a/templates/javascript/api-single.mustache +++ b/templates/javascript/api-single.mustache @@ -202,12 +202,9 @@ export function create{{capitalizedApiName}}Api(options: CreateClientOptions{{#h {{/allParams.0}} requestOptions?: RequestOptions ) : Promise<{{{returnType}}}> { - const requestPath = '{{{path}}}'{{#pathParams}}.replace( - {{=<% %>=}} - '{<%baseName%>}', - <%={{ }}=%> - encodeURIComponent(String({{paramName}})) - ){{/pathParams}}; + const requestPath = '{{{path}}}'{{#vendorExtensions}}{{#pathParams}}.replace( + {{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>,{{#x-is-custom-request}}String({{paramName}}){{/x-is-custom-request}}{{^x-is-custom-request}}encodeURIComponent(String({{paramName}})){{/x-is-custom-request}} + ){{/pathParams}}{{/vendorExtensions}}; const headers: Headers = {}; const queryParameters: QueryParameters = {}; diff --git a/templates/php/api.mustache b/templates/php/api.mustache index d63c43d753..efaf6311f5 100644 --- a/templates/php/api.mustache +++ b/templates/php/api.mustache @@ -231,7 +231,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts; } {{/isExplode}} {{/queryParams}} - {{#pathParams}} + {{#vendorExtensions}}{{#pathParams}} // path params {{#collectionFormat}} if (is_array(${{paramName}})) { @@ -240,12 +240,12 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts; {{/collectionFormat}} if (${{paramName}} !== null) { $resourcePath = str_replace( - '{' . '{{baseName}}' . '}', - ObjectSerializer::toPathValue(${{paramName}}), + {{=<% %>=}}'{<%baseName%>}'<%={{ }}=%>, + {{#x-is-custom-request}}{{paramName}}{{/x-is-custom-request}}{{^x-is-custom-request}}ObjectSerializer::toPathValue(${{paramName}}){{/x-is-custom-request}}, $resourcePath ); } - {{/pathParams}} + {{/pathParams}}{{/vendorExtensions}} {{#bodyParams}} if (isset(${{paramName}})) {