Skip to content

Conversation

@tak-amboss
Copy link
Contributor

Description

Enables the use of external JSON schema file references in type generation by adding the cwd parameter to json-schema-to-typescript's compile() function.

Changes

  • Added cwd: process.cwd() parameter to generateTypes() compile call
  • Enables $ref pointers to external .json schema files in typescriptSchema field config
  • Added test case with external schema file reference
  • Documented external schema reference usage in generating-types.mdx

Test Coverage

✅ New test: resolves external schema file references

  • Created test/types/schemas/custom-type.json as external schema
  • Added field with typescriptSchema referencing the external file
  • Verified generated types include the external type correctly

Example Usage

// payload.config.ts { typescript: { schema: [ ({ jsonSchema }) => { jsonSchema.definitions.MyType = { $ref: './schemas/my-type.json' } return jsonSchema }, ] } }

External references are resolved relative to process.cwd().

Related Issue

This was identified during investigation of JSON Schema parser capabilities. The cwd parameter is a standard json-schema-to-typescript option that was not being passed.

- Add cwd parameter to json-schema-to-typescript compile() call - Enables to external .json schema files in typescriptSchema - Add test with external schema file reference - Document external schema reference usage
Copy link
Contributor

@GermanJablo GermanJablo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me! Thank you!

@GermanJablo GermanJablo merged commit cb3a078 into payloadcms:main Nov 27, 2025
98 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

🚀 This is included in version v3.66.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants