{"id":18702524,"url":"https://github.com/mayocream/openapi-codegen","last_synced_at":"2026-01-28T10:34:15.077Z","repository":{"id":256936903,"uuid":"856765142","full_name":"mayocream/openapi-codegen","owner":"mayocream","description":"Go OpenAPI client codegen","archived":false,"fork":false,"pushed_at":"2024-09-15T11:14:45.000Z","size":101,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T17:18:36.098Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mayocream.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-09-13T06:56:11.000Z","updated_at":"2024-09-15T11:14:48.000Z","dependencies_parsed_at":"2024-11-07T11:48:19.998Z","dependency_job_id":"e82357de-201e-4faa-9901-cd1bccffea36","html_url":"https://github.com/mayocream/openapi-codegen","commit_stats":null,"previous_names":["mayocream/openapi-codegen"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mayocream/openapi-codegen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayocream%2Fopenapi-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayocream%2Fopenapi-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayocream%2Fopenapi-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayocream%2Fopenapi-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mayocream","download_url":"https://codeload.github.com/mayocream/openapi-codegen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayocream%2Fopenapi-codegen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28844014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T07:39:25.367Z","status":"ssl_error","status_checked_at":"2026-01-28T07:39:24.487Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-07T11:46:06.447Z","updated_at":"2026-01-28T10:34:15.061Z","avatar_url":"https://github.com/mayocream.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openapi-codegen\n\nImplementation of OpenAPI code generation in Go.\n\nSupports [OpenAPI 3.0.3](https://spec.openapis.org/oas/v3.0.3.html).\n\n## Features\n\n- [x] Type-safe structs generation based on [kin-openapi](https://github.com/getkin/kin-openapi) package\n- [x] HTTP Client generation based on [resty](https://github.com/go-resty/resty) package\n\n## Usage\n\n```bash\ngo install github.com/mayocream/openapi-codegen@latest\n\nUsage of openapi-codegen:\n  -t, --client-tpl string   Path to client template file, e.g. client.tmpl\n  -o, --output string       Output path for generated Go file (default \".\")\n  -p, --package string      Go package name (default \"api\")\n  -i, --spec string         Path to OpenAPI spec file (default \"openapi.yaml\")\n\nopenapi-codegen -i openapi.yaml -o . -p api\n```\n\n## Customization\n\nYou can customize the generated code by providing a custom template file. The template file should be a Go template file with the following functions:\n- pascalCase\n- goComment\n\nExample template file:\n```go\npackage {{ .PackageName }}\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/go-resty/resty/v2\"\n\t\"github.com/samber/lo\"\n)\n\ntype Client struct {\n\tclient  *resty.Client\n}\n\nfunc NewClient(baseURL string) *Client {\n\treturn \u0026Client{\n\t\tclient:  resty.New().SetBaseURL(baseURL),\n\t}\n}\n\n{{ range .Requests }}\n{{- if .Parameters }}\n// {{ .Name }}Params represents the parameters for the {{ .Name }} request\ntype {{ .Name }}Params struct {\n\t{{- range .Parameters }}\n\t{{- if .Description }} {{ goComment .Name .Description }} {{- end }}\n\t{{- if eq .Type \"enum\" }}\n\t// {{ .Name }} enum\n\t{{ .Name }} string `json:\"{{ .JSONName }}{{ if .OmitEmpty }},omitempty{{ end }}\"`\n\t{{- else }}\n\t{{ .Name }} {{ .Type }} `json:\"{{ .JSONName }}{{ if .OmitEmpty }},omitempty{{ end }}\"`\n\t{{- end }}\n\t{{- end }}\n}\n{{- end }}\nfunc (c *Client) {{ .Name }}({{ if .Parameters }}params {{ .Name }}Params{{ end }}{{ if .Body }}, body {{ .Body.Name }} {{ end }}) ({{ if .Response }}*{{ .Response.Name }}, {{ end }}error) {\n\tpath := \"{{ .Path }}\"\n\n\t{{- if .Parameters }}\n\t// Replace path parameters and prepare query parameters\n\tqueryParams := make(map[string]string)\n\t{{- range .Parameters }}\n\t{{- if eq .In \"path\" }}\n\tpath = strings.ReplaceAll(path, \"{{ printf \"{%s}\" .JSONName }}\", fmt.Sprintf(\"%v\", params.{{ .Name }}))\n\t{{- else if eq .In \"query\" }}\n\tif lo.IsNotEmpty(params.{{ .Name }}) {\n\t\tqueryParams[\"{{ .JSONName }}\"] = fmt.Sprintf(\"%v\", params.{{ .Name }})\n\t}\n\t{{- end }}\n\t{{- end }}\n\t{{- end }}\n\n\t// Create request\n\treq := c.client.R()\n\n\t{{- if .Parameters }}\n\t// Set query parameters\n\treq.SetQueryParams(queryParams)\n\n\t{{- range .Parameters }}\n\t{{- if eq .In \"header\" }}\n\t// Set header parameters\n\tif lo.IsNotEmpty(params.{{ .Name }}) {\n\t\treq.SetHeader(\"{{ .JSONName }}\", fmt.Sprintf(\"%v\", params.{{ .Name }}))\n\t}\n\t{{- end }}\n\t{{- end }}\n\t{{- end }}\n\n\t{{- if .Body }}\n\t// Set request body\n\treq.SetBody(body)\n\t{{- end }}\n\n\t{{- if .Response }}\n\t// Set response object\n\tvar result {{ .Response.Name }}\n\treq.SetResult(\u0026result)\n\t{{- end }}\n\n\t// Send request\n\tresp, err := req.{{ .Method }}(path)\n\tif err != nil {\n\t\treturn {{ if .Response }}nil, {{ end }}fmt.Errorf(\"error sending request: %w\", err)\n\t}\n\n\t// Check for successful status code\n\tif resp.StatusCode() \u003c 200 || resp.StatusCode() \u003e= 300 {\n\t\treturn {{ if .Response }}nil, {{ end }}fmt.Errorf(\"unexpected status code: %d, body: %s\", resp.StatusCode(), resp.String())\n\t}\n\n\t{{- if .Response }}\n\treturn \u0026result, nil\n\t{{- else }}\n\treturn nil\n\t{{- end }}\n}\n{{ end }}\n```\n\nso that you can generate the client code with the following command:\n```bash\nopenapi-codegen -i openapi.yaml -o . -p api -t client.tmpl\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayocream%2Fopenapi-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmayocream%2Fopenapi-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayocream%2Fopenapi-codegen/lists"}