Skip to content

Enum exclude don't work properly from enum generated from protobuf #5611

@jfrag

Description

@jfrag

Zod returned me this error message for an Enum with excluded params:

newStatus: Invalid option: expected one of "COMPLETED"|"CANCELLED"|0|1|2|3|4
The returned message normally was: newStatus: Invalid option: expected one of 0|1|2|3|4

The enum was generated from protobuf schema.

export enum SessionStatus {
    /**
     * @generated from protobuf enum value: SESSION_STATUS_UNSPECIFIED = 0;
     */
    UNSPECIFIED = 0,
    /**
     * @generated from protobuf enum value: SESSION_STATUS_DRAFT = 1;
     */
    DRAFT = 1,
    /**
     * @generated from protobuf enum value: SESSION_STATUS_OPEN = 2;
     */
    OPEN = 2,
    /**
     * @generated from protobuf enum value: SESSION_STATUS_CONFIRMED = 3;
     */
    CONFIRMED = 3,
    /**
     * @generated from protobuf enum value: SESSION_STATUS_IN_PROGRESS = 4;
     */
    IN_PROGRESS = 4,
    /**
     * @generated from protobuf enum value: SESSION_STATUS_COMPLETED = 5;
     */
    COMPLETED = 5,
    /**
     * @generated from protobuf enum value: SESSION_STATUS_CANCELLED = 6;
     */
    CANCELLED = 6
}
export const SessionStatusSchema = z.enum(SessionStatus);
export const UpdateSessionStatusRequestSchema = z.object({
  sessionId: UUIDSchema,
  newStatus: SessionStatusSchema.exclude(['COMPLETED', 'CANCELLED'])
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions