Skip to content

Issues with generating OpenAI client in zod #12

Closed
@mhaligowski

Description

@mhaligowski

Great tool, incredibly helpful!

I am having issues when generating zod types for the OpenAI schema definition, available here: https://github.com/openai/openai-openapi/blob/master/openapi.yaml.

The generation works correctly, but when running tsc, I'm seeing issue like this:

src/generated/openai.ts:2117:5 - error TS2322: Type 'Promise<unknown>' is not assignable to type 'Promise<TypeOf<TEndpoint["response"]>>'.
  Type 'unknown' is not assignable to type 'TypeOf<TEndpoint["response"]>'.
    Type 'unknown' is not assignable to type 'string | { object: "model"; id: string; created: number; owned_by: string; } | { object: "list"; data: { object: "model"; id: string; created: number; owned_by: string; }[]; } | { object: "fine_tuning.job"; error: { code: string; message: string; param: string | null; } | null; status: "validating_files" | "queued" | "running" | "succeeded" | "failed" | "cancelled"; id: string; model: string; created_at: number; fine_tuned_model: string | null; finished_at: number | null; hyperparameters: { n_epochs: number | "auto"; }; organization_id: string; result_files: string[]; trained_tokens: number | null; training_file: string; validation_file: string | null; } | { object: "list"; data: { object: "fine_tuning.job"; error: { code: string; message: string; param: string | null; } | null; status: "validating_files" | "queued" | "running" | "succeeded" | "failed" | "cancelled"; id: string; model: string; created_at: number; fine_tuned_model: string | null; finished_at: number | null; hyperparameters: { n_epochs: number | "auto"; }; organization_id: string; result_files: string[]; trained_tokens: number | null; training_file: string; validation_file: string | null; }[]; has_more: boolean; } | { object: "file"; status: "error" | "uploaded" | "processed"; id: string; created_at: number; bytes: number; filename: string; purpose: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output"; status_details?: string | undefined; } | { object: "list"; data: { object: "file"; status: "error" | "uploaded" | "processed"; id: string; created_at: number; bytes: number; filename: string; purpose: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output"; status_details?: string | undefined; }[]; } | { object: "list"; data: { object: "fine_tuning.job.event"; message: string; id: string; created_at: number; level: "error" | "info" | "warn"; }[]; } | { object: "assistant"; id: string; model: string; name: string | null; description: string | null; tools: ({ type: "code_interpreter"; } | { type: "retrieval"; } | { function: { name: string; description?: string | undefined; parameters?: unknown; }; type: "function"; })[]; created_at: number; instructions: string | null; file_ids: string[]; metadata?: unknown; } | { object: string; data: { object: "assistant"; id: string; model: string; name: string | null; description: string | null; tools: ({ type: "code_interpreter"; } | { type: "retrieval"; } | { function: { name: string; description?: string | undefined; parameters?: unknown; }; type: "function"; })[]; created_at: number; instructions: string | null; file_ids: string[]; metadata?: unknown; }[]; has_more: boolean; first_id: string; last_id: string; } | { object: "thread.run"; status: "queued" | "failed" | "cancelled" | "in_progress" | "requires_action" | "cancelling" | "completed" | "expired"; id: string; model: string; tools: ({ type: "code_interpreter"; } | { type: "retrieval"; } | { function: { name: string; description?: string | undefined; parameters?: unknown; }; type: "function"; })[]; created_at: number; instructions: string; file_ids: string[]; thread_id: string; assistant_id: string; required_action: { type: "submit_tool_outputs"; submit_tool_outputs: { tool_calls: { function: { name: string; arguments: string; }; type: "function"; id: string; }[]; }; } | null; last_error: { code: "server_error" | "rate_limit_exceeded"; message: string; } | null; expires_at: number; started_at: number | null; cancelled_at: number | null; failed_at: number | null; completed_at: number | null; metadata?: unknown; } | { object: string; data: { object: "thread.run"; status: "queued" | "failed" | "cancelled" | "in_progress" | "requires_action" | "cancelling" | "completed" | "expired"; id: string; model: string; tools: ({ type: "code_interpreter"; } | { type: "retrieval"; } | { function: { name: string; description?: string | undefined; parameters?: unknown; }; type: "function"; })[]; created_at: number; instructions: string; file_ids: string[]; thread_id: string; assistant_id: string; required_action: { type: "submit_tool_outputs"; submit_tool_outputs: { tool_calls: { function: { name: string; arguments: string; }; type: "function"; id: string; }[]; }; } | null; last_error: { code: "server_error" | "rate_limit_exceeded"; message: string; } | null; expires_at: number; started_at: number | null; cancelled_at: number | null; failed_at: number | null; completed_at: number | null; metadata?: unknown; }[]; has_more: boolean; first_id: string; last_id: string; } | { object: "thread"; id: string; created_at: number; metadata?: unknown; } | { object: "thread.message"; id: string; content: ({ type: "image_file"; image_file: { file_id: string; }; } | { type: "text"; text: { value: string; annotations: ({ type: "file_citation"; text: string; file_citation: { file_id: string; quote: string; }; start_index: number; end_index: number; } | { type: "file_path"; text: string; start_index: number; end_index: number; file_path: { file_id: string; }; })[]; }; })[]; role: "user" | "assistant"; created_at: number; file_ids: string[]; thread_id: string; assistant_id: string | null; run_id: string | null; metadata?: unknown; } | { object: string; data: { object: "thread.message"; id: string; content: ({ type: "image_file"; image_file: { file_id: string; }; } | { type: "text"; text: { value: string; annotations: ({ type: "file_citation"; text: string; file_citation: { file_id: string; quote: string; }; start_index: number; end_index: number; } | { type: "file_path"; text: string; start_index: number; end_index: number; file_path: { file_id: string; }; })[]; }; })[]; role: "user" | "assistant"; created_at: number; file_ids: string[]; thread_id: string; assistant_id: string | null; run_id: string | null; metadata?: unknown; }[]; has_more: boolean; first_id: string; last_id: string; } | { object: "thread.run.step"; type: "tool_calls" | "message_creation"; status: "failed" | "cancelled" | "in_progress" | "completed" | "expired"; id: string; created_at: number; thread_id: string; assistant_id: string; last_error: { code: "server_error" | "rate_limit_exceeded"; message: string; } | null; cancelled_at: number | null; failed_at: number | null; completed_at: number | null; run_id: string; step_details: { type: "message_creation"; message_creation: { message_id: string; }; } | { type: "tool_calls"; tool_calls: ({ type: "code_interpreter"; id: string; code_interpreter: { input: string; outputs: ({ type: "logs"; logs: string; } | { type: "image"; image: { file_id: string; }; })[]; }; } | { type: "retrieval"; id: string; retrieval?: unknown; } | { function: { name: string; arguments: string; output: string | null; }; type: "function"; id: string; })[]; }; expired_at: number | null; metadata?: unknown; } | { object: string; data: { object: "thread.run.step"; type: "tool_calls" | "message_creation"; status: "failed" | "cancelled" | "in_progress" | "completed" | "expired"; id: string; created_at: number; thread_id: string; assistant_id: string; last_error: { code: "server_error" | "rate_limit_exceeded"; message: string; } | null; cancelled_at: number | null; failed_at: number | null; completed_at: number | null; run_id: string; step_details: { type: "message_creation"; message_creation: { message_id: string; }; } | { type: "tool_calls"; tool_calls: ({ type: "code_interpreter"; id: string; code_interpreter: { input: string; outputs: ({ type: "logs"; logs: string; } | { type: "image"; image: { file_id: string; }; })[]; }; } | { type: "retrieval"; id: string; retrieval?: unknown; } | { function: { name: string; arguments: string; output: string | null; }; type: "function"; id: string; })[]; }; expired_at: number | null; metadata?: unknown; }[]; has_more: boolean; first_id: string; last_id: string; } | { object: "assistant.file"; id: string; created_at: number; assistant_id: string; } | { object: string; data: { object: "assistant.file"; id: string; created_at: number; assistant_id: string; }[]; has_more: boolean; first_id: string; last_id: string; } | { object: "thread.message.file"; id: string; created_at: number; message_id: string; } | { object: string; data: { object: "thread.message.file"; id: string; created_at: number; message_id: string; }[]; has_more: boolean; first_id: string; last_id: string; }'.

2117     return this.fetcher('get', this.baseUrl + path, params[0]);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/generated/openai.ts:2126:5 - error TS2322: Type 'Promise<unknown>' is not assignable to type 'Promise<TypeOf<TEndpoint["response"]>>'.
  Type 'unknown' is not assignable to type 'TypeOf<TEndpoint["response"]>'.
    Type 'unknown' is not assignable to type '{ object: string; id: string; deleted: boolean; } | { object: "file"; id: string; deleted: boolean; } | { object: "assistant.deleted"; id: string; deleted: boolean; } | { object: "thread.deleted"; id: string; deleted: boolean; } | { object: "assistant.file.deleted"; id: string; deleted: boolean; }'.

2126     return this.fetcher('delete', this.baseUrl + path, params[0]);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: src/generated/openai.ts:2117

Interestingly, it doesn't have issues with the first method in the ApiClient class. I am running TypeScript 5.0.2, for that matter, typed-openapi isd on 0.2.0.

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