Skip to content

Commit

Permalink
fix: uppercase method verbs (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Nov 13, 2023
1 parent 1c7d4d9 commit fa12e9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/generators/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/utils/assertion.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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:';
};
2 changes: 1 addition & 1 deletion tests/mutators/custom-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const customClient = async <ResponseType>({
data,
}: {
url: string;
method: 'get' | 'post' | 'put' | 'delete' | 'patch';
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
params?: Record<string, string>;
data?: BodyType<unknown>;
headers?: Record<string, string>;
Expand Down

0 comments on commit fa12e9c

Please sign in to comment.