Skip to content

allOf being generated as union [zod v4] #2735

@Investo-cat

Description

@Investo-cat

Heyapi config:

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: './test.yaml',
  output: {
    format: 'prettier',
    lint: 'eslint',
    path: './src/client',
  },
  plugins: [
    {
      name: 'zod',
      types: {
        infer: true,
      },
    },
  ],
});

OpenAPI specification

openapi: '3.0.3'
info: 
  title: Test
components:
  requestBodies:
    req:
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/body'

  schemas:
    body:
      type: array
      items:
        allOf:
          - type: object
            properties:
              id:
                type: integer
          - type: object
            properties:
              name:
                type: string

Generated zod schema

// This file is auto-generated by @hey-api/openapi-ts

import { z } from 'zod';

export const zBody = z.array(
  z.union([
    z.object({
      id: z.optional(z.int()),
    }),
    z.object({
      name: z.optional(z.string()),
    }),
  ]),
);

export type BodyZodType = z.infer<typeof zBody>;

export const zReq = zBody;

export type ReqZodType = z.infer<typeof zReq>;

But I expect .and or .intersection instead of .union

Metadata

Metadata

Assignees

Labels

bug 🔥Something isn't workingjavascriptPull requests that update Javascript code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions