next-openapi-gen 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +56 -4
- package/dist/index.js +56 -4
- package/dist/next/index.js +56 -4
- package/dist/react-router/index.js +56 -4
- package/dist/vite/index.js +56 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -12142,6 +12142,9 @@ var ZodSchemaConverter = class {
|
|
|
12142
12142
|
schemaNameToFiles = /* @__PURE__ */ new Map();
|
|
12143
12143
|
/** Per-file import alias for the `zod` module (`import { z as zod }` sets this to `"zod"`). */
|
|
12144
12144
|
zodImportAlias = /* @__PURE__ */ new Map();
|
|
12145
|
+
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
12146
|
+
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
12147
|
+
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
12145
12148
|
// Current processing context (set during file processing)
|
|
12146
12149
|
currentFilePath;
|
|
12147
12150
|
currentAST;
|
|
@@ -12168,7 +12171,14 @@ var ZodSchemaConverter = class {
|
|
|
12168
12171
|
}
|
|
12169
12172
|
logger.debug(`Looking for Zod schema: ${schemaName}`);
|
|
12170
12173
|
const requestedSchemaName = schemaName;
|
|
12171
|
-
|
|
12174
|
+
let mappedSchemaName = this.typeToSchemaMapping[schemaName];
|
|
12175
|
+
if (!mappedSchemaName) {
|
|
12176
|
+
const candidate = this.deriveSchemaNameByConvention(schemaName);
|
|
12177
|
+
if (candidate && this.locateSchemaByConvention(candidate)) {
|
|
12178
|
+
this.typeToSchemaMapping[schemaName] = candidate;
|
|
12179
|
+
mappedSchemaName = candidate;
|
|
12180
|
+
}
|
|
12181
|
+
}
|
|
12172
12182
|
if (mappedSchemaName) {
|
|
12173
12183
|
logger.debug(`Type '${schemaName}' is mapped to schema '${mappedSchemaName}'`);
|
|
12174
12184
|
schemaName = mappedSchemaName;
|
|
@@ -12218,7 +12228,7 @@ var ZodSchemaConverter = class {
|
|
|
12218
12228
|
this.processingSchemas.delete(schemaName);
|
|
12219
12229
|
if (mappedSchemaName && requestedSchemaName !== schemaName) {
|
|
12220
12230
|
const resolvedReference = this.getSchemaReferenceName(schemaName, this.currentContentType);
|
|
12221
|
-
if (this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
12231
|
+
if (!this.metaIdSchemaNames.has(requestedSchemaName) && this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
12222
12232
|
this.zodSchemas[requestedSchemaName] = this.zodSchemas[resolvedReference];
|
|
12223
12233
|
}
|
|
12224
12234
|
this.schemaVariantRefs.set(this.getVariantKey(requestedSchemaName, this.currentContentType), this.zodSchemas[requestedSchemaName] ? requestedSchemaName : resolvedReference);
|
|
@@ -13875,15 +13885,57 @@ var ZodSchemaConverter = class {
|
|
|
13875
13885
|
if (finalName !== schemaName) {
|
|
13876
13886
|
this.indexSchemaName(finalName, filePath);
|
|
13877
13887
|
}
|
|
13878
|
-
if (!this.
|
|
13888
|
+
if (!this.zodSchemas[finalName]) {
|
|
13879
13889
|
if (overrideId && overrideId !== schemaName) {
|
|
13880
13890
|
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
13891
|
+
this.metaIdSchemaNames.add(schemaName);
|
|
13892
|
+
if (this.typeToSchemaMapping[overrideId] === schemaName) {
|
|
13893
|
+
delete this.typeToSchemaMapping[overrideId];
|
|
13894
|
+
}
|
|
13881
13895
|
}
|
|
13882
|
-
this.
|
|
13896
|
+
const variantKey = this.getVariantKey(finalName, this.currentContentType);
|
|
13897
|
+
this.zodSchemas[finalName] = schema;
|
|
13898
|
+
this.schemaVariantRefs.set(variantKey, finalName);
|
|
13883
13899
|
} else {
|
|
13884
13900
|
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
13885
13901
|
}
|
|
13886
13902
|
}
|
|
13903
|
+
/**
|
|
13904
|
+
* Derives the conventional Zod schema name from a TypeScript type name.
|
|
13905
|
+
* e.g. "Slider" → "sliderSchema", "SliderItem" → "sliderItemSchema".
|
|
13906
|
+
* Returns null when the input is already a schema name or is not PascalCase.
|
|
13907
|
+
*/
|
|
13908
|
+
deriveSchemaNameByConvention(typeName) {
|
|
13909
|
+
if (!typeName || !/^[A-Z]/.test(typeName) || typeName.endsWith("Schema")) {
|
|
13910
|
+
return null;
|
|
13911
|
+
}
|
|
13912
|
+
return typeName[0].toLowerCase() + typeName.slice(1) + "Schema";
|
|
13913
|
+
}
|
|
13914
|
+
/**
|
|
13915
|
+
* Checks whether a Zod schema with the given name is present in schemaDirs
|
|
13916
|
+
* WITHOUT populating the processed-schema cache. A file-content substring check
|
|
13917
|
+
* (the same heuristic used by processFileForZodSchema) is sufficient here: we
|
|
13918
|
+
* only want to know whether the candidate *might* live in schemaDirs so that the
|
|
13919
|
+
* convention mapping can be registered; the actual processing happens later in
|
|
13920
|
+
* the normal convertZodSchemaToOpenApi lookup flow.
|
|
13921
|
+
*/
|
|
13922
|
+
locateSchemaByConvention(candidate) {
|
|
13923
|
+
if (this.schemaNameToFiles.has(candidate)) {
|
|
13924
|
+
return true;
|
|
13925
|
+
}
|
|
13926
|
+
for (const dir of this.schemaDirs) {
|
|
13927
|
+
for (const filePath of this.getSchemaFiles(dir)) {
|
|
13928
|
+
try {
|
|
13929
|
+
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
13930
|
+
if (content.includes(candidate)) {
|
|
13931
|
+
return true;
|
|
13932
|
+
}
|
|
13933
|
+
} catch {
|
|
13934
|
+
}
|
|
13935
|
+
}
|
|
13936
|
+
}
|
|
13937
|
+
return false;
|
|
13938
|
+
}
|
|
13887
13939
|
/**
|
|
13888
13940
|
* Check if node is Zod schema
|
|
13889
13941
|
*/
|
package/dist/index.js
CHANGED
|
@@ -11691,6 +11691,9 @@ var ZodSchemaConverter = class {
|
|
|
11691
11691
|
schemaNameToFiles = /* @__PURE__ */ new Map();
|
|
11692
11692
|
/** Per-file import alias for the `zod` module (`import { z as zod }` sets this to `"zod"`). */
|
|
11693
11693
|
zodImportAlias = /* @__PURE__ */ new Map();
|
|
11694
|
+
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
11695
|
+
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
11696
|
+
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
11694
11697
|
// Current processing context (set during file processing)
|
|
11695
11698
|
currentFilePath;
|
|
11696
11699
|
currentAST;
|
|
@@ -11717,7 +11720,14 @@ var ZodSchemaConverter = class {
|
|
|
11717
11720
|
}
|
|
11718
11721
|
logger.debug(`Looking for Zod schema: ${schemaName}`);
|
|
11719
11722
|
const requestedSchemaName = schemaName;
|
|
11720
|
-
|
|
11723
|
+
let mappedSchemaName = this.typeToSchemaMapping[schemaName];
|
|
11724
|
+
if (!mappedSchemaName) {
|
|
11725
|
+
const candidate = this.deriveSchemaNameByConvention(schemaName);
|
|
11726
|
+
if (candidate && this.locateSchemaByConvention(candidate)) {
|
|
11727
|
+
this.typeToSchemaMapping[schemaName] = candidate;
|
|
11728
|
+
mappedSchemaName = candidate;
|
|
11729
|
+
}
|
|
11730
|
+
}
|
|
11721
11731
|
if (mappedSchemaName) {
|
|
11722
11732
|
logger.debug(`Type '${schemaName}' is mapped to schema '${mappedSchemaName}'`);
|
|
11723
11733
|
schemaName = mappedSchemaName;
|
|
@@ -11767,7 +11777,7 @@ var ZodSchemaConverter = class {
|
|
|
11767
11777
|
this.processingSchemas.delete(schemaName);
|
|
11768
11778
|
if (mappedSchemaName && requestedSchemaName !== schemaName) {
|
|
11769
11779
|
const resolvedReference = this.getSchemaReferenceName(schemaName, this.currentContentType);
|
|
11770
|
-
if (this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11780
|
+
if (!this.metaIdSchemaNames.has(requestedSchemaName) && this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11771
11781
|
this.zodSchemas[requestedSchemaName] = this.zodSchemas[resolvedReference];
|
|
11772
11782
|
}
|
|
11773
11783
|
this.schemaVariantRefs.set(this.getVariantKey(requestedSchemaName, this.currentContentType), this.zodSchemas[requestedSchemaName] ? requestedSchemaName : resolvedReference);
|
|
@@ -13424,15 +13434,57 @@ var ZodSchemaConverter = class {
|
|
|
13424
13434
|
if (finalName !== schemaName) {
|
|
13425
13435
|
this.indexSchemaName(finalName, filePath);
|
|
13426
13436
|
}
|
|
13427
|
-
if (!this.
|
|
13437
|
+
if (!this.zodSchemas[finalName]) {
|
|
13428
13438
|
if (overrideId && overrideId !== schemaName) {
|
|
13429
13439
|
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
13440
|
+
this.metaIdSchemaNames.add(schemaName);
|
|
13441
|
+
if (this.typeToSchemaMapping[overrideId] === schemaName) {
|
|
13442
|
+
delete this.typeToSchemaMapping[overrideId];
|
|
13443
|
+
}
|
|
13430
13444
|
}
|
|
13431
|
-
this.
|
|
13445
|
+
const variantKey = this.getVariantKey(finalName, this.currentContentType);
|
|
13446
|
+
this.zodSchemas[finalName] = schema;
|
|
13447
|
+
this.schemaVariantRefs.set(variantKey, finalName);
|
|
13432
13448
|
} else {
|
|
13433
13449
|
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
13434
13450
|
}
|
|
13435
13451
|
}
|
|
13452
|
+
/**
|
|
13453
|
+
* Derives the conventional Zod schema name from a TypeScript type name.
|
|
13454
|
+
* e.g. "Slider" → "sliderSchema", "SliderItem" → "sliderItemSchema".
|
|
13455
|
+
* Returns null when the input is already a schema name or is not PascalCase.
|
|
13456
|
+
*/
|
|
13457
|
+
deriveSchemaNameByConvention(typeName) {
|
|
13458
|
+
if (!typeName || !/^[A-Z]/.test(typeName) || typeName.endsWith("Schema")) {
|
|
13459
|
+
return null;
|
|
13460
|
+
}
|
|
13461
|
+
return typeName[0].toLowerCase() + typeName.slice(1) + "Schema";
|
|
13462
|
+
}
|
|
13463
|
+
/**
|
|
13464
|
+
* Checks whether a Zod schema with the given name is present in schemaDirs
|
|
13465
|
+
* WITHOUT populating the processed-schema cache. A file-content substring check
|
|
13466
|
+
* (the same heuristic used by processFileForZodSchema) is sufficient here: we
|
|
13467
|
+
* only want to know whether the candidate *might* live in schemaDirs so that the
|
|
13468
|
+
* convention mapping can be registered; the actual processing happens later in
|
|
13469
|
+
* the normal convertZodSchemaToOpenApi lookup flow.
|
|
13470
|
+
*/
|
|
13471
|
+
locateSchemaByConvention(candidate) {
|
|
13472
|
+
if (this.schemaNameToFiles.has(candidate)) {
|
|
13473
|
+
return true;
|
|
13474
|
+
}
|
|
13475
|
+
for (const dir of this.schemaDirs) {
|
|
13476
|
+
for (const filePath of this.getSchemaFiles(dir)) {
|
|
13477
|
+
try {
|
|
13478
|
+
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
13479
|
+
if (content.includes(candidate)) {
|
|
13480
|
+
return true;
|
|
13481
|
+
}
|
|
13482
|
+
} catch {
|
|
13483
|
+
}
|
|
13484
|
+
}
|
|
13485
|
+
}
|
|
13486
|
+
return false;
|
|
13487
|
+
}
|
|
13436
13488
|
/**
|
|
13437
13489
|
* Check if node is Zod schema
|
|
13438
13490
|
*/
|
package/dist/next/index.js
CHANGED
|
@@ -12725,6 +12725,9 @@ var ZodSchemaConverter = class {
|
|
|
12725
12725
|
schemaNameToFiles = /* @__PURE__ */ new Map();
|
|
12726
12726
|
/** Per-file import alias for the `zod` module (`import { z as zod }` sets this to `"zod"`). */
|
|
12727
12727
|
zodImportAlias = /* @__PURE__ */ new Map();
|
|
12728
|
+
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
12729
|
+
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
12730
|
+
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
12728
12731
|
// Current processing context (set during file processing)
|
|
12729
12732
|
currentFilePath;
|
|
12730
12733
|
currentAST;
|
|
@@ -12751,7 +12754,14 @@ var ZodSchemaConverter = class {
|
|
|
12751
12754
|
}
|
|
12752
12755
|
logger.debug(`Looking for Zod schema: ${schemaName}`);
|
|
12753
12756
|
const requestedSchemaName = schemaName;
|
|
12754
|
-
|
|
12757
|
+
let mappedSchemaName = this.typeToSchemaMapping[schemaName];
|
|
12758
|
+
if (!mappedSchemaName) {
|
|
12759
|
+
const candidate = this.deriveSchemaNameByConvention(schemaName);
|
|
12760
|
+
if (candidate && this.locateSchemaByConvention(candidate)) {
|
|
12761
|
+
this.typeToSchemaMapping[schemaName] = candidate;
|
|
12762
|
+
mappedSchemaName = candidate;
|
|
12763
|
+
}
|
|
12764
|
+
}
|
|
12755
12765
|
if (mappedSchemaName) {
|
|
12756
12766
|
logger.debug(`Type '${schemaName}' is mapped to schema '${mappedSchemaName}'`);
|
|
12757
12767
|
schemaName = mappedSchemaName;
|
|
@@ -12801,7 +12811,7 @@ var ZodSchemaConverter = class {
|
|
|
12801
12811
|
this.processingSchemas.delete(schemaName);
|
|
12802
12812
|
if (mappedSchemaName && requestedSchemaName !== schemaName) {
|
|
12803
12813
|
const resolvedReference = this.getSchemaReferenceName(schemaName, this.currentContentType);
|
|
12804
|
-
if (this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
12814
|
+
if (!this.metaIdSchemaNames.has(requestedSchemaName) && this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
12805
12815
|
this.zodSchemas[requestedSchemaName] = this.zodSchemas[resolvedReference];
|
|
12806
12816
|
}
|
|
12807
12817
|
this.schemaVariantRefs.set(this.getVariantKey(requestedSchemaName, this.currentContentType), this.zodSchemas[requestedSchemaName] ? requestedSchemaName : resolvedReference);
|
|
@@ -14458,15 +14468,57 @@ var ZodSchemaConverter = class {
|
|
|
14458
14468
|
if (finalName !== schemaName) {
|
|
14459
14469
|
this.indexSchemaName(finalName, filePath);
|
|
14460
14470
|
}
|
|
14461
|
-
if (!this.
|
|
14471
|
+
if (!this.zodSchemas[finalName]) {
|
|
14462
14472
|
if (overrideId && overrideId !== schemaName) {
|
|
14463
14473
|
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
14474
|
+
this.metaIdSchemaNames.add(schemaName);
|
|
14475
|
+
if (this.typeToSchemaMapping[overrideId] === schemaName) {
|
|
14476
|
+
delete this.typeToSchemaMapping[overrideId];
|
|
14477
|
+
}
|
|
14464
14478
|
}
|
|
14465
|
-
this.
|
|
14479
|
+
const variantKey = this.getVariantKey(finalName, this.currentContentType);
|
|
14480
|
+
this.zodSchemas[finalName] = schema;
|
|
14481
|
+
this.schemaVariantRefs.set(variantKey, finalName);
|
|
14466
14482
|
} else {
|
|
14467
14483
|
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
14468
14484
|
}
|
|
14469
14485
|
}
|
|
14486
|
+
/**
|
|
14487
|
+
* Derives the conventional Zod schema name from a TypeScript type name.
|
|
14488
|
+
* e.g. "Slider" → "sliderSchema", "SliderItem" → "sliderItemSchema".
|
|
14489
|
+
* Returns null when the input is already a schema name or is not PascalCase.
|
|
14490
|
+
*/
|
|
14491
|
+
deriveSchemaNameByConvention(typeName) {
|
|
14492
|
+
if (!typeName || !/^[A-Z]/.test(typeName) || typeName.endsWith("Schema")) {
|
|
14493
|
+
return null;
|
|
14494
|
+
}
|
|
14495
|
+
return typeName[0].toLowerCase() + typeName.slice(1) + "Schema";
|
|
14496
|
+
}
|
|
14497
|
+
/**
|
|
14498
|
+
* Checks whether a Zod schema with the given name is present in schemaDirs
|
|
14499
|
+
* WITHOUT populating the processed-schema cache. A file-content substring check
|
|
14500
|
+
* (the same heuristic used by processFileForZodSchema) is sufficient here: we
|
|
14501
|
+
* only want to know whether the candidate *might* live in schemaDirs so that the
|
|
14502
|
+
* convention mapping can be registered; the actual processing happens later in
|
|
14503
|
+
* the normal convertZodSchemaToOpenApi lookup flow.
|
|
14504
|
+
*/
|
|
14505
|
+
locateSchemaByConvention(candidate) {
|
|
14506
|
+
if (this.schemaNameToFiles.has(candidate)) {
|
|
14507
|
+
return true;
|
|
14508
|
+
}
|
|
14509
|
+
for (const dir of this.schemaDirs) {
|
|
14510
|
+
for (const filePath of this.getSchemaFiles(dir)) {
|
|
14511
|
+
try {
|
|
14512
|
+
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
14513
|
+
if (content.includes(candidate)) {
|
|
14514
|
+
return true;
|
|
14515
|
+
}
|
|
14516
|
+
} catch {
|
|
14517
|
+
}
|
|
14518
|
+
}
|
|
14519
|
+
}
|
|
14520
|
+
return false;
|
|
14521
|
+
}
|
|
14470
14522
|
/**
|
|
14471
14523
|
* Check if node is Zod schema
|
|
14472
14524
|
*/
|
|
@@ -11729,6 +11729,9 @@ var ZodSchemaConverter = class {
|
|
|
11729
11729
|
schemaNameToFiles = /* @__PURE__ */ new Map();
|
|
11730
11730
|
/** Per-file import alias for the `zod` module (`import { z as zod }` sets this to `"zod"`). */
|
|
11731
11731
|
zodImportAlias = /* @__PURE__ */ new Map();
|
|
11732
|
+
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
11733
|
+
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
11734
|
+
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
11732
11735
|
// Current processing context (set during file processing)
|
|
11733
11736
|
currentFilePath;
|
|
11734
11737
|
currentAST;
|
|
@@ -11755,7 +11758,14 @@ var ZodSchemaConverter = class {
|
|
|
11755
11758
|
}
|
|
11756
11759
|
logger.debug(`Looking for Zod schema: ${schemaName}`);
|
|
11757
11760
|
const requestedSchemaName = schemaName;
|
|
11758
|
-
|
|
11761
|
+
let mappedSchemaName = this.typeToSchemaMapping[schemaName];
|
|
11762
|
+
if (!mappedSchemaName) {
|
|
11763
|
+
const candidate = this.deriveSchemaNameByConvention(schemaName);
|
|
11764
|
+
if (candidate && this.locateSchemaByConvention(candidate)) {
|
|
11765
|
+
this.typeToSchemaMapping[schemaName] = candidate;
|
|
11766
|
+
mappedSchemaName = candidate;
|
|
11767
|
+
}
|
|
11768
|
+
}
|
|
11759
11769
|
if (mappedSchemaName) {
|
|
11760
11770
|
logger.debug(`Type '${schemaName}' is mapped to schema '${mappedSchemaName}'`);
|
|
11761
11771
|
schemaName = mappedSchemaName;
|
|
@@ -11805,7 +11815,7 @@ var ZodSchemaConverter = class {
|
|
|
11805
11815
|
this.processingSchemas.delete(schemaName);
|
|
11806
11816
|
if (mappedSchemaName && requestedSchemaName !== schemaName) {
|
|
11807
11817
|
const resolvedReference = this.getSchemaReferenceName(schemaName, this.currentContentType);
|
|
11808
|
-
if (this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11818
|
+
if (!this.metaIdSchemaNames.has(requestedSchemaName) && this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11809
11819
|
this.zodSchemas[requestedSchemaName] = this.zodSchemas[resolvedReference];
|
|
11810
11820
|
}
|
|
11811
11821
|
this.schemaVariantRefs.set(this.getVariantKey(requestedSchemaName, this.currentContentType), this.zodSchemas[requestedSchemaName] ? requestedSchemaName : resolvedReference);
|
|
@@ -13462,15 +13472,57 @@ var ZodSchemaConverter = class {
|
|
|
13462
13472
|
if (finalName !== schemaName) {
|
|
13463
13473
|
this.indexSchemaName(finalName, filePath);
|
|
13464
13474
|
}
|
|
13465
|
-
if (!this.
|
|
13475
|
+
if (!this.zodSchemas[finalName]) {
|
|
13466
13476
|
if (overrideId && overrideId !== schemaName) {
|
|
13467
13477
|
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
13478
|
+
this.metaIdSchemaNames.add(schemaName);
|
|
13479
|
+
if (this.typeToSchemaMapping[overrideId] === schemaName) {
|
|
13480
|
+
delete this.typeToSchemaMapping[overrideId];
|
|
13481
|
+
}
|
|
13468
13482
|
}
|
|
13469
|
-
this.
|
|
13483
|
+
const variantKey = this.getVariantKey(finalName, this.currentContentType);
|
|
13484
|
+
this.zodSchemas[finalName] = schema;
|
|
13485
|
+
this.schemaVariantRefs.set(variantKey, finalName);
|
|
13470
13486
|
} else {
|
|
13471
13487
|
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
13472
13488
|
}
|
|
13473
13489
|
}
|
|
13490
|
+
/**
|
|
13491
|
+
* Derives the conventional Zod schema name from a TypeScript type name.
|
|
13492
|
+
* e.g. "Slider" → "sliderSchema", "SliderItem" → "sliderItemSchema".
|
|
13493
|
+
* Returns null when the input is already a schema name or is not PascalCase.
|
|
13494
|
+
*/
|
|
13495
|
+
deriveSchemaNameByConvention(typeName) {
|
|
13496
|
+
if (!typeName || !/^[A-Z]/.test(typeName) || typeName.endsWith("Schema")) {
|
|
13497
|
+
return null;
|
|
13498
|
+
}
|
|
13499
|
+
return typeName[0].toLowerCase() + typeName.slice(1) + "Schema";
|
|
13500
|
+
}
|
|
13501
|
+
/**
|
|
13502
|
+
* Checks whether a Zod schema with the given name is present in schemaDirs
|
|
13503
|
+
* WITHOUT populating the processed-schema cache. A file-content substring check
|
|
13504
|
+
* (the same heuristic used by processFileForZodSchema) is sufficient here: we
|
|
13505
|
+
* only want to know whether the candidate *might* live in schemaDirs so that the
|
|
13506
|
+
* convention mapping can be registered; the actual processing happens later in
|
|
13507
|
+
* the normal convertZodSchemaToOpenApi lookup flow.
|
|
13508
|
+
*/
|
|
13509
|
+
locateSchemaByConvention(candidate) {
|
|
13510
|
+
if (this.schemaNameToFiles.has(candidate)) {
|
|
13511
|
+
return true;
|
|
13512
|
+
}
|
|
13513
|
+
for (const dir of this.schemaDirs) {
|
|
13514
|
+
for (const filePath of this.getSchemaFiles(dir)) {
|
|
13515
|
+
try {
|
|
13516
|
+
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
13517
|
+
if (content.includes(candidate)) {
|
|
13518
|
+
return true;
|
|
13519
|
+
}
|
|
13520
|
+
} catch {
|
|
13521
|
+
}
|
|
13522
|
+
}
|
|
13523
|
+
}
|
|
13524
|
+
return false;
|
|
13525
|
+
}
|
|
13474
13526
|
/**
|
|
13475
13527
|
* Check if node is Zod schema
|
|
13476
13528
|
*/
|
package/dist/vite/index.js
CHANGED
|
@@ -11729,6 +11729,9 @@ var ZodSchemaConverter = class {
|
|
|
11729
11729
|
schemaNameToFiles = /* @__PURE__ */ new Map();
|
|
11730
11730
|
/** Per-file import alias for the `zod` module (`import { z as zod }` sets this to `"zod"`). */
|
|
11731
11731
|
zodImportAlias = /* @__PURE__ */ new Map();
|
|
11732
|
+
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
11733
|
+
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
11734
|
+
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
11732
11735
|
// Current processing context (set during file processing)
|
|
11733
11736
|
currentFilePath;
|
|
11734
11737
|
currentAST;
|
|
@@ -11755,7 +11758,14 @@ var ZodSchemaConverter = class {
|
|
|
11755
11758
|
}
|
|
11756
11759
|
logger.debug(`Looking for Zod schema: ${schemaName}`);
|
|
11757
11760
|
const requestedSchemaName = schemaName;
|
|
11758
|
-
|
|
11761
|
+
let mappedSchemaName = this.typeToSchemaMapping[schemaName];
|
|
11762
|
+
if (!mappedSchemaName) {
|
|
11763
|
+
const candidate = this.deriveSchemaNameByConvention(schemaName);
|
|
11764
|
+
if (candidate && this.locateSchemaByConvention(candidate)) {
|
|
11765
|
+
this.typeToSchemaMapping[schemaName] = candidate;
|
|
11766
|
+
mappedSchemaName = candidate;
|
|
11767
|
+
}
|
|
11768
|
+
}
|
|
11759
11769
|
if (mappedSchemaName) {
|
|
11760
11770
|
logger.debug(`Type '${schemaName}' is mapped to schema '${mappedSchemaName}'`);
|
|
11761
11771
|
schemaName = mappedSchemaName;
|
|
@@ -11805,7 +11815,7 @@ var ZodSchemaConverter = class {
|
|
|
11805
11815
|
this.processingSchemas.delete(schemaName);
|
|
11806
11816
|
if (mappedSchemaName && requestedSchemaName !== schemaName) {
|
|
11807
11817
|
const resolvedReference = this.getSchemaReferenceName(schemaName, this.currentContentType);
|
|
11808
|
-
if (this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11818
|
+
if (!this.metaIdSchemaNames.has(requestedSchemaName) && this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11809
11819
|
this.zodSchemas[requestedSchemaName] = this.zodSchemas[resolvedReference];
|
|
11810
11820
|
}
|
|
11811
11821
|
this.schemaVariantRefs.set(this.getVariantKey(requestedSchemaName, this.currentContentType), this.zodSchemas[requestedSchemaName] ? requestedSchemaName : resolvedReference);
|
|
@@ -13462,15 +13472,57 @@ var ZodSchemaConverter = class {
|
|
|
13462
13472
|
if (finalName !== schemaName) {
|
|
13463
13473
|
this.indexSchemaName(finalName, filePath);
|
|
13464
13474
|
}
|
|
13465
|
-
if (!this.
|
|
13475
|
+
if (!this.zodSchemas[finalName]) {
|
|
13466
13476
|
if (overrideId && overrideId !== schemaName) {
|
|
13467
13477
|
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
13478
|
+
this.metaIdSchemaNames.add(schemaName);
|
|
13479
|
+
if (this.typeToSchemaMapping[overrideId] === schemaName) {
|
|
13480
|
+
delete this.typeToSchemaMapping[overrideId];
|
|
13481
|
+
}
|
|
13468
13482
|
}
|
|
13469
|
-
this.
|
|
13483
|
+
const variantKey = this.getVariantKey(finalName, this.currentContentType);
|
|
13484
|
+
this.zodSchemas[finalName] = schema;
|
|
13485
|
+
this.schemaVariantRefs.set(variantKey, finalName);
|
|
13470
13486
|
} else {
|
|
13471
13487
|
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
13472
13488
|
}
|
|
13473
13489
|
}
|
|
13490
|
+
/**
|
|
13491
|
+
* Derives the conventional Zod schema name from a TypeScript type name.
|
|
13492
|
+
* e.g. "Slider" → "sliderSchema", "SliderItem" → "sliderItemSchema".
|
|
13493
|
+
* Returns null when the input is already a schema name or is not PascalCase.
|
|
13494
|
+
*/
|
|
13495
|
+
deriveSchemaNameByConvention(typeName) {
|
|
13496
|
+
if (!typeName || !/^[A-Z]/.test(typeName) || typeName.endsWith("Schema")) {
|
|
13497
|
+
return null;
|
|
13498
|
+
}
|
|
13499
|
+
return typeName[0].toLowerCase() + typeName.slice(1) + "Schema";
|
|
13500
|
+
}
|
|
13501
|
+
/**
|
|
13502
|
+
* Checks whether a Zod schema with the given name is present in schemaDirs
|
|
13503
|
+
* WITHOUT populating the processed-schema cache. A file-content substring check
|
|
13504
|
+
* (the same heuristic used by processFileForZodSchema) is sufficient here: we
|
|
13505
|
+
* only want to know whether the candidate *might* live in schemaDirs so that the
|
|
13506
|
+
* convention mapping can be registered; the actual processing happens later in
|
|
13507
|
+
* the normal convertZodSchemaToOpenApi lookup flow.
|
|
13508
|
+
*/
|
|
13509
|
+
locateSchemaByConvention(candidate) {
|
|
13510
|
+
if (this.schemaNameToFiles.has(candidate)) {
|
|
13511
|
+
return true;
|
|
13512
|
+
}
|
|
13513
|
+
for (const dir of this.schemaDirs) {
|
|
13514
|
+
for (const filePath of this.getSchemaFiles(dir)) {
|
|
13515
|
+
try {
|
|
13516
|
+
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
13517
|
+
if (content.includes(candidate)) {
|
|
13518
|
+
return true;
|
|
13519
|
+
}
|
|
13520
|
+
} catch {
|
|
13521
|
+
}
|
|
13522
|
+
}
|
|
13523
|
+
}
|
|
13524
|
+
return false;
|
|
13525
|
+
}
|
|
13474
13526
|
/**
|
|
13475
13527
|
* Check if node is Zod schema
|
|
13476
13528
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-openapi-gen",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Automatically generate OpenAPI 3.0, 3.1, and 3.2 documentation from Next.js projects, with support for Zod schemas, TypeScript types, and reusable OpenAPI fragments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|