{"id":28092521,"url":"https://github.com/otk-final/openapi-codegen","last_synced_at":"2025-05-13T13:19:10.727Z","repository":{"id":290387196,"uuid":"970160673","full_name":"otk-final/openapi-codegen","owner":"otk-final","description":"openapi（swagger）代码生成器","archived":false,"fork":false,"pushed_at":"2025-05-09T05:07:40.000Z","size":800,"stargazers_count":26,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T05:27:14.213Z","etag":null,"topics":["openapi","openapi-generator","swagger","swagger-codegen"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/otk-final.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-04-21T15:18:11.000Z","updated_at":"2025-05-09T05:07:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"e31fef45-0ee6-450f-ad70-bf8d749acc95","html_url":"https://github.com/otk-final/openapi-codegen","commit_stats":null,"previous_names":["otk-final/openapi-codegen"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otk-final%2Fopenapi-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otk-final%2Fopenapi-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otk-final%2Fopenapi-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/otk-final%2Fopenapi-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/otk-final","download_url":"https://codeload.github.com/otk-final/openapi-codegen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948510,"owners_count":21988962,"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":["openapi","openapi-generator","swagger","swagger-codegen"],"created_at":"2025-05-13T13:19:10.212Z","updated_at":"2025-05-13T13:19:10.708Z","avatar_url":"https://github.com/otk-final.png","language":"Go","readme":"# OpenApi （Swagger）接口代码生成器 \n\nThis is a tool that generates API call code in various programming languages based on the content of an OpenAPI document.\n\n根据openapi (swagger) 文档生成不同编程语言客户端接口代码\n\n| Ts     | ![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/api_ts.jpg) |\n| ------ | ------------------------------------------------------------ |\n| Java   | ![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/api_java.jpg) |\n| Go     | ![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/api_go.jpg) |\n| Swift  | ![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/api_swift.jpg) |\n| Python | ![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/api_python.jpg) |\n| Kotlin | ![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/api_kotlin.jpg) |\n\n![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/home_api.png)\n\n![image](https://github.com/otk-final/openapi-codegen/blob/master/_images/home_struct.png)\n\n## Feature\n\n- 支持`v2`/`v3`文档格式\n- 支持语言：`ts`，`swift`，`kotlin`，`java`，`python`，`go`\n- ***支持泛型***\n- 支持自定义模版\n\n## Install \n\n源码编译\n\n```\ngo build -o openapi\n```\n\n## Download - 1.0.1\n\n- [mac](https://github.com/otk-final/openapi-codegen/releases/download/v1.0.1/openapi_darwin.zip)\n- [windows](https://github.com/otk-final/openapi-codegen/releases/download/v1.0.1/openapi_windows.zip)\n- [linux](https://github.com/otk-final/openapi-codegen/releases/download/v1.0.1/openapi_linux.zip)\n\n安装并添加到环境变量\n\n## Tutorial\n\n### start\n\n```shell\nopenapi start -h\n\nQuick start\n\nUsage:\n   start [flags]\n\nFlags:\n  -c, --client_output string   client output file\n  -e, --endpoint string        example：https://{server}:{port}/v3/api-docs\n  -h, --help                   help for start\n  -l, --lang string            kotlin,python,ts,typescript,swift,java,go,golang\n  -o, --output string          api output file\n  -s, --style string           customize template file\n  -v, --version string         openapi version (default \"v3\")\n\n```\n\n例子\n\n```shell\nopenapi -l ts -o src/api.ts -c src/client.ts  -v v3 -e http://localhost:8080/v3/api_docs\n```\n\n```\nopenapi -l kotlin -o src/api.kt -c src/client.kt  -v v2 -e http://localhost:8080/v2/api_docs\n```\n\n\n\n### init\n\n```shell\nopenapi init\n```\n\n在当前目录下生成`openapi.json`配置文件\n\n### reload\n\n```shell\n#默认当前目录下 openapi.json\nopenapi reload\n\n#自定义文件路径\nopenapi reload -f /app/openapi.json\n```\n\n根据`openapi.json`配置文件重新生成接口代码，默认全部\n\n```shell\n#指定env\nopenapi reload -f /app/openapi.json -n server_name\n```\n\n\n\n### Configuration File\n\n```json\n[{\n    \"name:\"server_name\",\n    //openapi 文档地址\n    \"endpoint\": \"http://localhost:8083/v3/api-docs\",\n    //api文件路径\n    \"output\": \"src/api.ts\",\n    //client文件路径\n    \"client_output\": \"src/client.ts\",\n    //目标语言\n    \"lang\": \"ts\",\n    //自定义模版路径\n    \"style\": \"custom.tmpl\",\n    //openapi 版本\n    \"version\": \"v3\",\n    //忽略路径\n    \"ignore\": [\"/error\",\"/v3/\"],\n    //匹配路径\n    \"filter\": [\"/user/\"],\n    //别名 - 当目标语言遇到语法关键词冲突时使用\n    \"alias\": {\n      //属性别名\n      \"properties\": {\n        \"JsonNode\":\"any\"\n      },\n      //结构体别名\n      \"modes\": {\n        \"User\":\"People\"\n      },\n      //类型别名\n      \"types\": {\n        //自定义数据类型\n        \"string\": \"CustomString\",\n        //format 自定义数据类型\n       \t\"interge+int64\": \"CustomLong\" \n      },\n      //参数别名\n      \"parameters\": {\n        \"export\": \"output\"\n      }\n    },\n    //模版文件变量\n    \"variables\": {\n      \"apiPackage\": \"com.demo.api\",\n      \"structPackage\": \"com.demo.dto\",\n      \"clientPackage\": \"com.demo\"\n    },\n    //泛型\n    \"generics\": {\n      //是否开启\n      \"enable\": true,\n      //是否展开Root包装类型\n      \"unfold\": false,\n      //泛型表达式\n      \"expressions\": {\n        //单一类型 - ApiResult\u003cT\u003e{... T data ...}\n        \"ApiResult\": [\n          \"data\"\n        ],\n        //集合类型 - PageData\u003cT\u003e{... List\u003cT\u003e entities ...}\n        \"PageData\": [\n          \"entities+\"\n        ],\n        //Map类型 - Map\u003cString,T\u003e{... T data ...}\n        \"MapResult\": [\n          \"data~\"\n        ],\n        //复合泛型 - KVPair\u003cT,V\u003e {... T key,V value ...}\n        \"KVPair\": [\n          \"key\",\n          \"value\"\n        ]\n      }\n    },\n    // 解决 openapi重复operation_id 导出带数字的方法名： batch_12 =\u003e batch\n    \"repeatable_operation_id\": true\n  }]\n```\n\n- openapi文档规范中不支持泛型，泛型表达式需在配置文件中预声明\n- 当server端采用统一标准泛型结构返回时，如：`ApiResult\u003cT\u003e`时，可开启`generics.unfold`  参数，业务方法可以直接获取`T`\n- 集合泛型声明：`属性+` ，采用 `+` 符号\n- Map泛型声明：`属性~` ，采用 `~`  符号\n- 内置模版文件：[模版文件](https://github.com/otk-final/openapi-codegen/tree/master/tmpl)\n\n### Example\n\n#### server端\n\n\u003e [openapi-server](https://github.com/otk-final/openapi-server)\n\n#### client端\n\n\u003e [ts](https://github.com/otk-final/openapi-codegen/tree/master/_example/ts)\n\u003e\n\u003e [go](https://github.com/otk-final/openapi-codegen/tree/master/_example/golang)\n\u003e\n\u003e [java](https://github.com/otk-final/openapi-codegen/tree/master/_example/java)\n\u003e\n\u003e [kotlin](https://github.com/otk-final/openapi-codegen/tree/master/_example/kotlin)\n\u003e\n\u003e [swift](https://github.com/otk-final/openapi-codegen/tree/master/_example/swift)\n\u003e\n\u003e [python](https://github.com/otk-final/openapi-codegen/tree/master/_example/python)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotk-final%2Fopenapi-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fotk-final%2Fopenapi-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fotk-final%2Fopenapi-codegen/lists"}