{"id":21410104,"url":"https://github.com/recolude/swagger-unity-codegen","last_synced_at":"2025-07-14T02:30:51.468Z","repository":{"id":57561732,"uuid":"299078320","full_name":"recolude/swagger-unity-codegen","owner":"recolude","description":"Generate Unity3D client code from a swagger file","archived":false,"fork":false,"pushed_at":"2024-11-12T14:10:54.000Z","size":384,"stargazers_count":21,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T21:51:32.409Z","etag":null,"topics":["api","api-client","rest","swagger","unity3d"],"latest_commit_sha":null,"homepage":"","language":"Go","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/recolude.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":"2020-09-27T17:00:12.000Z","updated_at":"2024-07-08T13:50:34.000Z","dependencies_parsed_at":"2024-11-22T17:38:03.758Z","dependency_job_id":"c76467a1-8929-4986-a508-4f9af438bd56","html_url":"https://github.com/recolude/swagger-unity-codegen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/recolude/swagger-unity-codegen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recolude%2Fswagger-unity-codegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recolude%2Fswagger-unity-codegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recolude%2Fswagger-unity-codegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recolude%2Fswagger-unity-codegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/recolude","download_url":"https://codeload.github.com/recolude/swagger-unity-codegen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/recolude%2Fswagger-unity-codegen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265233753,"owners_count":23731825,"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":["api","api-client","rest","swagger","unity3d"],"created_at":"2024-11-22T17:37:34.328Z","updated_at":"2025-07-14T02:30:50.673Z","avatar_url":"https://github.com/recolude.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swagger Unity Codegen\n\n[![Build Status](https://travis-ci.com/recolude/swagger-unity-codegen.svg?branch=master)](https://travis-ci.com/recolude/swagger-unity-codegen) [![Coverage](https://codecov.io/gh/recolude/swagger-unity-codegen/branch/master/graph/badge.svg)](https://codecov.io/gh/recolude/swagger-unity-codegen) [![Go Report Card](https://goreportcard.com/badge/github.com/recolude/swagger-unity-codegen)](https://goreportcard.com/report/github.com/recolude/swagger-unity-codegen)\n\n**[Currently In Beta]**\n\nGenerate valid networking code for Unity3D that takes advantage of [Unity's Web Request](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html) object instead of something like RestSharp. This project was both made for and is used by [Recolude](https://app.recolude.com)'s Unity Plugin. Lots of cute unity things you can do here that wouldn't make sense sitting in original swagger codegen repo.\n\nPRs + Issues Welcome.\n\n## Installation\n\nBuilt and tested with golang 1.14, but should probably work on versions as far back as 1.10 (when string builder was introduced).\n\n```bash\ngit clone https://github.com/recolude/swagger-unity-codegen.git\ncd swagger-unity-codegen\ngo install ./cmd/swag3d\n```\n\n## Dependencies\n\nThe code produced from this tool will depend on two external DLLs. Trust me I tried my best to use just the builtin Unity Serializer at first, but it's just not powerful enough to take into account all the different types of definitions a swagger file can have 😓.\n\nThe two DLLs are:\n\n1. [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/)\n2. [JSONSubTypes](https://www.nuget.org/packages/JsonSubTypes/)\n\nMake sure that the DLLs you grab from the packages both target the same version of .NET\n\nIf you don't want to download them through nuget, you can checkout the dlls folder in this repository. I haven't tested them with most versions of Unity though.\n\n## Usage\n\n```\nNAME:\n   swag3d - swagger and Unity3D meet\n\nUSAGE:\n   swag3d [global options] command [command options] [arguments...]\n\nVERSION:\n   0.1.0\n\nDESCRIPTION:\n   Generate C# code specifically for Unity3D from a swagger file\n\nAUTHOR:\n   Elijah C Davis\n\nCOMMANDS:\n   generate, g  Generate c# code from a swagger file\n   help, h      Shows a list of commands or help for one command\n\nGLOBAL OPTIONS:\n   --help, -h     show help (default: false)\n   --version, -v  print the version (default: false)\n```\n\n### Example\n\nCommand used to generate Recolude's code.\n\n```bash\nswag3d generate \\\n\t--file api/openapi-spec/swagger.json \\\n\t--config-name=\"RecoludeConfig\" \\\n\t--config-menu=\"Recolude/Config\" \\\n\t--tags \"RecordingService\" \\\n\t--namespace Recolude.API \\\n\t--out \"Scripts\" \\\n\t--scriptable-object-config=false\n\n```\n\n## Features\n\n### Generate Scriptable Object For Configuring Services\n\nThe swagger tool will generate a [Scriptable Object](https://docs.unity3d.com/Manual/class-ScriptableObject.html) that can be used to store different keys found in your security definitions.\n\n![Imgur](https://i.imgur.com/WHI9XV2.png)\n\n### A Library You Can Use To Generate Your Own Code\n\nYou don't need a swagger file to generate your own unity code! This allows you to generate c# code as part of something like custom build pipelines that use in-house API definitions.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n\n\t\"github.com/recolude/swagger-unity-codegen/unitygen\"\n\t\"github.com/recolude/swagger-unity-codegen/unitygen/model\"\n\t\"github.com/recolude/swagger-unity-codegen/unitygen/model/property\"\n\t\"github.com/recolude/swagger-unity-codegen/unitygen/path\"\n)\n\nfunc main() {\n\t// Create a new file\n\tf, err := os.Create(\"api.cs\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// What we want our succesful response to be\n\tresponseDefinition := model.NewObject(\n\t\t\"EchoResponse\",\n\t\t[]model.Property{\n\t\t\tproperty.NewString(\"response\", \"\"),\n\t\t\tproperty.NewString(\"serverTime\", \"date-time\"),\n\t\t},\n\t)\n\n\tservice := unitygen.NewService(\n\t\t\"ExampleService\",\n\t\t[]path.Path{\n\t\t\tpath.NewPath(\n\t\t\t\t\"api/echo\",     // The URL endpoint, ex: example.com/api/echo\n\t\t\t\t\"Echo\",         // Name of the function that gets generated\n\t\t\t\thttp.MethodGet, // Get Rquest\n\t\t\t\tnil,            // Different tags\n\t\t\t\tnil,            // Security Definitions (Like API Keys)\n\n\t\t\t\t// Different responses that can be sent to the function\n\t\t\t\tmap[string]path.Response{\n\t\t\t\t\t\"200\": path.NewDefinitionResponse(\"\", responseDefinition),\n\t\t\t\t},\n\n\t\t\t\t// Paramters to call the function\n\t\t\t\t[]path.Parameter{\n\t\t\t\t\tpath.NewParameter(\n\t\t\t\t\t\tpath.QueryParameterLocation,   // Where the parameter should be located\n\t\t\t\t\t\t\"whatToEcho\",                  // name of the query param\n\t\t\t\t\t\ttrue,                          // require the parameter\n\t\t\t\t\t\tproperty.NewString(\"val\", \"\"), // name of the variable in c#\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t),\n\t\t},\n\t)\n\n\t// Write the service C# code to api.cs\n\tfmt.Fprint(f, responseDefinition.ToCSharp())\n\tfmt.Fprint(f, service.ToCSharp(nil, \"ServiceConfig\"))\n}\n```\n\nWhen the above code executes, it will generate the following C# code:\n\n```c#\n[System.Serializable]\npublic class EchoResponse\n{\n    public string response;\n\n    [SerializeField]\n    private string serverTime;\n\n    public System.DateTime ServerTime { get =\u003e System.DateTime.Parse(serverTime); }\n}\n\npublic class ExampleService\n{\n    public ServiceConfig Config { get; }\n\n    public ExampleService(ServiceConfig Config)\n    {\n        this.Config = Config;\n    }\n\n    public class EchoUnityWebRequest\n    {\n        public EchoResponse success;\n\n        public UnityWebRequest UnderlyingRequest { get; }\n\n        public EchoUnityWebRequest(UnityWebRequest req)\n        {\n            this.UnderlyingRequest = req;\n        }\n\n        public IEnumerator Run()\n        {\n            yield return this.UnderlyingRequest.SendWebRequest();\n            Interpret(this.UnderlyingRequest);\n        }\n\n        public void Interpret(UnityWebRequest req)\n        {\n            if (req.responseCode == 200)\n            {\n                success = JsonConvert.DeserializeObject\u003cEchoResponse\u003e(req.downloadHandler.text);\n            }\n        }\n    }\n\n    public class EchoRequestParams\n    {\n        private bool whatToEchoSet = false;\n        private string whatToEcho;\n        public string WhatToEcho { get { return whatToEcho; } set { whatToEchoSet = true; whatToEcho = value; } }\n        public void UnsetWhatToEcho() { whatToEcho = null; whatToEchoSet = false; }\n\n        public UnityWebRequest BuildUnityWebRequest(string baseURL)\n        {\n            var finalPath = baseURL + \"api/echo\";\n            var queryAdded = false;\n\n            if (whatToEchoSet)\n            {\n                finalPath += (queryAdded ? \"\u0026\" : \"?\") + \"whatToEcho=\";\n                queryAdded = true;\n                finalPath += UnityWebRequest.EscapeURL(whatToEcho.ToString());\n            }\n\n            return new UnityWebRequest(finalPath, UnityWebRequest.kHttpVerbGET);\n        }\n    }\n\n    public EchoUnityWebRequest Echo(EchoRequestParams requestParams)\n    {\n        var unityNetworkReq = requestParams.BuildUnityWebRequest(this.Config.BasePath);\n        unityNetworkReq.downloadHandler = new DownloadHandlerBuffer();\n        return new EchoUnityWebRequest(unityNetworkReq);\n    }\n\n    public EchoUnityWebRequest Echo(string whatToEcho)\n    {\n        return Echo(new EchoRequestParams()\n        {\n            WhatToEcho = whatToEcho,\n        });\n    }\n}\n```\n\n## Progress Towards V1\n\nOrdered by priority (to me)!\n\n- [x] Scriptable Object For Configuration.\n- [x] Easier Request Building.\n- [x] Prune unused definitions.\n- [x] Support for System.DateTime.\n- [x] Support Serializing Bodies.\n- [ ] Polymorphism\n- [ ] Implement [Fluent Interface Pattern](https://en.wikipedia.org/wiki/Fluent_interface) For Creating Requests.\n- [ ] Optional Parameters In Request Body.\n- [ ] Required Fields\n- [x] Embedded object definitions.\n- [ ] Embedded array object definitions.\n- [ ] Generate a scriptable object for any definition found in the swagger file.\n- [ ] Ability to generate ~~`*.unitypackage`~~ a package recognizable by the unity package manager.\n- [x] YAML support.\n- [ ] Oauth security definition.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecolude%2Fswagger-unity-codegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frecolude%2Fswagger-unity-codegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frecolude%2Fswagger-unity-codegen/lists"}