Skip to content

Commit

Permalink
Merge pull request #1060 from hey-api/fix/operation-path-colon
Browse files Browse the repository at this point in the history
fix: handle colon in operation path
  • Loading branch information
mrlubos authored Sep 19, 2024
2 parents f94cb64 + 8d66c08 commit 6c28a91
Show file tree
Hide file tree
Showing 66 changed files with 838 additions and 69 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-deers-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: handle colon in operation path
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Operation, OperationParameter } from './client';
export interface Config {
debug?: boolean;
filterFn?: {
operation?: (operation: Operation) => boolean;
operation?: (operationKey: string) => boolean;
operationParameter?: (parameter: OperationParameter) => boolean;
};
nameFn: {
Expand Down
19 changes: 9 additions & 10 deletions packages/openapi-ts/src/openApi/v2/parser/getOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,18 @@ export const getOperations = ({
}
}

const operation = getOperation({
method,
op,
openApi,
pathParams: pathParameters,
types,
url,
});

if (
!config.filterFn?.operation ||
config.filterFn?.operation(operation)
config.filterFn?.operation(operationKey)
) {
const operation = getOperation({
method,
op,
openApi,
pathParams: pathParameters,
types,
url,
});
operations.push(operation);
}
}
Expand Down
19 changes: 9 additions & 10 deletions packages/openapi-ts/src/openApi/v3/parser/getOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,18 @@ export const getOperations = ({
}
}

const operation = getOperation({
method,
op,
openApi,
pathParams: pathParameters,
types,
url,
});

if (
!config.filterFn?.operation ||
config.filterFn?.operation(operation)
config.filterFn?.operation(operationKey)
) {
const operation = getOperation({
method,
op,
openApi,
pathParams: pathParameters,
types,
url,
});
operations.push(operation);
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/openapi-ts/src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { camelCase } from './camelCase';
import { getConfig, isStandaloneClient } from './config';
import { transformTypeKeyName } from './type';

export const operationFilterFn = (operation: Operation): boolean => {
export const operationFilterFn = (operationKey: string): boolean => {
const config = getConfig();

const regexp = config.services.filter
? new RegExp(config.services.filter)
: undefined;
const operationKey = `${operation.method} ${operation.path}`;
return !regexp || regexp.test(operationKey);
};

Expand Down Expand Up @@ -52,7 +50,7 @@ export const operationNameFn = (operation: Omit<Operation, 'name'>): string => {
urlWithoutPlaceholders = urlWithoutPlaceholders
.replace(/{(.*?)}/g, 'by-$1')
// replace slashes with hyphens for camelcase method at the end
.replace(/\//g, '-');
.replace(/[/:]/g, '-');

return camelCase({
input: `${operation.method}-${urlWithoutPlaceholders}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from './client';
import type { ImportData, ImportError, ImportResponse, ApiVversionOdataControllerCountError, ApiVversionOdataControllerCountResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseError, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseError, CallWithResponseAndNoContentResponseResponse, DummyAError, DummyAResponse, DummyBError, DummyBResponse, CallWithResponseError, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesError, TypesResponse, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, FileResponseError, FileResponseResponse, ComplexTypesData, ComplexTypesError, ComplexTypesResponse, MultipartRequestData, MultipartResponseError, MultipartResponseResponse, ComplexParamsData, ComplexParamsError, ComplexParamsResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen';
import type { ImportData, ImportError, ImportResponse, ApiVversionOdataControllerCountError, ApiVversionOdataControllerCountResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseError, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseError, CallWithResponseAndNoContentResponseResponse, DummyAError, DummyAResponse, DummyBError, DummyBResponse, CallWithResponseError, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, TypesError, TypesResponse, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, FileResponseError, FileResponseResponse, ComplexTypesData, ComplexTypesError, ComplexTypesResponse, MultipartRequestData, MultipartResponseError, MultipartResponseResponse, ComplexParamsData, ComplexParamsError, ComplexParamsResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen';

export const client = createClient(createConfig());

Expand All @@ -20,6 +20,11 @@ export const apiVVersionOdataControllerCount = <ThrowOnError extends boolean = f
url: '/api/v{api-version}/simple/$count'
}); };

export const getApiVbyApiVersionSimpleOperation = <ThrowOnError extends boolean = false>(options: Options<GetApiVbyApiVersionSimpleOperationData, ThrowOnError>) => { return (options?.client ?? client).get<GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, ThrowOnError>({
...options,
url: '/api/v{api-version}/simple:operation'
}); };

export const getCallWithoutParametersAndResponse = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { return (options?.client ?? client).get<void, unknown, ThrowOnError>({
...options,
url: '/api/v{api-version}/simple'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,19 @@ export type ApiVversionOdataControllerCountResponse = (Model_From_Zendesk);

export type ApiVversionOdataControllerCountError = unknown;

export type GetApiVbyApiVersionSimpleOperationData = {
path: {
/**
* foo in method
*/
foo_param: string;
};
};

export type GetApiVbyApiVersionSimpleOperationResponse = (number);

export type GetApiVbyApiVersionSimpleOperationError = (ModelWithBoolean);

export type DeleteFooData3 = {
headers: {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-axios';
import type { ImportData, ImportError, ImportResponse, ApiVversionOdataControllerCountError, ApiVversionOdataControllerCountResponse, DeleteFooData3, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, CallWithDescriptionsData, DeprecatedCallData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseError, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseError, CallWithResponseAndNoContentResponseResponse, CallWithResponseError, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, DummyAError, DummyAResponse, DummyBError, DummyBResponse, CollectionFormatData, TypesData, TypesError, TypesResponse, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, FileResponseError, FileResponseResponse, ComplexTypesData, ComplexTypesError, ComplexTypesResponse, ComplexParamsData, ComplexParamsError, ComplexParamsResponse, MultipartRequestData, MultipartResponseError, MultipartResponseResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen';
import type { ImportData, ImportError, ImportResponse, GetApiVbyApiVersionSimpleOperationData, GetApiVbyApiVersionSimpleOperationError, GetApiVbyApiVersionSimpleOperationResponse, ApiVversionOdataControllerCountError, ApiVversionOdataControllerCountResponse, DeleteFooData3, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, CallWithDescriptionsData, DeprecatedCallData, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithNoContentResponseError, CallWithNoContentResponseResponse, CallWithResponseAndNoContentResponseError, CallWithResponseAndNoContentResponseResponse, CallWithResponseError, CallWithResponseResponse, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, DummyAError, DummyAResponse, DummyBError, DummyBResponse, CollectionFormatData, TypesData, TypesError, TypesResponse, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, FileResponseError, FileResponseResponse, ComplexTypesData, ComplexTypesError, ComplexTypesResponse, ComplexParamsData, ComplexParamsError, ComplexParamsResponse, MultipartRequestData, MultipartResponseError, MultipartResponseResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from './types.gen';

export const client = createClient(createConfig());

Expand All @@ -20,6 +20,13 @@ export class DefaultService {
});
}

public static getApiVbyApiVersionSimpleOperation<ThrowOnError extends boolean = false>(options: Options<GetApiVbyApiVersionSimpleOperationData, ThrowOnError>) {
return (options?.client ?? client).get<GetApiVbyApiVersionSimpleOperationResponse, GetApiVbyApiVersionSimpleOperationError, ThrowOnError>({
...options,
url: '/api/v{api-version}/simple:operation'
});
}

}

export class SimpleService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,19 @@ export type ImportResponse = (Model_From_Zendesk | ModelWithReadOnlyAndWriteOnly

export type ImportError = unknown;

export type GetApiVbyApiVersionSimpleOperationData = {
path: {
/**
* foo in method
*/
foo_param: string;
};
};

export type GetApiVbyApiVersionSimpleOperationResponse = (number);

export type GetApiVbyApiVersionSimpleOperationError = (ModelWithBoolean);

export type ApiVversionOdataControllerCountResponse = (Model_From_Zendesk);

export type ApiVversionOdataControllerCountError = unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import type { Options } from '@hey-api/client-axios';
import { queryOptions, type UseMutationOptions, type DefaultError, infiniteQueryOptions, type InfiniteData } from '@tanstack/react-query';
import { client, export_, import_, apiVVersionOdataControllerCount, getCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, postCallWithoutParametersAndResponse, deleteCallWithoutParametersAndResponse, patchCallWithoutParametersAndResponse, deleteFoo, callWithDescriptions, deprecatedCall, callWithParameters, callWithWeirdParameterNames, getCallWithOptionalParam, postCallWithOptionalParam, postApiVbyApiVersionRequestBody, postApiVbyApiVersionFormData, callWithDefaultParameters, callWithDefaultOptionalParameters, callToTestOrderOfParams, duplicateName, duplicateName1, duplicateName2, duplicateName3, callWithNoContentResponse, callWithResponseAndNoContentResponse, dummyA, dummyB, callWithResponse, callWithDuplicateResponses, callWithResponses, collectionFormat, types, uploadFile, fileResponse, complexTypes, multipartRequest, multipartResponse, complexParams, callWithResultFromHeader, testErrorCode, nonAsciiæøåÆøÅöôêÊ字符串, putWithFormUrlEncoded } from '../services.gen';
import type { ImportData, ImportError, ImportResponse, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsData, ComplexParamsError, ComplexParamsResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from '../types.gen';
import { client, export_, import_, apiVVersionOdataControllerCount, getApiVbyApiVersionSimpleOperation, getCallWithoutParametersAndResponse, putCallWithoutParametersAndResponse, postCallWithoutParametersAndResponse, deleteCallWithoutParametersAndResponse, patchCallWithoutParametersAndResponse, deleteFoo, callWithDescriptions, deprecatedCall, callWithParameters, callWithWeirdParameterNames, getCallWithOptionalParam, postCallWithOptionalParam, postApiVbyApiVersionRequestBody, postApiVbyApiVersionFormData, callWithDefaultParameters, callWithDefaultOptionalParameters, callToTestOrderOfParams, duplicateName, duplicateName1, duplicateName2, duplicateName3, callWithNoContentResponse, callWithResponseAndNoContentResponse, dummyA, dummyB, callWithResponse, callWithDuplicateResponses, callWithResponses, collectionFormat, types, uploadFile, fileResponse, complexTypes, multipartRequest, multipartResponse, complexParams, callWithResultFromHeader, testErrorCode, nonAsciiæøåÆøÅöôêÊ字符串, putWithFormUrlEncoded } from '../services.gen';
import type { ImportData, ImportError, ImportResponse, GetApiVbyApiVersionSimpleOperationData, DeleteFooData3, CallWithDescriptionsData, DeprecatedCallData, CallWithParametersData, CallWithWeirdParameterNamesData, GetCallWithOptionalParamData, PostCallWithOptionalParamData, PostCallWithOptionalParamError, PostCallWithOptionalParamResponse, PostApiVbyApiVersionRequestBodyData, PostApiVbyApiVersionFormDataData, CallWithDefaultParametersData, CallWithDefaultOptionalParametersData, CallToTestOrderOfParamsData, CallWithDuplicateResponsesError, CallWithDuplicateResponsesResponse, CallWithResponsesError, CallWithResponsesResponse, CollectionFormatData, TypesData, UploadFileData, UploadFileError, UploadFileResponse, FileResponseData, ComplexTypesData, MultipartRequestData, ComplexParamsData, ComplexParamsError, ComplexParamsResponse, CallWithResultFromHeaderError, CallWithResultFromHeaderResponse, TestErrorCodeData, TestErrorCodeError, TestErrorCodeResponse, NonAsciiæøåÆøÅöôêÊ字符串Data, NonAsciiæøåÆøÅöôêÊ字符串Error, NonAsciiæøåÆøÅöôêÊ字符串Response, PutWithFormUrlEncodedData } from '../types.gen';
import type { AxiosError } from 'axios';

type QueryKey<TOptions extends Options> = [
Expand Down Expand Up @@ -91,6 +91,22 @@ export const apiVVersionOdataControllerCountOptions = (options?: Options) => { r
queryKey: apiVVersionOdataControllerCountQueryKey(options)
}); };

export const getApiVbyApiVersionSimpleOperationQueryKey = (options: Options<GetApiVbyApiVersionSimpleOperationData>) => [
createQueryKey("getApiVbyApiVersionSimpleOperation", options)
];

export const getApiVbyApiVersionSimpleOperationOptions = (options: Options<GetApiVbyApiVersionSimpleOperationData>) => { return queryOptions({
queryFn: async ({ queryKey }) => {
const { data } = await getApiVbyApiVersionSimpleOperation({
...options,
...queryKey[0],
throwOnError: true
});
return data;
},
queryKey: getApiVbyApiVersionSimpleOperationQueryKey(options)
}); };

export const getCallWithoutParametersAndResponseQueryKey = (options?: Options) => [
createQueryKey("getCallWithoutParametersAndResponse", options)
];
Expand Down
Loading

0 comments on commit 6c28a91

Please sign in to comment.