Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generating typescript #3817

Open
MoeHamdan opened this issue Jan 4, 2022 · 11 comments
Open

Error generating typescript #3817

MoeHamdan opened this issue Jan 4, 2022 · 11 comments

Comments

@MoeHamdan
Copy link

Hello with latest NSwag I am getting the bellow error, kindly advise.
Starting web host
System.InvalidOperationException: Error while rendering Liquid template TypeScript/AxiosClient:
System.InvalidOperationException: Error while rendering Liquid template TypeScript/Client.RequestUrl:
System.NullReferenceException: Object reference not set to an instance of an object.

Runtime: Net60
at NSwag.CodeGeneration.TypeScript.Models.TypeScriptParameterModel.get_GetDateTimeToString() in //src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptParameterModel.cs:line 96
at Fluid.Accessors.PropertyInfoAccessor.Invoker2.Invoke(Object target) at Fluid.Accessors.PropertyInfoAccessor.Get(Object obj, String name, TemplateContext ctx) at Fluid.Values.ObjectValueBase.GetValueAsync(String name, TemplateContext context) at Fluid.Ast.IdentifierSegment.ResolveAsync(FluidValue value, TemplateContext context) at Fluid.Ast.MemberExpression.EvaluateAsync(TemplateContext context) at Fluid.Ast.OutputStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Ast.ElseIfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Ast.IfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Ast.ForStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Parser.FluidTemplate.Awaited(ValueTask1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList1 statements, Int32 startIndex) at Fluid.FluidTemplateExtensions.<RenderAsync>g__Awaited|3_0(ValueTask task, StringWriter writer, StringBuilderPool builder) at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render() ---> System.NullReferenceException: Object reference not set to an instance of an object. at NSwag.CodeGeneration.TypeScript.Models.TypeScriptParameterModel.get_GetDateTimeToString() in /_/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptParameterModel.cs:line 96 at Fluid.Accessors.PropertyInfoAccessor.Invoker2.Invoke(Object target)
at Fluid.Accessors.PropertyInfoAccessor.Get(Object obj, String name, TemplateContext ctx)
at Fluid.Values.ObjectValueBase.GetValueAsync(String name, TemplateContext context)
at Fluid.Ast.IdentifierSegment.ResolveAsync(FluidValue value, TemplateContext context)
at Fluid.Ast.MemberExpression.EvaluateAsync(TemplateContext context)
at Fluid.Ast.OutputStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.ElseIfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.IfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.ForStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Parser.FluidTemplate.Awaited(ValueTask1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList1 statements, Int32 startIndex)
at Fluid.FluidTemplateExtensions.g__Awaited|3_0(ValueTask task, StringWriter writer, StringBuilderPool builder)
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()
--- End of inner exception stack trace ---
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidParser.RenderTemplate(List1 arguments, TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Parser.ParserTagStatement1.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.ForStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.IfStatement.Awaited(ValueTask1 conditionTask, ValueTask1 incompleteStatementTask, TextWriter writer, TextEncoder encoder, TemplateContext context, Int32 statementStartIndex)
at Fluid.Parser.FluidTemplate.Awaited(ValueTask1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList1 statements, Int32 startIndex)
at Fluid.FluidTemplateExtensions.g__Awaited|3_0(ValueTask task, StringWriter writer, StringBuilderPool builder)
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()
---> System.InvalidOperationException: Error while rendering Liquid template TypeScript/Client.RequestUrl:
System.NullReferenceException: Object reference not set to an instance of an object.
at NSwag.CodeGeneration.TypeScript.Models.TypeScriptParameterModel.get_GetDateTimeToString() in /
/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptParameterModel.cs:line 96
at Fluid.Accessors.PropertyInfoAccessor.Invoker2.Invoke(Object target) at Fluid.Accessors.PropertyInfoAccessor.Get(Object obj, String name, TemplateContext ctx) at Fluid.Values.ObjectValueBase.GetValueAsync(String name, TemplateContext context) at Fluid.Ast.IdentifierSegment.ResolveAsync(FluidValue value, TemplateContext context) at Fluid.Ast.MemberExpression.EvaluateAsync(TemplateContext context) at Fluid.Ast.OutputStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Ast.ElseIfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Ast.IfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Ast.ForStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Parser.FluidTemplate.Awaited(ValueTask1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList1 statements, Int32 startIndex) at Fluid.FluidTemplateExtensions.<RenderAsync>g__Awaited|3_0(ValueTask task, StringWriter writer, StringBuilderPool builder) at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render() ---> System.NullReferenceException: Object reference not set to an instance of an object. at NSwag.CodeGeneration.TypeScript.Models.TypeScriptParameterModel.get_GetDateTimeToString() in /_/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptParameterModel.cs:line 96 at Fluid.Accessors.PropertyInfoAccessor.Invoker2.Invoke(Object target)
at Fluid.Accessors.PropertyInfoAccessor.Get(Object obj, String name, TemplateContext ctx)
at Fluid.Values.ObjectValueBase.GetValueAsync(String name, TemplateContext context)
at Fluid.Ast.IdentifierSegment.ResolveAsync(FluidValue value, TemplateContext context)
at Fluid.Ast.MemberExpression.EvaluateAsync(TemplateContext context)
at Fluid.Ast.OutputStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.ElseIfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.IfStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.ForStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Parser.FluidTemplate.Awaited(ValueTask1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList1 statements, Int32 startIndex)
at Fluid.FluidTemplateExtensions.g__Awaited|3_0(ValueTask task, StringWriter writer, StringBuilderPool builder)
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()
--- End of inner exception stack trace ---
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidParser.RenderTemplate(List1 arguments, TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Parser.ParserTagStatement1.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.ForStatement.WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context)
at Fluid.Ast.IfStatement.Awaited(ValueTask1 conditionTask, ValueTask1 incompleteStatementTask, TextWriter writer, TextEncoder encoder, TemplateContext context, Int32 statementStartIndex)
at Fluid.Parser.FluidTemplate.Awaited(ValueTask1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList1 statements, Int32 startIndex)
at Fluid.FluidTemplateExtensions.g__Awaited|3_0(ValueTask task, StringWriter writer, StringBuilderPool builder)
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()
--- End of inner exception stack trace ---
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render()
at NJsonSchema.CodeGeneration.CodeArtifact..ctor(String typeName, CodeArtifactType type, CodeArtifactLanguage language, CodeArtifactCategory category, ITemplate template)
at NSwag.CodeGeneration.TypeScript.TypeScriptClientGenerator.GenerateClientTypes(String controllerName, String controllerClassName, IEnumerable1 operations)+MoveNext() in /_/src/NSwag.CodeGeneration.TypeScript/TypeScriptClientGenerator.cs:line 112 at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection) at NSwag.CodeGeneration.ClientGeneratorBase3.GenerateAllClientTypes() in //src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 117
at NSwag.CodeGeneration.ClientGeneratorBase3.GenerateFile(ClientGeneratorOutputType outputType) in /_/src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 73 at NSwag.CodeGeneration.ClientGeneratorBase3.GenerateFile() in /
/src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 65
at NSwag.Commands.CodeGeneration.SwaggerToTypeScriptClientCommand.b__159_0() in //src/NSwag.Commands/Commands/CodeGeneration/OpenApiToTypeScriptClientCommand.cs:line 418
at NSwag.Commands.CodeGeneration.SwaggerToTypeScriptClientCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /
/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToTypeScriptClientCommand.cs:line 399
at NSwag.Commands.NSwagDocument.ExecuteAsync() in //src/NSwag.Commands/NSwagDocument.cs:line 85
at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /
/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 85
at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in //src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 32
at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /
/src/NSwag.Commands/NSwagCommandProcessor.cs:line 61

@rmatejka-sw
Copy link

Have you found a solution for this? For me, it's related to using MomentJS for the dates. Works fine if I use Date.

@MoeHamdan
Copy link
Author

No, for me I cannot change that we have a production web app

@rmatejka-sw
Copy link

Yeah, same here. For the short term, I changed to Date, generated a different file, and then manually merged the relevant parts.

@curcas
Copy link

curcas commented Mar 18, 2022

I have the same problem.
What I found out so far is that it only happens with DateTime parameters from the route.

"/api/Appointment/GetAppointmentConflictsByTask/getAppointmentConflictsByTask/{dateFrom}/{dateTo}/{taskId}": {
    "get": {
        "tags": [
            "Appointment"
        ],
        "operationId": "Appointment_GetAppointmentConflictsByTask",
        "parameters": [
            {
                "name": "dateFrom",
                "in": "path",
                "required": true,
                "schema": {
                    "type": "string",
                    "format": "date-time"
                },
                "x-position": 1
            },
            {
                "name": "dateTo",
                "in": "path",
                "required": true,
                "schema": {
                    "type": "string",
                    "format": "date-time"
                },
                "x-position": 2
            },
            {
                "name": "taskId",
                "in": "path",
                "required": true,
                "schema": {
                    "type": "integer",
                    "format": "int32"
                },
                "x-position": 3
            }
        ],
        "responses": {
            "200": {
                "description": "",
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/components/schemas/AppointmentConflictObj"
                            }
                        }
                    }
                }
            },
            "401": {
                "description": ""
            },
            "500": {
            "description": ""
            }
        }
    }
},

@robkroll
Copy link

robkroll commented Mar 24, 2022

Hello. I'm getting the same error. I did some digging, it seems to be related to commit 34eeb97 for issue #1613. The _schema property (which comes from OpenApiParameter.Schema) in TypeScriptParameterModel is null, and it seems like this only gets populated from if the parameter Kind is body? I thought it should be the base classes Schema property instead, but I have no idea 😄

In any case, downgrading to 13.15.9 has been a workaround for me. Edit: And as mentioned above, you need to remove DateTime parameters from the route.

@curcas
Copy link

curcas commented Mar 29, 2022

According to the commit the change was introduced in 13.14.7.

Downgrading to 13.15.9 did not solve it and 13.14.5 introduced other problems as the parameters in the url were not replaced anymore.

@pfab-io
Copy link

pfab-io commented Apr 12, 2022

same problem with MomentJs, reverting dateTimeType to Date solve the issue

@ximikavt
Copy link

Any updates on this. Currently MomentJs dateTimeType do not work.

@adammankowski1
Copy link

As a workaround set outputType to OpenApi3 instead of Swagger. Works with v13.18.2.

@rmatejka-sw
Copy link

Thanks! Worked for me as well.

@SathiyaGirinathan
Copy link

Any Updates? Still I'm facing the issue. The below is my nswag template.

{
"runtime": "Default",
"defaultVariables": null,
"documentGenerator": {
"fromDocument": {
"url": "http://localhost:22742/swagger/v1/swagger.json",
"output": null,
"newLineBehavior": "Auto"
}
},
"codeGenerators": {
"openApiToTypeScriptClient": {
"className": "{controller}ServiceProxy",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 4.9,
"template": "Angular",
"promiseType": "Promise",
"httpClass": "HttpClient",
"withCredentials": false,
"useSingletonProvider": false,
"injectionTokenType": "InjectionToken",
"rxJsVersion": 7.8,
"dateTimeType": "MomentJS",
"nullValue": "Undefined",
"generateClientClasses": true,
"generateClientInterfaces": false,
"generateOptionalParameters": false,
"exportTypes": true,
"wrapDtoExceptions": false,
"exceptionClass": "ApiException",
"clientBaseClass": null,
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"protectedMethods": [],
"configurationClass": null,
"useTransformOptionsMethod": false,
"useTransformResultMethod": false,
"generateDtoTypes": true,
"operationGenerationMode": "MultipleClientsFromPathSegments",
"markOptionalProperties": false,
"generateCloneMethod": false,
"typeStyle": "Class",
"enumStyle": "Enum",
"useLeafType": false,
"classTypes": [],
"extendedClasses": [],
"extensionCode": "service.extensions.ts",
"generateDefaultValues": true,
"excludedTypeNames": [],
"excludedParameterNames": [],
"handleReferences": false,
"generateTypeCheckFunctions": false,
"generateConstructorInterface": true,
"convertConstructorInterfaceData": false,
"importRequiredTypes": true,
"useGetBaseUrlMethod": false,
"baseUrlTokenName": "API_BASE_URL",
"queryNullValue": "",
"useAbortSignal": false,
"inlineNamedDictionaries": false,
"inlineNamedAny": false,
"includeHttpContext": false,
"templateDirectory": null,
"typeNameGeneratorType": null,
"propertyNameGeneratorType": null,
"enumNameGeneratorType": null,
"serviceHost": null,
"serviceSchemes": null,
"output": "../src/shared/service-proxies/service-proxies.ts",
"newLineBehavior": "Auto"
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants