mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 19:04:38 +00:00
fix: refactor openAPI log (#24182)
* fix: refactor openAPI log * fix: move logs to debug level
This commit is contained in:
parent
e4700a5963
commit
6b37320810
@ -2,6 +2,8 @@ import { transformUidToValidOpenApiName } from '@strapi/utils';
|
||||
import type { Internal } from '@strapi/types';
|
||||
import * as z from 'zod/v4';
|
||||
|
||||
// Schema generation happens on-demand when schemas don't exist in the registry
|
||||
|
||||
/**
|
||||
* Safely adds or updates a schema in Zod's global registry.
|
||||
*
|
||||
@ -24,7 +26,7 @@ export const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType
|
||||
|
||||
if (idMap.has(transformedId)) {
|
||||
// Remove existing schema to prevent conflicts
|
||||
strapi.log.debug(`Removing existing schema ${transformedId} from registry`);
|
||||
strapi.log.debug(`Replacing existing schema ${transformedId} in registry`);
|
||||
idMap.delete(transformedId);
|
||||
}
|
||||
|
||||
@ -77,13 +79,27 @@ export const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.Zo
|
||||
// Return existing schema if already registered
|
||||
const mapItem = idMap.get(transformedId);
|
||||
if (mapItem) {
|
||||
strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);
|
||||
// Schema already exists, return it silently
|
||||
return mapItem;
|
||||
}
|
||||
|
||||
strapi.log.warn(
|
||||
`Schema ${transformedId} not found in global registry, creating an any placeholder`
|
||||
);
|
||||
strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
|
||||
|
||||
// Determine if this is a built-in schema or user content
|
||||
const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
|
||||
|
||||
if (isBuiltInSchema) {
|
||||
// Built-in schemas keep at debug level to avoid clutter
|
||||
strapi.log.debug(`Initializing validation schema for ${transformedId}`);
|
||||
} else {
|
||||
// User content
|
||||
const schemaName = transformedId
|
||||
.replace('Document', '')
|
||||
.replace('Entry', '')
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
.trim();
|
||||
strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
|
||||
}
|
||||
|
||||
// Temporary any placeholder before replacing with the actual schema type
|
||||
// Used to prevent infinite loops in cyclical data structures
|
||||
@ -95,7 +111,16 @@ export const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.Zo
|
||||
// Replace the placeholder with the real schema
|
||||
safeGlobalRegistrySet(id, schema);
|
||||
|
||||
strapi.log.debug(`Schema ${transformedId} successfully created and registered`);
|
||||
// Show completion for user content only
|
||||
if (!isBuiltInSchema) {
|
||||
const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;
|
||||
const schemaName = transformedId
|
||||
.replace('Document', '')
|
||||
.replace('Entry', '')
|
||||
.replace(/([A-Z])/g, ' $1')
|
||||
.trim();
|
||||
strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
|
||||
}
|
||||
|
||||
return schema;
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user