Search Unity

Feedback "Version" model ambiguity with System.Version

Discussion in 'Unity Cloud Content Delivery' started by Kamyker, Aug 24, 2020.

  1. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    I've generated c# client using https://editor.swagger.io/ but there are errors:
    Code (CSharp):
    1. 'Version' is an ambiguous reference between 'IO.Swagger.Model.Version' and 'System.Version'
    2.  
    For now it has to be fixed manually every time client sdk is updated, I wish this wasn't the case, maybe version model could be renamed to something else?

    Edit
    Tried NSwag instead and it seems to work a lot better. Anyway Unity should provide C# client to make it easier to use in Unity and server C# projects. If not that then at least recommend proper api generator.
     
    Last edited: Aug 24, 2020
  2. timtunity3d

    timtunity3d

    Unity Technologies

    Joined:
    Oct 1, 2015
    Posts:
    131
    That's a good point. Generating swagger clients always seems to lead to these sort of issues. I'm adding a task to look into a better way to document code generation and/or providing a client.
     
  3. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    For anyone looking to generate one, here's simple test method:
    Code (CSharp):
    1.  
    2.         [TestMethod()]
    3.         public async Task GenerateApi()
    4.         {
    5.             var className = "CDNServer";
    6.             var @namespace = "UnityCDNServer";
    7.             using ( System.Net.WebClient wclient = new System.Net.WebClient() )
    8.             {
    9.                 var document = await OpenApiDocument.FromJsonAsync(wclient.DownloadString("https://content-api.cloud.unity3d.com/doc/doc.json"));
    10.                 //var document = await OpenApiDocument.FromJsonAsync(File.ReadAllText(@"path"));
    11.                 var settings = new CSharpClientGeneratorSettings
    12.                 {
    13.                     ClassName = className,
    14.                     CSharpGeneratorSettings =
    15.                    {
    16.                     Namespace = @namespace
    17.                    }
    18.                 };
    19.                 var generator = new CSharpClientGenerator(document, settings);
    20.                 var code = generator.GenerateFile();
    21.                 string projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
    22.                 Console.WriteLine( solution_dir );
    23.                 File.WriteAllText( Path.Combine( projectDir, className + ".cs" ), code );
    24.             }
    25.         }
    26.  
    #Edit
    When generating api for use in Unity make sure to set
    GenerateDataAnnotations = false
    for CSharpGeneratorSettings as Unity doesn't have that net dll.
     
    Last edited: Aug 24, 2020