RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.82k stars 1.3k forks source link

Error generating typescript client System.Int64' cannot be converted to type 'System.Int32 #2746

Open dmandreev opened 4 years ago

dmandreev commented 4 years ago

Environment - ASP.NET Owin.

After upgrading NJsonSchema.CodeGeneration ^ NJsonSchema.CodeGeneration.TypeScript to 10.1.11 and NSwag.CodeGeneration.TypeScript 13.3.0 generator throws error. On any method (tried to mark all with [OpenApiIgnore], and find "bugged method" but without success)

NJsonSchema.CodeGeneration 10.1.5 and NSwag.CodeGeneration.TypeScript 13.2.3 version working fine.

Any clues how to fix it?

"Error while rendering Liquid template TypeScript/Class: System.ArgumentException: Object of type 'System.Int64' cannot be converted to type 'System.Int32'.

at DotLiquid.Context.HandleError(Exception ex) at DotLiquid.Block.RenderAll(List`1 list, Context context, TextWriter result) at DotLiquid.Document.Render(Context context, TextWriter result) at DotLiquid.Template.RenderInternal(TextWriter result, RenderParameters parameters) at DotLiquid.Template.Render(TextWriter writer, RenderParameters parameters) at DotLiquid.Template.Render(RenderParameters parameters) at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()

rootix commented 4 years ago

Did you found a solution to this already? We experience the exact same issue with the same version

dmandreev commented 4 years ago

Still no. Tried to compile debug version of DotLiquid, to trace error, but with no success due to lack of time.

dmandreev commented 4 years ago

As I can see, it's change in DotLiquid that introduced by
commit 7c168d18b4ec5665076e03cde8152ebceecb1985 Author: David Burg daviburg@microsoft.com Date: Tue Feb 25 13:14:34 2020 -0800

Support integer values for numbers beyond the range of 32 bit integers but within the RFC allowed 64 bit integers.

at Context.cs Contect class in function private object Resolve(string key, bool notifyNotFound = true)

Old code parses integers in such way:

   match = IntegerRegex.Match(key);
            if (match.Success)
                return Convert.ToInt32(match.Groups[1].Value);

new code parses integers and return long

           // Integer.
            match = IntegerRegex.Match(key);
            if (match.Success)
            {
                return Convert.ToInt64(match.Groups[1].Value);
            }

after that it leads to exception in Strainer.Invoke due to dynamic "tab" filter invocation because it has signature {(, System.String Tab(DotLiquid.Context, System.String, Int32))}

The workaround is to downgrade DotLiquid to 2.0.314

guffy1234 commented 4 years ago

Have the same issue. @dmandreev thanks for workaround. Waiting for a fix.

Kemyke commented 4 years ago

This is technically a not backward compatible change in DotLiquid. Sometimes it is hard to see if a small change will brake the interface. In this case this change should result in a bump of the major version. Which will prevent to reference incompatible versions of the DotLiquid package. This should be reported in that repository.

Thanks for the finding.

daviburg commented 4 years ago

My mess up. I will be reworking the change in dot Liquid.

daviburg commented 4 years ago

Trying to make amends at https://github.com/dotliquid/dotliquid/pull/378