Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Fix parameter getting replaced from path
Browse files Browse the repository at this point in the history
This meant that my previous commit didn't actually do anything, as it was not in the route to extract parameters from.
  • Loading branch information
s-thom authored and fabien0102 committed Jul 20, 2021
1 parent 03abbbc commit e18fa08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ export const generateRestfulComponent = (

route = route.replace(/\{/g, "${"); // `/pet/{id}` => `/pet/${id}`

// Remove the last param of the route if we are in the DELETE case
// Remove the last param of the route if we are in the DELETE case and generating React components/hooks
let lastParamInTheRoute: string | null = null;
if (verb === "delete") {
if (!skipReact && verb === "delete") {
const lastParamInTheRouteRegExp = /\/\$\{(\w+)\}\/?$/;
lastParamInTheRoute = (route.match(lastParamInTheRouteRegExp) || [])[1];
route = route.replace(lastParamInTheRouteRegExp, ""); // `/pet/${id}` => `/pet`
Expand Down Expand Up @@ -344,9 +344,7 @@ export const generateRestfulComponent = (
* </DeleteResource>
*/

const paramsInPath = getParamsInPath(route).filter(
param => !(!skipReact && verb === "delete" && param === lastParamInTheRoute),
);
const paramsInPath = getParamsInPath(route).filter(param => !(verb === "delete" && param === lastParamInTheRoute));
const { query: queryParams = [], path: pathParams = [], header: headerParams = [] } = groupBy(
[...parameters, ...(operation.parameters || [])].map<ParameterObject>(p => {
if (isReference(p)) {
Expand Down
7 changes: 7 additions & 0 deletions src/scripts/tests/__snapshots__/import-open-api.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ export interface FindPetByIdPathParams {
}
export interface DeletePetPathParams {
/**
* ID of pet to delete
*/
id: number
}
export interface UpdatePetPathParams {
/**
Expand Down

0 comments on commit e18fa08

Please sign in to comment.