next-openapi-gen 0.7.10 → 0.7.11

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.
@@ -551,6 +551,45 @@ export class ZodSchemaConverter {
551
551
  return this.processZodPrimitive(node);
552
552
  }
553
553
  }
554
+ // Handle schema reference with method calls, e.g., Image.optional(), UserSchema.nullable()
555
+ if (t.isCallExpression(node) &&
556
+ t.isMemberExpression(node.callee) &&
557
+ t.isIdentifier(node.callee.object) &&
558
+ t.isIdentifier(node.callee.property) &&
559
+ node.callee.object.name !== "z" // Make sure it's not a z.* call
560
+ ) {
561
+ const schemaName = node.callee.object.name;
562
+ const methodName = node.callee.property.name;
563
+ // Process base schema first if not already processed
564
+ if (!this.zodSchemas[schemaName]) {
565
+ this.convertZodSchemaToOpenApi(schemaName);
566
+ }
567
+ // If the schema exists, create a reference and apply the method
568
+ if (this.zodSchemas[schemaName]) {
569
+ let schema = {
570
+ allOf: [{ $ref: `#/components/schemas/${schemaName}` }],
571
+ };
572
+ // Apply method-specific transformations
573
+ switch (methodName) {
574
+ case "optional":
575
+ case "nullable":
576
+ case "nullish":
577
+ // Don't add nullable flag here as it would be at the wrong level
578
+ // The fact that it's optional is handled by not including it in required array
579
+ break;
580
+ case "describe":
581
+ if (node.arguments.length > 0 &&
582
+ t.isStringLiteral(node.arguments[0])) {
583
+ schema.description = node.arguments[0].value;
584
+ }
585
+ break;
586
+ default:
587
+ // For other methods, process as a chain
588
+ return this.processZodChain(node);
589
+ }
590
+ return schema;
591
+ }
592
+ }
554
593
  // Handle chained methods, e.g., z.string().email().min(5)
555
594
  if (t.isCallExpression(node) &&
556
595
  t.isMemberExpression(node.callee) &&
@@ -1045,13 +1084,23 @@ export class ZodSchemaConverter {
1045
1084
  // Apply the current method
1046
1085
  switch (methodName) {
1047
1086
  case "optional":
1048
- schema.nullable = true;
1087
+ // Don't add nullable for schema references wrapped in allOf
1088
+ // as it doesn't make sense in that context
1089
+ if (!schema.allOf) {
1090
+ schema.nullable = true;
1091
+ }
1049
1092
  break;
1050
1093
  case "nullable":
1051
- schema.nullable = true;
1094
+ // Don't add nullable for schema references wrapped in allOf
1095
+ if (!schema.allOf) {
1096
+ schema.nullable = true;
1097
+ }
1052
1098
  break;
1053
1099
  case "nullish": // Handles both null and undefined
1054
- schema.nullable = true;
1100
+ // Don't add nullable for schema references wrapped in allOf
1101
+ if (!schema.allOf) {
1102
+ schema.nullable = true;
1103
+ }
1055
1104
  break;
1056
1105
  case "describe":
1057
1106
  if (node.arguments.length > 0 && t.isStringLiteral(node.arguments[0])) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-openapi-gen",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
4
4
  "description": "Automatically generate OpenAPI 3.0 documentation from Next.js projects, with support for Zod schemas and TypeScript types.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",