diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index ff65cf8a8..c43407f0e 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -28,3 +28,5 @@ export const VERBS_WITH_BODY = [ export const URL_REGEX = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/; + +export const TEMPLATE_TAG_REGEX = /\${(.+?)}/g; // For replace of 'thing' ${thing} diff --git a/packages/core/src/getters/route.ts b/packages/core/src/getters/route.ts index ba43061ce..9ab29f031 100644 --- a/packages/core/src/getters/route.ts +++ b/packages/core/src/getters/route.ts @@ -1,6 +1,6 @@ import { camel, sanitize } from '../utils'; +import { TEMPLATE_TAG_REGEX } from '../constants'; -const TEMPLATE_TAG_REGEX = /\${(\w+)}/g; // For replace of 'thing' ${thing} const TEMPLATE_TAG_IN_PATH_REGEX = /\/([\w]+)(?:\$\{)/g; // all dynamic parts of path const hasParam = (path: string): boolean => /[^{]*{[\w*_-]*}.*/.test(path); diff --git a/packages/query/src/utils.ts b/packages/query/src/utils.ts index 53bb185c0..49285ae38 100644 --- a/packages/query/src/utils.ts +++ b/packages/query/src/utils.ts @@ -11,6 +11,7 @@ import { upath, GetterProps, GetterPropType, + TEMPLATE_TAG_REGEX, } from '@orval/core'; import chalk from 'chalk'; @@ -122,7 +123,7 @@ export const wrapRouteParameters = ( route: string, prepend: string, append: string, -): string => route.replaceAll(/\${(.+?)}/g, `\${${prepend}$1${append}}`); +): string => route.replaceAll(TEMPLATE_TAG_REGEX, `\${${prepend}$1${append}}`); export const makeRouteSafe = (route: string): string => wrapRouteParameters(route, 'encodeURIComponent(String(', '))');