Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Zod schema generation for OpenAPI 3.1 prefixItems/tuple structures #1961

Open
aaazzam opened this issue Mar 6, 2025 · 0 comments
Labels
zod Zod related issue

Comments

@aaazzam
Copy link

aaazzam commented Mar 6, 2025

When generating Zod validation schemas from OpenAPI specifications that use prefixItems to define tuple structures (common when working with Python APIs that use Tuple types), Orval generates invalid TypeScript with syntax errors including:

  • Duplicate zodzod namespace references
  • Incorrectly placed commas and syntax in tuple definitions
  • Malformed Zod validation code that fails to compile
{
  "openapi": "3.1.0",
  "info": {
    "title": "Tuple Test API",
    "version": "1.0.0"
  },
  "paths": {
    "/test": {
      "get": {
        "operationId": "getTupleTest",
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GraphResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Node": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["RUNNING", "COMPLETED", "FAILED"]
          }
        },
        "required": ["id", "name", "status"]
      },
      "GraphResponse": {
        "type": "object",
        "properties": {
          "nodes": {
            "type": "array",
            "items": {
              "type": "array",
              "prefixItems": [
                {
                  "type": "string",
                  "format": "uuid"
                },
                {
                  "$ref": "#/components/schemas/Node"
                }
              ],
              "minItems": 2,
              "maxItems": 2
            }
          }
        },
        "required": ["nodes"]
      }
    }
  }
}
import * as zod from 'zod';

// This is the problematic generated code with errors
export const getTupleTestResponse = zod.object({
  "nodes": zod.array(zod.tuple([zod.string(),.uuid(),
zodzod.object({
  "id": zod.string().uuid(),
  "name": zod.string(),
  "status": zod.enum(['RUNNING', 'COMPLETED', 'FAILED'])
})]))
});
@melloware melloware added the zod Zod related issue label Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zod Zod related issue
Projects
None yet
Development

No branches or pull requests

2 participants