@cerios/openapi-to-zod 1.0.0 → 1.1.0
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/README.md +178 -0
- package/dist/cli.js +122 -23
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +129 -23
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +117 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -14
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +59 -2
- package/dist/internal.d.ts +59 -2
- package/dist/internal.js +130 -2
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +127 -2
- package/dist/internal.mjs.map +1 -1
- package/dist/{types-BjoP91vk.d.mts → types-B7ePTDjr.d.mts} +31 -0
- package/dist/{types-BjoP91vk.d.ts → types-B7ePTDjr.d.ts} +31 -0
- package/package.json +102 -89
package/README.md
CHANGED
|
@@ -187,6 +187,7 @@ Examples:
|
|
|
187
187
|
| `schemaType` | `"all"` \| `"request"` \| `"response"` | Schema filtering |
|
|
188
188
|
| `prefix` | `string` | Prefix for schema names |
|
|
189
189
|
| `suffix` | `string` | Suffix for schema names |
|
|
190
|
+
| `stripSchemaPrefix` | `string \| RegExp` | Strip prefix from schema names before generating (e.g., `"Company.Models."` or `/^[A-Z]+\./`) |
|
|
190
191
|
| `showStats` | `boolean` | Include generation statistics |
|
|
191
192
|
| `request` | `object` | Request-specific options (mode, includeDescriptions, useDescribe) |
|
|
192
193
|
| `response` | `object` | Response-specific options (mode, includeDescriptions, useDescribe) |
|
|
@@ -598,6 +599,183 @@ This is useful when:
|
|
|
598
599
|
- Following specific naming conventions (DTO, Model, Entity)
|
|
599
600
|
- Avoiding naming conflicts with existing code
|
|
600
601
|
|
|
602
|
+
### Schema Prefix Stripping
|
|
603
|
+
|
|
604
|
+
The `stripSchemaPrefix` option removes common prefixes from schema names in your OpenAPI spec before generating Zod schemas. This is particularly useful when your OpenAPI spec uses namespaced schema names (like .NET-generated specs with "Company.Models.User").
|
|
605
|
+
|
|
606
|
+
**OpenAPI Spec with Namespaced Schemas:**
|
|
607
|
+
```yaml
|
|
608
|
+
components:
|
|
609
|
+
schemas:
|
|
610
|
+
Company.Models.User:
|
|
611
|
+
type: object
|
|
612
|
+
properties:
|
|
613
|
+
id:
|
|
614
|
+
type: string
|
|
615
|
+
name:
|
|
616
|
+
type: string
|
|
617
|
+
role:
|
|
618
|
+
$ref: '#/components/schemas/Company.Models.UserRole'
|
|
619
|
+
Company.Models.UserRole:
|
|
620
|
+
type: string
|
|
621
|
+
enum: [admin, user, guest]
|
|
622
|
+
Company.Models.Post:
|
|
623
|
+
type: object
|
|
624
|
+
properties:
|
|
625
|
+
id:
|
|
626
|
+
type: string
|
|
627
|
+
title:
|
|
628
|
+
type: string
|
|
629
|
+
author:
|
|
630
|
+
$ref: '#/components/schemas/Company.Models.User'
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
**Without `stripSchemaPrefix`:**
|
|
634
|
+
```typescript
|
|
635
|
+
export const companyModelsUserRoleSchema = z.enum(["admin", "user", "guest"]);
|
|
636
|
+
|
|
637
|
+
export const companyModelsUserSchema = z.object({
|
|
638
|
+
id: z.string(),
|
|
639
|
+
name: z.string(),
|
|
640
|
+
role: companyModelsUserRoleSchema // Long reference name
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
export const companyModelsPostSchema = z.object({
|
|
644
|
+
id: z.string(),
|
|
645
|
+
title: z.string(),
|
|
646
|
+
author: companyModelsUserSchema // Long reference name
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
export type CompanyModelsUserRole = z.infer<typeof companyModelsUserRoleSchema>;
|
|
650
|
+
export type CompanyModelsUser = z.infer<typeof companyModelsUserSchema>;
|
|
651
|
+
export type CompanyModelsPost = z.infer<typeof companyModelsPostSchema>;
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
**With `stripSchemaPrefix: "Company.Models."`:**
|
|
655
|
+
```typescript
|
|
656
|
+
export const userRoleSchema = z.enum(["admin", "user", "guest"]);
|
|
657
|
+
|
|
658
|
+
export const userSchema = z.object({
|
|
659
|
+
id: z.string(),
|
|
660
|
+
name: z.string(),
|
|
661
|
+
role: userRoleSchema // Clean reference
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
export const postSchema = z.object({
|
|
665
|
+
id: z.string(),
|
|
666
|
+
title: z.string(),
|
|
667
|
+
author: userSchema // Clean reference
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
export type UserRole = z.infer<typeof userRoleSchema>;
|
|
671
|
+
export type User = z.infer<typeof userSchema>;
|
|
672
|
+
export type Post = z.infer<typeof postSchema>;
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
#### Usage
|
|
676
|
+
|
|
677
|
+
```typescript
|
|
678
|
+
export default defineConfig({
|
|
679
|
+
specs: [{
|
|
680
|
+
input: 'openapi.yaml',
|
|
681
|
+
output: 'schemas.ts',
|
|
682
|
+
stripSchemaPrefix: 'Company.Models.' // Strip this exact prefix
|
|
683
|
+
}]
|
|
684
|
+
});
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
#### Regex Patterns
|
|
688
|
+
|
|
689
|
+
Use regex patterns to strip dynamic prefixes:
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
export default defineConfig({
|
|
693
|
+
specs: [{
|
|
694
|
+
input: 'openapi.yaml',
|
|
695
|
+
output: 'schemas.ts',
|
|
696
|
+
// Strip any namespace prefix ending with a dot
|
|
697
|
+
stripSchemaPrefix: '^[A-Z][a-z]+\\.'
|
|
698
|
+
}]
|
|
699
|
+
});
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
**Regex Auto-Detection:**
|
|
703
|
+
|
|
704
|
+
Regex patterns are auto-detected if they contain: `^`, `$`, `\\d`, `\\w`, `\\s`, `.*`, `.+`, `[]`, `()`
|
|
705
|
+
|
|
706
|
+
```typescript
|
|
707
|
+
// These are all treated as regex patterns:
|
|
708
|
+
stripSchemaPrefix: '^Company\\.' // Starts with ^
|
|
709
|
+
stripSchemaPrefix: '[A-Z]+\\.' // Contains []
|
|
710
|
+
stripSchemaPrefix: '.*\\.Models\\.' // Contains .*
|
|
711
|
+
|
|
712
|
+
// This is a literal string:
|
|
713
|
+
stripSchemaPrefix: 'Company.Models.' // No regex markers
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
For TypeScript configs, you can also use `RegExp` objects:
|
|
717
|
+
|
|
718
|
+
```typescript
|
|
719
|
+
stripSchemaPrefix: /^[A-Z][a-z]+\./
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
#### Common Patterns
|
|
723
|
+
|
|
724
|
+
**Pattern 1: .NET Namespaces**
|
|
725
|
+
```typescript
|
|
726
|
+
{
|
|
727
|
+
stripSchemaPrefix: 'Company.Models.'
|
|
728
|
+
}
|
|
729
|
+
// Company.Models.User → User
|
|
730
|
+
// Company.Models.Post → Post
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**Pattern 2: Multiple Namespaces**
|
|
734
|
+
```typescript
|
|
735
|
+
{
|
|
736
|
+
stripSchemaPrefix: '^[A-Za-z]+\\.Models\\.'
|
|
737
|
+
}
|
|
738
|
+
// MyApp.Models.User → User
|
|
739
|
+
// OtherApp.Models.User → User
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
**Pattern 3: Version Prefixes**
|
|
743
|
+
```typescript
|
|
744
|
+
{
|
|
745
|
+
stripSchemaPrefix: '^v\\d+\\.'
|
|
746
|
+
}
|
|
747
|
+
// v1.User → User
|
|
748
|
+
// v2.Product → Product
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
#### Interaction with prefix/suffix Options
|
|
752
|
+
|
|
753
|
+
`stripSchemaPrefix` is applied **before** `prefix` and `suffix` options:
|
|
754
|
+
|
|
755
|
+
```typescript
|
|
756
|
+
export default defineConfig({
|
|
757
|
+
specs: [{
|
|
758
|
+
input: 'openapi.yaml',
|
|
759
|
+
output: 'schemas.ts',
|
|
760
|
+
stripSchemaPrefix: 'Company.Models.', // Applied first
|
|
761
|
+
prefix: 'api', // Applied second
|
|
762
|
+
suffix: 'dto' // Applied third
|
|
763
|
+
}]
|
|
764
|
+
});
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
**Result:**
|
|
768
|
+
- `Company.Models.User` → `User` → `apiUserDtoSchema`
|
|
769
|
+
- `Company.Models.Post` → `Post` → `apiPostDtoSchema`
|
|
770
|
+
|
|
771
|
+
#### Benefits
|
|
772
|
+
|
|
773
|
+
1. **Cleaner Schema Names**: Generates `userSchema` instead of `companyModelsUserSchema`
|
|
774
|
+
2. **Better Type Names**: Creates `User` type instead of `CompanyModelsUser`
|
|
775
|
+
3. **Shorter References**: Simpler schema references in composed types
|
|
776
|
+
4. **Better Code Completion**: Easier to find schemas in IDE autocomplete
|
|
777
|
+
5. **Flexible Pattern Matching**: Use regex for dynamic prefixes
|
|
778
|
+
|
|
601
779
|
## Generation Statistics
|
|
602
780
|
|
|
603
781
|
Statistics are **included by default** in generated files. Use `showStats: false` to disable:
|
package/dist/cli.js
CHANGED
|
@@ -5137,8 +5137,20 @@ init_cjs_shims();
|
|
|
5137
5137
|
|
|
5138
5138
|
// src/utils/name-utils.ts
|
|
5139
5139
|
init_cjs_shims();
|
|
5140
|
+
function sanitizeIdentifier(str) {
|
|
5141
|
+
return str.replace(/[^a-zA-Z0-9._\-\s]+/g, "_");
|
|
5142
|
+
}
|
|
5140
5143
|
function toCamelCase(str, options) {
|
|
5141
|
-
|
|
5144
|
+
const sanitized = sanitizeIdentifier(str);
|
|
5145
|
+
const words = sanitized.split(/[.\-_\s]+/).filter((word) => word.length > 0);
|
|
5146
|
+
let name;
|
|
5147
|
+
if (words.length === 0) {
|
|
5148
|
+
name = str.charAt(0).toLowerCase() + str.slice(1);
|
|
5149
|
+
} else if (words.length === 1) {
|
|
5150
|
+
name = words[0].charAt(0).toLowerCase() + words[0].slice(1);
|
|
5151
|
+
} else {
|
|
5152
|
+
name = words[0].charAt(0).toLowerCase() + words[0].slice(1) + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
5153
|
+
}
|
|
5142
5154
|
if (options == null ? void 0 : options.prefix) {
|
|
5143
5155
|
const prefix = options.prefix.toLowerCase();
|
|
5144
5156
|
name = prefix + name.charAt(0).toUpperCase() + name.slice(1);
|
|
@@ -5151,12 +5163,23 @@ function toCamelCase(str, options) {
|
|
|
5151
5163
|
}
|
|
5152
5164
|
function toPascalCase(str) {
|
|
5153
5165
|
const stringValue = String(str);
|
|
5154
|
-
|
|
5166
|
+
const isAlreadyValidCase = /^[a-zA-Z][a-zA-Z0-9]*$/.test(stringValue);
|
|
5167
|
+
if (isAlreadyValidCase) {
|
|
5168
|
+
return stringValue.charAt(0).toUpperCase() + stringValue.slice(1);
|
|
5169
|
+
}
|
|
5170
|
+
const sanitized = sanitizeIdentifier(stringValue);
|
|
5171
|
+
const words = sanitized.split(/[.\-_\s]+/).filter((word) => word.length > 0);
|
|
5172
|
+
let result;
|
|
5173
|
+
if (words.length === 0) {
|
|
5174
|
+
result = "Value";
|
|
5175
|
+
} else {
|
|
5176
|
+
result = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
5177
|
+
}
|
|
5155
5178
|
if (/^\d/.test(result)) {
|
|
5156
5179
|
result = `N${result}`;
|
|
5157
5180
|
}
|
|
5158
5181
|
if (!result || /^_+$/.test(result)) {
|
|
5159
|
-
|
|
5182
|
+
return "Value";
|
|
5160
5183
|
}
|
|
5161
5184
|
return result;
|
|
5162
5185
|
}
|
|
@@ -5168,9 +5191,10 @@ function resolveRef(ref) {
|
|
|
5168
5191
|
// src/generators/enum-generator.ts
|
|
5169
5192
|
function generateEnum(name, values, options) {
|
|
5170
5193
|
const schemaName = `${toCamelCase(name, options)}Schema`;
|
|
5194
|
+
const typeName = toPascalCase(name);
|
|
5171
5195
|
const enumValues = values.map((v) => `"${v}"`).join(", ");
|
|
5172
5196
|
const schemaCode = `export const ${schemaName} = z.enum([${enumValues}]);`;
|
|
5173
|
-
const typeCode = `export type ${
|
|
5197
|
+
const typeCode = `export type ${typeName} = z.infer<typeof ${schemaName}>;`;
|
|
5174
5198
|
return { schemaCode, typeCode };
|
|
5175
5199
|
}
|
|
5176
5200
|
|
|
@@ -5311,6 +5335,77 @@ var LRUCache = class {
|
|
|
5311
5335
|
}
|
|
5312
5336
|
};
|
|
5313
5337
|
|
|
5338
|
+
// src/utils/pattern-utils.ts
|
|
5339
|
+
init_cjs_shims();
|
|
5340
|
+
function isRegexPattern(pattern) {
|
|
5341
|
+
if (pattern.startsWith("^") || pattern.endsWith("$")) {
|
|
5342
|
+
return true;
|
|
5343
|
+
}
|
|
5344
|
+
if (/\\[dDwWsS]/.test(pattern)) {
|
|
5345
|
+
return true;
|
|
5346
|
+
}
|
|
5347
|
+
if (/\.\*|\.\+/.test(pattern)) {
|
|
5348
|
+
return true;
|
|
5349
|
+
}
|
|
5350
|
+
if (/[[\]()]/.test(pattern)) {
|
|
5351
|
+
return true;
|
|
5352
|
+
}
|
|
5353
|
+
if (/[^/][+?*]\{/.test(pattern)) {
|
|
5354
|
+
return true;
|
|
5355
|
+
}
|
|
5356
|
+
return false;
|
|
5357
|
+
}
|
|
5358
|
+
function patternToRegex(pattern) {
|
|
5359
|
+
if (pattern instanceof RegExp) {
|
|
5360
|
+
return pattern;
|
|
5361
|
+
}
|
|
5362
|
+
if (isRegexPattern(pattern)) {
|
|
5363
|
+
try {
|
|
5364
|
+
return new RegExp(pattern);
|
|
5365
|
+
} catch (error) {
|
|
5366
|
+
console.warn(`\u26A0\uFE0F Invalid regex pattern "${pattern}": ${error instanceof Error ? error.message : String(error)}`);
|
|
5367
|
+
return null;
|
|
5368
|
+
}
|
|
5369
|
+
}
|
|
5370
|
+
return null;
|
|
5371
|
+
}
|
|
5372
|
+
function stripPrefix(input, pattern, ensureLeadingChar) {
|
|
5373
|
+
if (!pattern) {
|
|
5374
|
+
return input;
|
|
5375
|
+
}
|
|
5376
|
+
const regex = patternToRegex(pattern);
|
|
5377
|
+
if (regex) {
|
|
5378
|
+
const match = input.match(regex);
|
|
5379
|
+
if (match && match.index === 0) {
|
|
5380
|
+
const stripped = input.substring(match[0].length);
|
|
5381
|
+
if (ensureLeadingChar) {
|
|
5382
|
+
if (stripped === "") {
|
|
5383
|
+
return ensureLeadingChar;
|
|
5384
|
+
}
|
|
5385
|
+
if (!stripped.startsWith(ensureLeadingChar)) {
|
|
5386
|
+
return `${ensureLeadingChar}${stripped}`;
|
|
5387
|
+
}
|
|
5388
|
+
}
|
|
5389
|
+
return stripped;
|
|
5390
|
+
}
|
|
5391
|
+
} else {
|
|
5392
|
+
const stringPattern = pattern;
|
|
5393
|
+
if (input.startsWith(stringPattern)) {
|
|
5394
|
+
const stripped = input.substring(stringPattern.length);
|
|
5395
|
+
if (ensureLeadingChar) {
|
|
5396
|
+
if (stripped === "") {
|
|
5397
|
+
return ensureLeadingChar;
|
|
5398
|
+
}
|
|
5399
|
+
if (!stripped.startsWith(ensureLeadingChar)) {
|
|
5400
|
+
return `${ensureLeadingChar}${stripped}`;
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5403
|
+
return stripped;
|
|
5404
|
+
}
|
|
5405
|
+
}
|
|
5406
|
+
return input;
|
|
5407
|
+
}
|
|
5408
|
+
|
|
5314
5409
|
// src/validators/array-validator.ts
|
|
5315
5410
|
init_cjs_shims();
|
|
5316
5411
|
function generateArrayValidation(schema, context) {
|
|
@@ -6175,8 +6270,9 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
6175
6270
|
}
|
|
6176
6271
|
(_a = this.context.schemaDependencies.get(currentSchema)) == null ? void 0 : _a.add(refName);
|
|
6177
6272
|
}
|
|
6178
|
-
const
|
|
6179
|
-
|
|
6273
|
+
const strippedRefName = stripPrefix(resolvedRefName, this.context.stripSchemaPrefix);
|
|
6274
|
+
const schemaName = `${toCamelCase(strippedRefName, this.context.namingOptions)}Schema`;
|
|
6275
|
+
if (currentSchema && (refName === currentSchema || this.isCircularThroughAlias(currentSchema, refName))) {
|
|
6180
6276
|
const lazySchema = `z.lazy((): z.ZodTypeAny => ${schemaName})`;
|
|
6181
6277
|
return wrapNullable(lazySchema, nullable);
|
|
6182
6278
|
}
|
|
@@ -6477,6 +6573,7 @@ var OpenApiGenerator = class {
|
|
|
6477
6573
|
schemaType: options.schemaType || "all",
|
|
6478
6574
|
prefix: options.prefix,
|
|
6479
6575
|
suffix: options.suffix,
|
|
6576
|
+
stripSchemaPrefix: options.stripSchemaPrefix,
|
|
6480
6577
|
showStats: (_c = options.showStats) != null ? _c : true,
|
|
6481
6578
|
request: options.request,
|
|
6482
6579
|
response: options.response,
|
|
@@ -6553,7 +6650,8 @@ var OpenApiGenerator = class {
|
|
|
6553
6650
|
namingOptions: {
|
|
6554
6651
|
prefix: this.options.prefix,
|
|
6555
6652
|
suffix: this.options.suffix
|
|
6556
|
-
}
|
|
6653
|
+
},
|
|
6654
|
+
stripSchemaPrefix: this.options.stripSchemaPrefix
|
|
6557
6655
|
});
|
|
6558
6656
|
}
|
|
6559
6657
|
/**
|
|
@@ -6587,9 +6685,11 @@ var OpenApiGenerator = class {
|
|
|
6587
6685
|
const typeCode = this.types.get(name);
|
|
6588
6686
|
if (schemaCode) {
|
|
6589
6687
|
output.push(schemaCode);
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6688
|
+
const strippedName = stripPrefix(name, this.options.stripSchemaPrefix);
|
|
6689
|
+
const typeName = toPascalCase(strippedName);
|
|
6690
|
+
if (!schemaCode.includes(`export type ${typeName}`)) {
|
|
6691
|
+
const schemaName = `${toCamelCase(strippedName, { prefix: this.options.prefix, suffix: this.options.suffix })}Schema`;
|
|
6692
|
+
output.push(`export type ${typeName} = z.infer<typeof ${schemaName}>;`);
|
|
6593
6693
|
}
|
|
6594
6694
|
output.push("");
|
|
6595
6695
|
} else if (typeCode) {
|
|
@@ -6905,7 +7005,8 @@ var OpenApiGenerator = class {
|
|
|
6905
7005
|
const resolvedOptions = context === "response" ? this.responseOptions : this.requestOptions;
|
|
6906
7006
|
if (schema.enum) {
|
|
6907
7007
|
const jsdoc2 = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
|
|
6908
|
-
const
|
|
7008
|
+
const strippedName2 = stripPrefix(name, this.options.stripSchemaPrefix);
|
|
7009
|
+
const { schemaCode, typeCode } = generateEnum(strippedName2, schema.enum, {
|
|
6909
7010
|
prefix: this.options.prefix,
|
|
6910
7011
|
suffix: this.options.suffix
|
|
6911
7012
|
});
|
|
@@ -6914,7 +7015,8 @@ ${typeCode}`;
|
|
|
6914
7015
|
this.schemas.set(name, enumSchemaCode);
|
|
6915
7016
|
return;
|
|
6916
7017
|
}
|
|
6917
|
-
const
|
|
7018
|
+
const strippedName = stripPrefix(name, this.options.stripSchemaPrefix);
|
|
7019
|
+
const schemaName = `${toCamelCase(strippedName, { prefix: this.options.prefix, suffix: this.options.suffix })}Schema`;
|
|
6918
7020
|
const jsdoc = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
|
|
6919
7021
|
if (schema.allOf && schema.allOf.length === 1 && schema.allOf[0].$ref) {
|
|
6920
7022
|
const refName = resolveRef(schema.allOf[0].$ref);
|
|
@@ -6930,7 +7032,8 @@ ${typeCode}`;
|
|
|
6930
7032
|
namingOptions: {
|
|
6931
7033
|
prefix: this.options.prefix,
|
|
6932
7034
|
suffix: this.options.suffix
|
|
6933
|
-
}
|
|
7035
|
+
},
|
|
7036
|
+
stripSchemaPrefix: this.options.stripSchemaPrefix
|
|
6934
7037
|
});
|
|
6935
7038
|
const isAlias = !!(schema.$ref && !schema.properties && !schema.allOf && !schema.oneOf && !schema.anyOf);
|
|
6936
7039
|
const zodSchema = this.propertyGenerator.generatePropertySchema(schema, name, isAlias);
|
|
@@ -7132,7 +7235,8 @@ ${propsCode}
|
|
|
7132
7235
|
generateQueryParamType(schema, param) {
|
|
7133
7236
|
if (schema.$ref) {
|
|
7134
7237
|
const refName = resolveRef(schema.$ref);
|
|
7135
|
-
const
|
|
7238
|
+
const strippedRefName = stripPrefix(refName, this.options.stripSchemaPrefix);
|
|
7239
|
+
const schemaName = toCamelCase(strippedRefName, { prefix: this.options.prefix, suffix: this.options.suffix });
|
|
7136
7240
|
return `${schemaName}Schema`;
|
|
7137
7241
|
}
|
|
7138
7242
|
if (schema.enum) {
|
|
@@ -7368,6 +7472,7 @@ var OpenApiGeneratorOptionsSchema = import_zod2.z.strictObject({
|
|
|
7368
7472
|
schemaType: import_zod2.z.enum(["all", "request", "response"]).optional(),
|
|
7369
7473
|
prefix: import_zod2.z.string().optional(),
|
|
7370
7474
|
suffix: import_zod2.z.string().optional(),
|
|
7475
|
+
stripSchemaPrefix: import_zod2.z.string().optional(),
|
|
7371
7476
|
showStats: import_zod2.z.boolean().optional(),
|
|
7372
7477
|
request: RequestResponseOptionsSchema.optional(),
|
|
7373
7478
|
response: RequestResponseOptionsSchema.optional(),
|
|
@@ -7384,6 +7489,7 @@ var ConfigFileSchema = import_zod2.z.strictObject({
|
|
|
7384
7489
|
schemaType: import_zod2.z.enum(["all", "request", "response"]).optional(),
|
|
7385
7490
|
prefix: import_zod2.z.string().optional(),
|
|
7386
7491
|
suffix: import_zod2.z.string().optional(),
|
|
7492
|
+
stripSchemaPrefix: import_zod2.z.string().optional(),
|
|
7387
7493
|
showStats: import_zod2.z.boolean().optional(),
|
|
7388
7494
|
request: RequestResponseOptionsSchema.optional(),
|
|
7389
7495
|
response: RequestResponseOptionsSchema.optional(),
|
|
@@ -7413,7 +7519,7 @@ async function loadConfig(configPath) {
|
|
|
7413
7519
|
}
|
|
7414
7520
|
if (!result || !result.config) {
|
|
7415
7521
|
throw new Error(
|
|
7416
|
-
configPath ? `Config file not found at: ${configPath}` : "No config file found. Searched for: openapi-to-zod.config.ts, openapi-to-zod.config.json, package.json (openapi-to-zod key)"
|
|
7522
|
+
configPath ? `Config file not found at: ${configPath}` : "No config file found. Searched for: openapi-to-zod.config.ts, openapi-to-zod.config.json, package.json (openapi-to-zod key)\nRun 'openapi-to-zod init' to create a new config file."
|
|
7417
7523
|
);
|
|
7418
7524
|
}
|
|
7419
7525
|
try {
|
|
@@ -7520,14 +7626,7 @@ function findSpecFiles() {
|
|
|
7520
7626
|
}
|
|
7521
7627
|
async function executeConfigMode(options) {
|
|
7522
7628
|
var _a, _b;
|
|
7523
|
-
|
|
7524
|
-
try {
|
|
7525
|
-
config = await loadConfig(options.config);
|
|
7526
|
-
} catch {
|
|
7527
|
-
throw new CliOptionsError("No config file found. Run 'openapi-to-zod init' to create one.", {
|
|
7528
|
-
configPath: options.config
|
|
7529
|
-
});
|
|
7530
|
-
}
|
|
7629
|
+
const config = await loadConfig(options.config);
|
|
7531
7630
|
const specs = mergeConfigWithDefaults(config);
|
|
7532
7631
|
const executionMode = config.executionMode || "parallel";
|
|
7533
7632
|
const batchSize = (_b = (_a = specs[0]) == null ? void 0 : _a.batchSize) != null ? _b : 10;
|