{"id":27088755,"url":"https://github.com/vc-great/openapi-to","last_synced_at":"2025-06-13T05:35:21.652Z","repository":{"id":176962996,"uuid":"646310819","full_name":"Vc-great/openapi-to","owner":"Vc-great","description":"根据openapi生成代码 ts request type zod MSW Faker nestjs","archived":false,"fork":false,"pushed_at":"2024-12-20T04:47:18.000Z","size":2002,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T04:03:37.641Z","etag":null,"topics":["interface","nestjs","openapi","request","swagger","ts","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/Vc-great.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":"2023-05-28T01:11:53.000Z","updated_at":"2024-12-20T04:47:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"9de7703a-d0a3-47c5-84ec-43cfc558e8be","html_url":"https://github.com/Vc-great/openapi-to","commit_stats":null,"previous_names":["vc-great/openapi-to"],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vc-great%2Fopenapi-to","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vc-great%2Fopenapi-to/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vc-great%2Fopenapi-to/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vc-great%2Fopenapi-to/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vc-great","download_url":"https://codeload.github.com/Vc-great/openapi-to/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441917,"owners_count":20939382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["interface","nestjs","openapi","request","swagger","ts","zod"],"created_at":"2025-04-06T06:22:15.316Z","updated_at":"2025-06-13T05:35:21.640Z","avatar_url":"https://github.com/Vc-great.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![codecov](https://codecov.io/github/Vc-great/openapi-to/branch/V2/graph/badge.svg?token=5UB04YYCEB)](https://codecov.io/github/Vc-great/openapi-to)\n\nThe current version is not compatible with V2.[V2 document](https://github.com/Vc-great/openapi-to/tree/v2)\n\n\n\n# At Glance\nopenapi-to is a library and toolkit that transforms your Swagger/OpenAPI specification into various client libraries, including:\n+ [x] ts request\n+ [x] ts type\n+ [x] zod\n+ [x] SWR\n+ [ ] Faker.js\n+ [ ] MSW\n+ [ ] nestjs\n+ [ ] vue-Query\n+ [ ] react-Query\n\n# Features\n- Works with Node.js 20+.\n- Supports Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1.\n\n# Quick Start\n## Install\n```shell [npm]\nnpm i openapi-to --save-dev\n```\n\n\n## Usage 1\n```js\n  npx openapi init  // Generate openapi.config.ts file\n  npx openapi g     // Generate code from the openapi.config.ts file\n```\n\n## Usage 2\n```json [package.json]\n{\n  \"scripts\": {\n    \"openapi:init\": \"openapi init\",\n    \"openapi:generate\": \"openapi g\"\n  }\n}\n```\n## Example\n```typescript twoslash [single]\nimport { defineConfig, pluginSWR, pluginTSRequest, pluginTSType, pluginZod } from 'openapi-to'\n\n\nexport default defineConfig({\n  servers:[\n    {\n    input: {\n      path:'https://petstore.swagger.io/v2/swagger.json'  //api documentation url\n    },\n        output:{\n       dir:'server'\n    }\n    }\n  ],\n  plugins: [\n    pluginSWR(),\n    pluginZod(),\n    pluginTSType(),\n    pluginTSRequest({\n      parser: 'zod',\n      requestClient: 'axios',\n      requestImportDeclaration: {\n        moduleSpecifier: '@/utils/request',\n      },\n      requestConfigTypeImportDeclaration: {\n        namedImports: ['AxiosRequestConfig'],\n        moduleSpecifier: 'axios',\n      }\n  ]\n})\n```\n\n# plugins\n## pluginTSRequest\n\nThe  plugin enables you to generate API controllers, simplifying the process of handling API requests and improving integration between frontend and backend services.\n\nBy default, we are using [Axios](https://axios-http.com/docs/intro) but you can also add your own client.\n\n**parser**\n\nWhich parser should be used before returning the data.\n\n| Type     | Zod   |\n| -------- | ----- |\n| Required | false |\n| Default  |       |\n\n**requestClient**\n\nRequest the client\n\n| Type     | axios\\|common |\n| -------- | ------------- |\n| Required | false         |\n| Default  | axios         |\n\naxios\n\n```ts\n//...\nexport async function addPetService(data: AddPetMutationRequest, requestConfig?: Partial\u003cAxiosRequestConfig\u003cAddPetMutationRequest\u003e\u003e) {\n  const res = await request\u003cAddPetMutationResponse, AxiosResponse\u003cAddPetMutationResponse, AddPetMutationRequest\u003e, AddPetMutationRequest\u003e({\n    method: 'POST',\n    url: '/pet',\n    data: data,\n    ...requestConfig\n  });\n  return res;\n}\n//...\n```\n\ncommon\n\n```ts\nexport async function addPetService(data: AddPetMutationRequest, requestConfig?: Partial\u003cAxiosRequestConfig\u003e) {\n  const res = await request\u003cAddPetMutationResponse\u003e({\n    method: 'POST',\n    url: '/pet',\n    data: data,\n    ...requestConfig\n  });\n  return res\n}\n```\n\n**requestImportDeclaration**\n\nRequest the client Import\n\n| Type     | String          |\n| -------- | --------------- |\n| Required | false           |\n| Default  | @/utils/request |\n\n**requestConfigTypeImportDeclaration**\n\nRequest Configuration Type Import\n\n**requestConfigTypeImportDeclaration.namedImports**\n\nRequest Configuration Type name\n\n| Type     | String             |\n| -------- | ------------------ |\n| Required | false              |\n| Default  | AxiosRequestConfig |\n\n**requestConfigTypeImportDeclaration.moduleSpecifier**\n\nRequest Configuration Type module\n\n| Type     | String |\n| -------- | ------ |\n| Required | false  |\n| Default  | axios  |\n\n```ts\n requestConfigTypeImportDeclaration: {\n    namedImports: ['AxiosRequestConfig'],\n    moduleSpecifier: 'axios',\n  }\n```\n\n**importWithExtension**\n\nWhether to add an extension (such as .ts) in the import path\n\n| Type     | String |\n| -------- | ------ |\n| Required | false  |\n| Default  | true   |\n\n**Example**\n\n```ts\npluginTSRequest({\n  parser: 'zod',\n  requestClient: 'axios',\n  requestImportDeclaration: {\n    moduleSpecifier: '@/utils/request',\n  },\n  requestConfigTypeImportDeclaration: {\n    namedImports: ['AxiosRequestConfig'],\n    moduleSpecifier: 'axios',\n  },\n   importWithExtension:false\n})\n```\n\n\n\n**pluginTSType**\n\nWith the TypeScript plugin you can create [TypeScript](https://www.typescriptlang.org/) types.\n\n**importWithExtension**\n\nWhether to add an extension (such as .ts) in the import path\n\n| Type     | String |\n| -------- | ------ |\n| Required | false  |\n| Default  | true   |\n\n\n## pluginZod\nWith the Zod plugin you can use [Zod](https://zod.dev/) to validate your schemas.\n\n**importWithExtension**\n\nWhether to add an extension (such as .ts) in the import path\n\n| Type     | String |\n| -------- | ------ |\n| Required | false  |\n| Default  | true   |\n\n## pluginSWR\n\nWith the SWR plugin you can create [SWR hooks](https://swr.vercel.app/) based on an operation.\n\n\n\n**infinite**\n\nuseSWRInfinite Related configurations\n\n**infinite.pageNumParam**\n\nGenerate useSWRInfinite based on pageNumParam\n\n| Type     | String |\n| -------- | ------ |\n| Required | false  |\n| Default  |        |\n\n**importWithExtension**\n\nWhether to add an extension (such as .ts) in the import path\n\n| Type     | String |\n| -------- | ------ |\n| Required | false  |\n| Default  | true   |\n\n\n\n**Example**\n\n```ts\n    pluginSWR({\n      infinite: {\n        pageNumParam: 'pageNum'\n      },\n      importWithExtension:false\n    })\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvc-great%2Fopenapi-to","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvc-great%2Fopenapi-to","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvc-great%2Fopenapi-to/lists"}