Skip to content

v0.96.1 cause typescript errors in generated zod schemas because of extend() on z.object({}).and() #3811

@amarant

Description

@amarant

Description

Following probably this PR : #3780
v0.96.1 cause typescript errors in generated zod schemas because of the usage extends() on z.object({}).and()

I have errors in :

  zUserNotificationDeleteContentRunning.extend({ status: z.literal('running') }),

Reproducible example or configuration

using this typespec reproduction :

import "@typespec/http";
import "@typespec/openapi";
import "@typespec/openapi3";

using Http;

model UserNotificationDeleteContentBase {
  name: string;
}

model UserNotificationDeleteContentRunning extends UserNotificationDeleteContentBase {
  startedAt: utcDateTime;
}

model UserNotificationDeleteContentSuccess extends UserNotificationDeleteContentBase {
  finishedAt: utcDateTime;
}

model UserNotificationDeleteContentError extends UserNotificationDeleteContentBase {
  finishedAt: utcDateTime;
  error: string;
}

@discriminated(#{ envelope: "none", discriminatorPropertyName: "status" })
union UserNotificationDeleteContent {
  running: UserNotificationDeleteContentRunning,
  success: UserNotificationDeleteContentSuccess,
  error: UserNotificationDeleteContentError,
}


@route("/notification")
@get
op getNotification() : UserNotificationDeleteContent;

And this example :

https://stackblitz.com/edit/hey-api-client-fetch-example-penlxfm1?file=openapi-ts.config.ts

OpenAPI specification (optional)

openapi: 3.0.0
info:
  title: (title)
  version: 0.0.0
tags: []
paths:
  /notification:
    get:
      operationId: getNotification
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserNotificationDeleteContent'
components:
  schemas:
    UserNotificationDeleteContent:
      type: object
      oneOf:
        - $ref: '#/components/schemas/UserNotificationDeleteContentRunning'
        - $ref: '#/components/schemas/UserNotificationDeleteContentSuccess'
        - $ref: '#/components/schemas/UserNotificationDeleteContentError'
      discriminator:
        propertyName: status
        mapping:
          running: '#/components/schemas/UserNotificationDeleteContentRunning'
          success: '#/components/schemas/UserNotificationDeleteContentSuccess'
          error: '#/components/schemas/UserNotificationDeleteContentError'
    UserNotificationDeleteContentBase:
      type: object
      required:
        - name
      properties:
        name:
          type: string
    UserNotificationDeleteContentError:
      type: object
      required:
        - finishedAt
        - error
      properties:
        finishedAt:
          type: string
          format: date-time
        error:
          type: string
      allOf:
        - $ref: '#/components/schemas/UserNotificationDeleteContentBase'
    UserNotificationDeleteContentRunning:
      type: object
      required:
        - startedAt
      properties:
        startedAt:
          type: string
          format: date-time
      allOf:
        - $ref: '#/components/schemas/UserNotificationDeleteContentBase'
    UserNotificationDeleteContentSuccess:
      type: object
      required:
        - finishedAt
      properties:
        finishedAt:
          type: string
          format: date-time
      allOf:
        - $ref: '#/components/schemas/UserNotificationDeleteContentBase'

System information (optional)

No response

Metadata

Metadata

Labels

bug 🔥Broken or incorrect behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions