Skip to content

Commit 39bead7

Browse files
authored
refactor: use formatNames utility for interface name generation (#14481)
## Changes This PR consolidates the inline interface name generation logic in `configToJSONSchema.ts` to use the existing `formatNames()` utility function. ## Motivation The inline code `singular(toWords(slug, true))` was duplicating logic already available through `formatNames(slug).singular`. Using the existing utility function: - Reduces code duplication - Maintains consistency with the rest of the codebase - Makes it clear where the interface naming logic lives ## Testing Verified that `formatNames(slug).singular` produces identical results to the previous inline implementation across various slug patterns (plural, singular, edge cases like 'media', 'series', etc.). **No behavioral changes** - this generates the exact same interface names for all collection and global slugs.
1 parent 61a7095 commit 39bead7

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

packages/payload/src/utilities/configToJSONSchema.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'
2-
3-
import pluralize from 'pluralize'
4-
const { singular } = pluralize
5-
61
import type { I18n } from '@payloadcms/translations'
2+
import type { JSONSchema4, JSONSchema4TypeName } from 'json-schema'
73

84
import type { Auth } from '../auth/types.js'
95
import type { SanitizedCollectionConfig } from '../collections/config/types.js'
@@ -14,7 +10,7 @@ import type { SanitizedGlobalConfig } from '../globals/config/types.js'
1410
import { MissingEditorProp } from '../errors/MissingEditorProp.js'
1511
import { fieldAffectsData } from '../fields/config/types.js'
1612
import { generateJobsJSONSchemas } from '../queues/config/generateJobsJSONSchemas.js'
17-
import { toWords } from './formatLabels.js'
13+
import { formatNames } from './formatLabels.js'
1814
import { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js'
1915

2016
const fieldIsRequired = (field: FlattenedField): boolean => {
@@ -758,7 +754,7 @@ export function entityToJSONSchema(
758754

759755
const title = entity.typescript?.interface
760756
? entity.typescript.interface
761-
: singular(toWords(entity.slug, true))
757+
: formatNames(entity.slug).singular
762758

763759
let mutableFields = [...entity.flattenedFields]
764760

@@ -1067,7 +1063,7 @@ export function authCollectionToOperationsJSONSchema(
10671063
additionalProperties: false,
10681064
properties,
10691065
required: Object.keys(properties),
1070-
title: `${singular(toWords(`${config.slug}`, true))}AuthOperations`,
1066+
title: `${formatNames(config.slug).singular}AuthOperations`,
10711067
}
10721068
}
10731069

0 commit comments

Comments
 (0)