Skip to content

Commit

Permalink
fix(generator): handle custom request escaping (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Apr 4, 2022
1 parent 111102c commit 70a7ffa
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7
7.0.2
18 changes: 9 additions & 9 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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/**'
Expand All @@ -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(
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions clients/algoliasearch-client-javascript/bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
2 changes: 1 addition & 1 deletion openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
"invokerPackage": "Algolia\\AlgoliaSearch",
"globalProperty": "apis,supportingFiles",
"additionalProperties": {
"configClassname": "AbTestingConfig",
"configClassname": "AbtestingConfig",
"hasRegionalHost": true,
"allowedRegions": "us-de",
"variableNamingConvention": "camelCase",
Expand Down
6 changes: 4 additions & 2 deletions templates/java/libraries/okhttp-gson/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair> queryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
{{javaUtilPrefix}}Map<String, String> headers = new {{javaUtilPrefix}}HashMap<String, String>();
Expand Down
9 changes: 3 additions & 6 deletions templates/javascript/api-single.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
8 changes: 4 additions & 4 deletions templates/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ use {{invokerPackage}}\RetryStrategy\ClusterHosts;
}
{{/isExplode}}
{{/queryParams}}
{{#pathParams}}
{{#vendorExtensions}}{{#pathParams}}
// path params
{{#collectionFormat}}
if (is_array(${{paramName}})) {
Expand All @@ -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}})) {
Expand Down

0 comments on commit 70a7ffa

Please sign in to comment.