fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #1195 from hey-api/fix/tanstack-query-missing-import

fix: TanStack Query plugin using missing import for infinite query

authored by

Lubos and committed by
GitHub
598028a9 15acb335

+91 -18
+5
.changeset/orange-singers-drop.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: TanStack Query plugin using missing import for infinite query
+1 -1
packages/openapi-ts/src/ir/pagination.ts
··· 1 1 import type { IRSchemaObject } from './ir'; 2 2 3 - export const paginationKeywordsRegExp = /^(cursor|offset|page|start)/; 3 + export const paginationKeywordsRegExp = /^(cursor|offset|page|start)$/; 4 4 5 5 export interface Pagination { 6 6 in: string;
+5 -7
packages/openapi-ts/src/openApi/index.ts
··· 68 68 config: Config; 69 69 parserConfig: ParserConfig; 70 70 spec: unknown; 71 - }) => { 71 + }): IRContext | undefined => { 72 72 const context = new IRContext({ 73 73 config, 74 74 parserConfig, ··· 78 78 switch (context.spec.openapi) { 79 79 case '3.0.3': 80 80 parseV3_0_3(context as IRContext<OpenApiV3_0_3>); 81 - break; 81 + return context; 82 82 case '3.1.0': 83 83 parseV3_1_0(context as IRContext<OpenApiV3_1_0>); 84 - break; 84 + return context; 85 85 default: 86 86 // TODO: parser - uncomment after removing legacy parser. 87 87 // For now, we fall back to legacy parser if spec version 88 88 // is not supported 89 - break; 90 - // throw new Error('Unsupported OpenAPI specification'); 89 + // throw new Error('Unsupported OpenAPI specification'); 90 + return; 91 91 } 92 - 93 - return context; 94 92 };
+7 -8
packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts
··· 17 17 } from '../../../generate/services'; 18 18 import { relativeModulePath } from '../../../generate/utils'; 19 19 import type { IROperationObject } from '../../../ir/ir'; 20 + import { paginationKeywordsRegExp } from '../../../ir/pagination'; 20 21 import { isOperationParameterRequired } from '../../../openApi'; 21 22 import { getOperationKey } from '../../../openApi/common/parser/operation'; 22 23 import type { ··· 100 101 return parameter.in; 101 102 } 102 103 }; 103 - 104 - const paginationWordsRegExp = /^(cursor|offset|page|start)/; 105 104 106 105 const createInfiniteParamsFn = 'createInfiniteParams'; 107 106 const createQueryKeyFn = 'createQueryKey'; ··· 903 902 let paginationField!: Model | OperationParameter; 904 903 905 904 const paginationParameter = operation.parameters.find((parameter) => { 906 - paginationWordsRegExp.lastIndex = 0; 907 - if (paginationWordsRegExp.test(parameter.name)) { 905 + paginationKeywordsRegExp.lastIndex = 0; 906 + if (paginationKeywordsRegExp.test(parameter.name)) { 908 907 paginationField = parameter; 909 908 return true; 910 909 } ··· 919 918 (model) => model.meta?.$ref === ref, 920 919 ); 921 920 return refModel?.properties.find((property) => { 922 - paginationWordsRegExp.lastIndex = 0; 923 - if (paginationWordsRegExp.test(property.name)) { 921 + paginationKeywordsRegExp.lastIndex = 0; 922 + if (paginationKeywordsRegExp.test(property.name)) { 924 923 paginationField = property; 925 924 return true; 926 925 } ··· 928 927 } 929 928 930 929 return parameter.properties.find((property) => { 931 - paginationWordsRegExp.lastIndex = 0; 932 - if (paginationWordsRegExp.test(property.name)) { 930 + paginationKeywordsRegExp.lastIndex = 0; 931 + if (paginationKeywordsRegExp.test(property.name)) { 933 932 paginationField = property; 934 933 return true; 935 934 }
+2 -2
packages/openapi-ts/test/sample.cjs
··· 11 11 // debug: true, 12 12 experimental_parser: true, 13 13 // input: './test/spec/v3.json', 14 - input: './test/spec/3.1.0/full.json', 15 - // input: './test/spec/v2.json', 14 + // input: './test/spec/3.1.0/full.json', 15 + input: './test/spec/tanstack.json', 16 16 // input: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json', 17 17 // name: 'foo', 18 18 output: {
+71
packages/openapi-ts/test/spec/tanstack.json
··· 1 + { 2 + "openapi": "3.0.1", 3 + "info": { 4 + "title": "OpenAPI definition", 5 + "version": "v0" 6 + }, 7 + "paths": { 8 + "/api/search": { 9 + "post": { 10 + "operationId": "search", 11 + "requestBody": { 12 + "content": { 13 + "application/json": { 14 + "schema": { 15 + "$ref": "#/components/schemas/SearchRequest" 16 + } 17 + } 18 + } 19 + } 20 + } 21 + } 22 + }, 23 + "components": { 24 + "schemas": { 25 + "SearchParamsRequest": { 26 + "required": ["contractIds", "contractNumbers"], 27 + "type": "object", 28 + "properties": { 29 + "contractIds": { 30 + "type": "array", 31 + "items": { 32 + "type": "string", 33 + "format": "uuid" 34 + } 35 + }, 36 + "contractNumbers": { 37 + "type": "array", 38 + "items": { 39 + "type": "string" 40 + } 41 + } 42 + } 43 + }, 44 + "SearchRequest": { 45 + "required": ["searchParameters"], 46 + "type": "object", 47 + "properties": { 48 + "searchParameters": { 49 + "$ref": "#/components/schemas/SearchParamsRequest" 50 + }, 51 + "pageParameters": { 52 + "$ref": "#/components/schemas/PageParameters" 53 + } 54 + } 55 + }, 56 + "PageParameters": { 57 + "type": "object", 58 + "properties": { 59 + "offset": { 60 + "type": "integer", 61 + "format": "int32" 62 + }, 63 + "limit": { 64 + "type": "integer", 65 + "format": "int32" 66 + } 67 + } 68 + } 69 + } 70 + } 71 + }