Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: automatically delete when there is a slash at the end of baseurl #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion v2/api-validator/src/client/generated/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { ApiResult } from './ApiResult';
import { CancelablePromise } from './CancelablePromise';
import type { OnCancel } from './CancelablePromise';
import type { OpenAPIConfig } from './OpenAPI';
import { removeTrailingSlash } from '../../../url-helpers';

export const isDefined = <T>(value: T | null | undefined): value is Exclude<T, null | undefined> => {
return value !== undefined && value !== null;
Expand Down Expand Up @@ -101,7 +102,8 @@ const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
return substring;
});

const url = `${config.BASE}${path}`;
const prefix = removeTrailingSlash(config.BASE);
const url = `${prefix}${path}`;
if (options.query) {
return `${url}${getQueryString(options.query)}`;
}
Expand Down
6 changes: 5 additions & 1 deletion v2/api-validator/src/url-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import config from './config';

export function getServerUrlPathPrefix(): string {
const prefix = new URL(config.get('client.serverBaseUrl')).pathname;
return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
return removeTrailingSlash(prefix);
}

export function removeServerPathPrefixFromRelativeUrl(relativeUrl: string): string {
Expand All @@ -15,3 +15,7 @@ export function getRelativeUrlWithoutPathPrefix(absoluteUrl: string): string {
const relativeUrl = parsedUrl.pathname + parsedUrl.search;
return removeServerPathPrefixFromRelativeUrl(relativeUrl);
}

export function removeTrailingSlash(path: string): string {
return path.endsWith('/') ? path.slice(0, -1) : path;
}