{"id":19482700,"url":"https://github.com/darkphoenix2704/openapi-zod-swagger","last_synced_at":"2026-06-11T02:31:40.335Z","repository":{"id":262085598,"uuid":"886174424","full_name":"DarkPhoenix2704/openapi-zod-swagger","owner":"DarkPhoenix2704","description":"📦 A minimalist, copy-paste template for building type-safe API clients with Zod validation","archived":false,"fork":false,"pushed_at":"2024-11-10T12:11:50.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-16T22:38:26.512Z","etag":null,"topics":["api-client","axios","rest-api","template","type-safe","typescript","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DarkPhoenix2704.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-10T12:00:55.000Z","updated_at":"2024-11-10T12:12:00.000Z","dependencies_parsed_at":"2024-11-10T13:20:29.472Z","dependency_job_id":"3886bebc-5ed0-4176-9454-ae8fbb23e4be","html_url":"https://github.com/DarkPhoenix2704/openapi-zod-swagger","commit_stats":null,"previous_names":["darkphoenix2704/openapi-zod-swagger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DarkPhoenix2704/openapi-zod-swagger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkPhoenix2704%2Fopenapi-zod-swagger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkPhoenix2704%2Fopenapi-zod-swagger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkPhoenix2704%2Fopenapi-zod-swagger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkPhoenix2704%2Fopenapi-zod-swagger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DarkPhoenix2704","download_url":"https://codeload.github.com/DarkPhoenix2704/openapi-zod-swagger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkPhoenix2704%2Fopenapi-zod-swagger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34180147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","axios","rest-api","template","type-safe","typescript","zod"],"created_at":"2024-11-10T20:11:51.104Z","updated_at":"2026-06-11T02:31:40.320Z","avatar_url":"https://github.com/DarkPhoenix2704.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Type-Safe API Client Template\n\nA copy-paste template for creating strongly-typed API clients with built-in request/response validation.\n\n## Features\n\n- 🔒 Type-safe API calls\n- ✅ Request and response validation using Zod schemas\n- 📦 Version-aware API routing\n- 🔄 Automatic response parsing\n- 🛠️ Built on Axios for reliable HTTP requests\n- 🎯 Resource-based route organization\n\n## Usage\n\n### 1. Copy the Required Files\n\nCopy the following structure to your project:\n\n```\nsrc/\n├── api/\n│   ├── index.ts\n│   └── v1/\n│       └── users/\n│           ├── index.ts\n│           └── schema.ts\n├── core/\n│   ├── registry.ts\n│   └── types.ts\n└── index.ts\n```\n\n### 2. Install Dependencies\n\n```bash\nnpm install axios zod\n# or\nyarn add axios zod\n```\n\n### 3. Initialize Client\n\n```typescript\nimport { createApiClient } from './path-to/api-client';\n\n// Create an API client instance\nconst api = createApiClient({\n  baseURL: 'https://api.example.com',\n  headers: {\n    'Authorization': 'Bearer your-token'\n  }\n});\n```\n\n### 4. Use the Client\n\n```typescript\n// Example: List users\nasync function getUsers() {\n  try {\n    const response = await api.v1.users.listUsers(\n      undefined, // params\n      { limit: 10, offset: 0 } // query\n    );\n    console.log(response.data);\n  } catch (error) {\n    console.error('Failed to fetch users:', error);\n  }\n}\n```\n\n## Adding New Routes\n\n### 1. Create Schema File\n\n```typescript\n// src/api/v1/posts/schema.ts\nimport { z } from 'zod';\n\nexport const postSchema = z.object({\n  id: z.string(),\n  title: z.string(),\n  content: z.string(),\n  authorId: z.string()\n});\n\nexport const createPostSchema = postSchema.omit({\n  id: true\n});\n```\n\n### 2. Create Route File\n\n```typescript\n// src/api/v1/posts/index.ts\nimport Registry from '../../../core/registry';\nimport { postSchema, createPostSchema } from './schema';\nimport { z } from 'zod';\n\nexport function registerPostRoutes(registry: Registry) {\n  registry.register({\n    name: 'createPost',\n    method: 'POST',\n    version: 'v1',\n    path: '/v1/posts',\n    description: 'Create a new post',\n    request: {\n      body: createPostSchema\n    },\n    responses: {\n      201: {\n        description: 'The created post',\n        schema: postSchema\n      }\n    },\n    tags: ['posts']\n  });\n}\n```\n\n### 3. Register Routes\n\n```typescript\n// src/api/index.ts\nimport { registerUserRoutes } from './v1/users';\nimport { registerPostRoutes } from './v1/posts';\nimport Registry from \"../core/registry\";\n\nexport function registerRoutes(registry: Registry) {\n    registerUserRoutes(registry);\n    registerPostRoutes(registry);\n}\n```\n\n## Current Limitations\n\n- Native type inference is not yet complete and work in progress\n- Response types must be explicitly defined\n- No built-in support for file uploads\n- Limited error type definitions\n\n## Configuration\n\nThe client accepts Axios request config options:\n\n```typescript\nconst api = createApiClient({\n  baseURL: 'https://api.example.com',\n  timeout: 5000,\n  headers: {\n    'Authorization': 'Bearer token'\n  }\n});\n```\n\n## Error Handling\n\n```typescript\ntry {\n  const users = await api.v1.users.listUsers();\n} catch (error) {\n  if (error instanceof z.ZodError) {\n    // Handle validation error\n    console.error('Response validation failed:', error.errors);\n  } else {\n    // Handle other errors (network, etc.)\n    console.error('Request failed:', error);\n  }\n}\n```\n\n## Customization\n\nYou can modify the core files to add additional functionality:\n\n- Add middleware support in `registry.ts`\n- Extend error handling in the request function\n- Add custom validation rules to schemas\n- Implement caching mechanisms\n- Add request/response interceptors\n\n## Contributing\n\nThis is a template library - fork it and customize it for your needs! Feel free to share improvements through issues and pull requests.\n\n## License\n\nMIT License","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkphoenix2704%2Fopenapi-zod-swagger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkphoenix2704%2Fopenapi-zod-swagger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkphoenix2704%2Fopenapi-zod-swagger/lists"}