Skip to content

Commit 2118c6c

Browse files
authored
feat: exposes helpful args to ts schema gen (#10984)
You can currently extend Payload's type generation if you provide additional JSON schema definitions yourself. But, Payload has helpful functions like `fieldsToJSONSchema` which would be nice to easily re-use. The only issue is that the `fieldsToJSONSchema` requires arguments which are difficult to access from the context of plugins, etc. They should really be provided at runtime to the `config.typescript.schema` functions. This PR does exactly that. Adds more args to the `schema` extension point to make utility functions easier to re-use.
1 parent a07fd9e commit 2118c6c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/payload/src/config/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {
22
DefaultTranslationKeys,
33
DefaultTranslationsObject,
4+
I18n,
45
I18nClient,
56
I18nOptions,
67
TFunction,
@@ -1122,7 +1123,16 @@ export type Config = {
11221123
* Allows you to modify the base JSON schema that is generated during generate:types. This JSON schema will be used
11231124
* to generate the TypeScript interfaces.
11241125
*/
1125-
schema?: Array<(args: { jsonSchema: JSONSchema4 }) => JSONSchema4>
1126+
schema?: Array<
1127+
(args: {
1128+
collectionIDFieldTypes: {
1129+
[key: string]: 'number' | 'string'
1130+
}
1131+
config: SanitizedConfig
1132+
i18n: I18n
1133+
jsonSchema: JSONSchema4
1134+
}) => JSONSchema4
1135+
>
11261136
}
11271137
/**
11281138
* Customize the handling of incoming file uploads for collections that have uploads enabled.

packages/payload/src/utilities/configToJSONSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ export function configToJSONSchema(
11021102

11031103
if (config?.typescript?.schema?.length) {
11041104
for (const schema of config.typescript.schema) {
1105-
jsonSchema = schema({ jsonSchema })
1105+
jsonSchema = schema({ collectionIDFieldTypes, config, i18n, jsonSchema })
11061106
}
11071107
}
11081108

0 commit comments

Comments
 (0)