Skip to content

Commit

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

Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed Nov 18, 2024
1 parent ba69002 commit 67c3c38
Showing 1 changed file with 3 additions and 3 deletions.
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 67c3c38

Please sign in to comment.