swagger-api / swagger-api/swagger-codegen
[C#] Codegen for Unity
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Even though there's two generators for C# (csharp and csharp-dotnet2) both relying on RestSharp, and also both can be adapted to work with Unity, the game engine. But here's my motivation for a separate generator for Unity:
-
Using UnityWebRequest which is the fastest and has the lowest memory footprint across all platforms Unity supports, for any build settings. In addition, it will result in a smaller build sizes after removing (also, it automatically handles special cases and platforms, such as WebGL, where the .NET networking
classes (ie, everything in the System.Net namespace, particularly System.Net.Sockets) are non-functional in WebGL.) -
Using a version of
Json.NETthat is adapted for Unity (for both Mono and IL2CPP platforms) -
A generated code that automatically handles Scripting restrictions (for example, certain types will be stripped out in a IL2CPP build, unless they are used in the code somehwhere, or else json deserialization could fail. The generated code can be done to take this into account)
-
Handing async operations Unity style (using Coroutines and/or async/await methods, depending on current player and build settings, using platform dependent compilation defines)
-
Adding some sugar (assembly definition files, scriptable objects to store configurations, custom inspectors to make calls to codegen and regenerate the code - see picture below as an example - , and so on)

-
Exposing only relevant options to Unity in the generator
-
Removing irrelevant files (e.g. no need for build scripts or C# solution files)
-
Tests organised in a way to run well in Unity's test runner
Please let me know what do you think.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the existing csharp and csharp-dotnet2 generators first, then define the separate Unity generator around UnityWebRequest, Unity-compatible Json.NET, Unity-style async handling, and platform restrictions. Done would mean the Unity-specific generator covers the requested options, Unity-oriented files and configuration, and tests that run in Unity's test runner.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, unity
- Domain
- game-dev, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100