@vertz/openapi 0.1.2 → 0.1.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/bin/openapi.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/shared/{chunk-h8tb765a.js → chunk-19t7k664.js} +29 -17
- package/package.json +1 -1
package/bin/openapi.ts
CHANGED
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -42,6 +42,15 @@ function groupOperations(operations, strategy, options) {
|
|
|
42
42
|
|
|
43
43
|
// src/generators/client-generator.ts
|
|
44
44
|
function camelCase(name) {
|
|
45
|
+
const leadingUpper = name.match(/^[A-Z]+/);
|
|
46
|
+
if (leadingUpper) {
|
|
47
|
+
const prefix = leadingUpper[0];
|
|
48
|
+
if (prefix.length >= name.length)
|
|
49
|
+
return name.toLowerCase();
|
|
50
|
+
if (prefix.length > 1) {
|
|
51
|
+
return prefix.slice(0, -1).toLowerCase() + name.slice(prefix.length - 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
45
54
|
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
46
55
|
}
|
|
47
56
|
function generateAuthField(scheme) {
|
|
@@ -241,6 +250,14 @@ var VALID_IDENTIFIER = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
|
241
250
|
function isValidIdentifier(name) {
|
|
242
251
|
return VALID_IDENTIFIER.test(name);
|
|
243
252
|
}
|
|
253
|
+
function toPascalCase(name) {
|
|
254
|
+
const cleaned = name.replace(/[^A-Za-z0-9]+/g, " ").trim();
|
|
255
|
+
if (!cleaned)
|
|
256
|
+
return "_";
|
|
257
|
+
const segments = cleaned.split(/\s+/).filter(Boolean);
|
|
258
|
+
const result = segments.map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
|
|
259
|
+
return /^[0-9]/.test(result) ? `_${result}` : result;
|
|
260
|
+
}
|
|
244
261
|
|
|
245
262
|
// src/generators/resource-generator.ts
|
|
246
263
|
function generateResources(resources) {
|
|
@@ -334,7 +351,7 @@ function buildReturnType(op) {
|
|
|
334
351
|
return "Promise<FetchResponse<unknown[]>>";
|
|
335
352
|
}
|
|
336
353
|
if (op.response) {
|
|
337
|
-
const name =
|
|
354
|
+
const name = toPascalCase(op.operationId) + "Response";
|
|
338
355
|
return `Promise<FetchResponse<${name}>>`;
|
|
339
356
|
}
|
|
340
357
|
return "Promise<FetchResponse<void>>";
|
|
@@ -368,7 +385,7 @@ function collectTypeImports(resource) {
|
|
|
368
385
|
if (op.response.name) {
|
|
369
386
|
types.add(sanitizeTypeName(op.response.name));
|
|
370
387
|
} else {
|
|
371
|
-
types.add(
|
|
388
|
+
types.add(toPascalCase(op.operationId) + "Response");
|
|
372
389
|
}
|
|
373
390
|
}
|
|
374
391
|
if (op.requestBody) {
|
|
@@ -383,13 +400,10 @@ function collectTypeImports(resource) {
|
|
|
383
400
|
function deriveInputName(op) {
|
|
384
401
|
if (op.requestBody?.name)
|
|
385
402
|
return sanitizeTypeName(op.requestBody.name);
|
|
386
|
-
return
|
|
403
|
+
return toPascalCase(op.operationId) + "Input";
|
|
387
404
|
}
|
|
388
405
|
function deriveQueryName(op) {
|
|
389
|
-
return
|
|
390
|
-
}
|
|
391
|
-
function capitalize(s) {
|
|
392
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
406
|
+
return toPascalCase(op.operationId) + "Query";
|
|
393
407
|
}
|
|
394
408
|
|
|
395
409
|
// src/generators/json-schema-to-zod.ts
|
|
@@ -607,18 +621,19 @@ ${entries.join(`,
|
|
|
607
621
|
function deriveResponseSchemaName(op) {
|
|
608
622
|
if (op.response?.name)
|
|
609
623
|
return toSchemaVarName(op.response.name);
|
|
610
|
-
return toSchemaVarName(op.operationId + "Response");
|
|
624
|
+
return toSchemaVarName(toPascalCase(op.operationId) + "Response");
|
|
611
625
|
}
|
|
612
626
|
function deriveInputSchemaName(op) {
|
|
613
627
|
if (op.requestBody?.name)
|
|
614
628
|
return toSchemaVarName(op.requestBody.name);
|
|
615
|
-
return toSchemaVarName(op.operationId + "Input");
|
|
629
|
+
return toSchemaVarName(toPascalCase(op.operationId) + "Input");
|
|
616
630
|
}
|
|
617
631
|
function deriveQuerySchemaName(op) {
|
|
618
|
-
return toSchemaVarName(op.operationId + "Query");
|
|
632
|
+
return toSchemaVarName(toPascalCase(op.operationId) + "Query");
|
|
619
633
|
}
|
|
620
634
|
function toSchemaVarName(name) {
|
|
621
|
-
const
|
|
635
|
+
const sanitized = sanitizeTypeName(name);
|
|
636
|
+
const camel = sanitized.charAt(0).toLowerCase() + sanitized.slice(1);
|
|
622
637
|
return camel + "Schema";
|
|
623
638
|
}
|
|
624
639
|
|
|
@@ -679,15 +694,15 @@ function generateResourceTypes(resource, namedSchemas) {
|
|
|
679
694
|
function deriveResponseName(op) {
|
|
680
695
|
if (op.response?.name)
|
|
681
696
|
return sanitizeTypeName(op.response.name);
|
|
682
|
-
return
|
|
697
|
+
return toPascalCase(op.operationId) + "Response";
|
|
683
698
|
}
|
|
684
699
|
function deriveInputName2(op) {
|
|
685
700
|
if (op.requestBody?.name)
|
|
686
701
|
return sanitizeTypeName(op.requestBody.name);
|
|
687
|
-
return
|
|
702
|
+
return toPascalCase(op.operationId) + "Input";
|
|
688
703
|
}
|
|
689
704
|
function deriveQueryName2(op) {
|
|
690
|
-
return
|
|
705
|
+
return toPascalCase(op.operationId) + "Query";
|
|
691
706
|
}
|
|
692
707
|
function generateQueryInterface(name, op, namedSchemas) {
|
|
693
708
|
const lines = op.queryParams.map((param) => {
|
|
@@ -702,9 +717,6 @@ ${lines.join(`
|
|
|
702
717
|
}
|
|
703
718
|
`;
|
|
704
719
|
}
|
|
705
|
-
function capitalize2(s) {
|
|
706
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
707
|
-
}
|
|
708
720
|
|
|
709
721
|
// src/generators/index.ts
|
|
710
722
|
function generateAll(spec, options) {
|