Skip to content

Commit

Permalink
Fixed path component filter (#921)
Browse files Browse the repository at this point in the history
* Fixed path component filter
JS considers `''` to be false. Updating the filter to include blank strings.

Signed-off-by: Theo Truong <[email protected]>

* # make sure that '' in param in considered null as well

Signed-off-by: Theo Truong <[email protected]>

---------

Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong authored Nov 18, 2024
1 parent ba69002 commit 55fd7d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const kConfigErr = Symbol('configuration error');
function noop() {}

function parsePathParam(param) {
if (param == null) return null;
if (param == null || param === '') return null;
return encodeURIComponent(param);
}

Expand Down
6 changes: 3 additions & 3 deletions api_generator/src/spec_parser/ApiPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export default class ApiPath {
}).join(' + ')
}

// turn ['one', a, b, 'two/three', c] into `['/one', a, b, 'two/three', c].filter(c => c).join('/')`
// turn [a, b, 'one', c] into `['', a, b, 'one', c].filter(c => c).join('/')`
// turn ['one', a, b, 'two/three', c] into `['/one', a, b, 'two/three', c].filter(c => c != null).join('/')`
// turn [a, b, 'one', c] into `['', a, b, 'one', c].filter(c => c != null).join('/')`
#build_optional (): string {
const components = _.clone(this.components)
if (components[0].startsWith("'")) components[0] = `'/${components[0].slice(1)}`
else components.unshift("''")
return `[${components.join(', ')}].filter(c => c).join('/')`
return `[${components.join(', ')}].filter(c => c != null).join('/')`
}

// turn '/one/{a}/{b}/two/three/{c}' into ['one', a, b, 'two/three', c]
Expand Down

0 comments on commit 55fd7d1

Please sign in to comment.