Skip to content

Commit dd1e86f

Browse files
committed
refactor: update paginationRegExp initialization to use config
1 parent d7228e1 commit dd1e86f

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

packages/openapi-ts/src/openApi/2.0.x/parser/pagination.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const paginationField = ({
2929
in: undefined;
3030
};
3131
}): boolean | string => {
32-
const paginationRegExp = getPaginationKeywordsRegExp();
32+
const paginationRegExp = getPaginationKeywordsRegExp(context.config);
3333
paginationRegExp.lastIndex = 0;
3434
if (paginationRegExp.test(name)) {
3535
return true;
@@ -84,11 +84,14 @@ export const paginationField = ({
8484
}
8585

8686
for (const name in schema.properties) {
87-
const paginationRegExp = getPaginationKeywordsRegExp();
87+
const paginationRegExp = getPaginationKeywordsRegExp(context.config);
8888
paginationRegExp.lastIndex = 0;
8989

9090
if (paginationRegExp.test(name)) {
91-
const property = schema.properties[name]!;
91+
const property = schema.properties[name];
92+
93+
// Skip if property doesn't exist
94+
if (!property) continue;
9295

9396
if (typeof property !== 'boolean' && !('$ref' in property)) {
9497
const schemaType = getSchemaType({ schema: property });

packages/openapi-ts/src/openApi/3.0.x/parser/pagination.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const paginationField = ({
2828
name: string;
2929
schema: SchemaObject | ReferenceObject;
3030
}): boolean | string => {
31-
const paginationRegExp = getPaginationKeywordsRegExp();
31+
const paginationRegExp = getPaginationKeywordsRegExp(context.config);
3232
paginationRegExp.lastIndex = 0;
3333
if (paginationRegExp.test(name)) {
3434
return true;
@@ -73,11 +73,14 @@ export const paginationField = ({
7373
}
7474

7575
for (const name in schema.properties) {
76-
const paginationRegExp = getPaginationKeywordsRegExp();
76+
const paginationRegExp = getPaginationKeywordsRegExp(config);
7777
paginationRegExp.lastIndex = 0;
7878

7979
if (paginationRegExp.test(name)) {
80-
const property = schema.properties[name]!;
80+
const property = schema.properties[name];
81+
82+
// Skip if property doesn't exist
83+
if (!property) continue;
8184

8285
if (typeof property !== 'boolean' && !('$ref' in property)) {
8386
const schemaType = getSchemaType({ schema: property });
@@ -92,6 +95,7 @@ export const paginationField = ({
9295

9396
for (const allOf of schema.allOf ?? []) {
9497
const pagination = paginationField({
98+
config,
9599
context,
96100
name,
97101
schema: allOf,

packages/openapi-ts/src/openApi/3.1.x/parser/pagination.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const paginationField = ({
2424
name: string;
2525
schema: SchemaObject;
2626
}): boolean | string => {
27-
const paginationRegExp = getPaginationKeywordsRegExp();
27+
const paginationRegExp = getPaginationKeywordsRegExp(context.config);
2828
paginationRegExp.lastIndex = 0;
2929
if (paginationRegExp.test(name)) {
3030
return true;
@@ -69,11 +69,14 @@ export const paginationField = ({
6969
}
7070

7171
for (const name in schema.properties) {
72-
const paginationRegExp = getPaginationKeywordsRegExp();
72+
const paginationRegExp = getPaginationKeywordsRegExp(context.config);
7373
paginationRegExp.lastIndex = 0;
7474

7575
if (paginationRegExp.test(name)) {
76-
const property = schema.properties[name]!;
76+
const property = schema.properties[name];
77+
78+
// Skip if property doesn't exist
79+
if (!property) continue;
7780

7881
if (typeof property !== 'boolean') {
7982
// TODO: resolve deeper references
@@ -85,8 +88,13 @@ export const paginationField = ({
8588
(schema) => schema.type !== 'null',
8689
);
8790
if (nonNullCompositionSchemas.length === 1) {
91+
const firstSchema = nonNullCompositionSchemas[0];
92+
93+
// Skip if schema doesn't exist
94+
if (!firstSchema) continue;
95+
8896
const schemaTypes = getSchemaTypes({
89-
schema: nonNullCompositionSchemas[0]!,
97+
schema: firstSchema,
9098
});
9199
if (isPaginationType(schemaTypes)) {
92100
return name;

packages/openapi-ts/src/plugins/@tanstack/query-core/plugin-legacy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ export const handlerLegacy: Plugin.LegacyHandler<
900900
let paginationField!: Model | OperationParameter;
901901

902902
const paginationParameter = operation.parameters.find((parameter) => {
903-
const paginationRegExp = getPaginationKeywordsRegExp();
903+
const paginationRegExp = getPaginationKeywordsRegExp(config);
904904
paginationRegExp.lastIndex = 0;
905905
if (paginationRegExp.test(parameter.name)) {
906906
paginationField = parameter;
@@ -917,7 +917,9 @@ export const handlerLegacy: Plugin.LegacyHandler<
917917
(model) => model.meta?.$ref === ref,
918918
);
919919
return refModel?.properties.find((property) => {
920-
const paginationRegExp = getPaginationKeywordsRegExp();
920+
const paginationRegExp = getPaginationKeywordsRegExp(
921+
plugin.config,
922+
);
921923
paginationRegExp.lastIndex = 0;
922924
if (paginationRegExp.test(property.name)) {
923925
paginationField = property;
@@ -927,7 +929,7 @@ export const handlerLegacy: Plugin.LegacyHandler<
927929
}
928930

929931
return parameter.properties.find((property) => {
930-
const paginationRegExp = getPaginationKeywordsRegExp();
932+
const paginationRegExp = getPaginationKeywordsRegExp(plugin.config);
931933
paginationRegExp.lastIndex = 0;
932934
if (paginationRegExp.test(property.name)) {
933935
paginationField = property;

0 commit comments

Comments
 (0)