From fa12e9c1b2b576d667379057b0753143dee098aa Mon Sep 17 00:00:00 2001 From: Melloware Date: Mon, 13 Nov 2023 17:42:29 -0500 Subject: [PATCH] fix: uppercase method verbs (#1044) --- packages/core/src/generators/options.ts | 2 +- packages/core/src/utils/assertion.ts | 9 +++++++-- tests/mutators/custom-client.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/core/src/generators/options.ts b/packages/core/src/generators/options.ts index 7b812cebf..779f6b0e0 100644 --- a/packages/core/src/generators/options.ts +++ b/packages/core/src/generators/options.ts @@ -268,7 +268,7 @@ export const generateMutatorConfig = ({ ? ',\n headers' : ''; - return `{url: \`${route}\`, method: '${verb}'${headerOptions}${bodyOptions}${queryParamsOptions}${ + return `{url: \`${route}\`, method: '${verb.toUpperCase()}'${headerOptions}${bodyOptions}${queryParamsOptions}${ !isBodyVerb && hasSignal ? `, ${ isExactOptionalPropertyTypes diff --git a/packages/core/src/utils/assertion.ts b/packages/core/src/utils/assertion.ts index 1853f0cdf..7b0feb7bc 100644 --- a/packages/core/src/utils/assertion.ts +++ b/packages/core/src/utils/assertion.ts @@ -1,5 +1,4 @@ import { ReferenceObject, SchemaObject } from 'openapi3-ts'; -import validatorIsUrl from 'validator/lib/isURL'; import { SchemaType, Verbs } from '../types'; import { extname } from './path'; @@ -81,5 +80,11 @@ export const isRootKey = (specKey: string, target: string) => { }; export const isUrl = (str: string) => { - return validatorIsUrl(str, { require_tld: false }); + let givenURL; + try { + givenURL = new URL(str); + } catch (error) { + return false; + } + return givenURL.protocol === 'http:' || givenURL.protocol === 'https:'; }; diff --git a/tests/mutators/custom-client.ts b/tests/mutators/custom-client.ts index a8e21e2de..790ca5388 100644 --- a/tests/mutators/custom-client.ts +++ b/tests/mutators/custom-client.ts @@ -5,7 +5,7 @@ export const customClient = async ({ data, }: { url: string; - method: 'get' | 'post' | 'put' | 'delete' | 'patch'; + method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; params?: Record; data?: BodyType; headers?: Record;