-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1178 from hey-api/feat/parser-plugin-tanstack-query
feat: rewrite tanstack query plugin to new parser
- Loading branch information
Showing
56 changed files
with
7,875 additions
and
7,210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { IRSchemaObject } from './ir'; | ||
|
||
export const paginationKeywordsRegExp = /^(cursor|offset|page|start)/; | ||
|
||
export interface Pagination { | ||
in: string; | ||
name: string; | ||
schema: IRSchemaObject; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/openapi-ts/src/openApi/3.1.0/parser/pagination.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import type { IRContext } from '../../../ir/context'; | ||
import { paginationKeywordsRegExp } from '../../../ir/pagination'; | ||
import type { ParameterObject, RequestBodyObject } from '../types/spec'; | ||
import { type SchemaObject } from '../types/spec'; | ||
import { mediaTypeObject } from './mediaType'; | ||
import { getSchemaTypes } from './schema'; | ||
|
||
// We handle only simple values for now, up to 1 nested field | ||
export const paginationField = ({ | ||
context, | ||
name, | ||
schema, | ||
}: { | ||
context: IRContext; | ||
name: string; | ||
schema: SchemaObject; | ||
}): boolean | string => { | ||
paginationKeywordsRegExp.lastIndex = 0; | ||
if (paginationKeywordsRegExp.test(name)) { | ||
return true; | ||
} | ||
|
||
if (schema.$ref) { | ||
const ref = context.resolveRef< | ||
ParameterObject | RequestBodyObject | SchemaObject | ||
>(schema.$ref); | ||
|
||
if ('content' in ref || 'in' in ref) { | ||
let refSchema: SchemaObject | undefined; | ||
|
||
if ('in' in ref) { | ||
refSchema = ref.schema; | ||
} | ||
|
||
if (!refSchema) { | ||
// parameter or body | ||
const content = mediaTypeObject({ content: ref.content }); | ||
if (content?.schema) { | ||
refSchema = content.schema; | ||
} | ||
} | ||
|
||
if (!refSchema) { | ||
return false; | ||
} | ||
|
||
return paginationField({ | ||
context, | ||
name, | ||
schema: refSchema, | ||
}); | ||
} | ||
|
||
return paginationField({ | ||
context, | ||
name, | ||
schema: ref, | ||
}); | ||
} | ||
|
||
for (const name in schema.properties) { | ||
paginationKeywordsRegExp.lastIndex = 0; | ||
|
||
if (paginationKeywordsRegExp.test(name)) { | ||
const property = schema.properties[name]; | ||
|
||
if (typeof property !== 'boolean') { | ||
const schemaTypes = getSchemaTypes({ schema: property }); | ||
|
||
if ( | ||
schemaTypes.includes('boolean') || | ||
schemaTypes.includes('integer') || | ||
schemaTypes.includes('number') || | ||
schemaTypes.includes('string') | ||
) { | ||
return name; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
}; |
Oops, something went wrong.