Skip to content

fix: pass i18n to entityToJSONSchema for locale-keyed descriptions - #30

Open
alexdeia wants to merge 1 commit into
maximseshuk:mainfrom
alexdeia:fix/localized-field-descriptions
Open

alexdeia wants to merge 1 commit into
maximseshuk:mainfrom
alexdeia:fix/localized-field-descriptions

Conversation

@alexdeia

Copy link
Copy Markdown

What

Pass the build context's i18n through to Payload's entityToJSONSchema when building collection, global and block schemas. It was always passed as undefined.

Why

When a field (or entity) has a locale-keyed admin.description without an en key, e.g. admin: { description: { de: 'Titel' } }, Payload's entityOrFieldToJsDocs reads description[i18n.language] and throws TypeError: Cannot read properties of undefined (reading 'language'). buildDocument catches it and the whole collection is dropped from the spec with only a warning:

@seshuk/payload-plugin-openapi: skipped collection "posts": Cannot read properties of undefined (reading 'language')

With i18n passed, the description resolves in the request language and the collection is documented.

The same bug is in 0.x (0.2.3, Payload 3): there toComponentSchema in src/spec/entitySchemas.ts also passes undefined for i18n. The same two-line change fixes it there, in case you want to cherry-pick it.

How I tested it

  • New unit test in spec/entitySchemas: resolves a locale-keyed field description without an \en` key. It fails without the fix with the TypeError` above and passes with it.
  • pnpm typecheck, pnpm lint, pnpm format, pnpm test:unit (184 passed), pnpm test:int (98 passed).
  • The equivalent patch on 0.2.3 against a Payload 3.90 app with Russian-only field descriptions: the skipped collections now appear in /api/openapi.json.

Checklist

  • pnpm typecheck && pnpm lint && pnpm format && pnpm test:unit pass
  • Tests added or updated for the behavior change
  • README.md and docs/ updated if users will notice the change (not needed: no option or behavior users configure)
  • Commit subjects follow Conventional Commits (fix: ..., feat: ...)

@alexdeia
alexdeia force-pushed the fix/localized-field-descriptions branch from 187430a to deba174 Compare November 18, 2026 14:34

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant