Open MoeHamdan opened 2 years ago
Have you found a solution for this? For me, it's related to using MomentJS for the dates. Works fine if I use Date.
No, for me I cannot change that we have a production web app
Yeah, same here. For the short term, I changed to Date, generated a different file, and then manually merged the relevant parts.
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": ""
}
}
}
},
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.
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.
same problem with MomentJs, reverting dateTimeType to Date solve the issue
Any updates on this. Currently MomentJs dateTimeType do not work.
As a workaround set outputType
to OpenApi3
instead of Swagger
. Works with v13.18.2.
Thanks! Worked for me as well.
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" } } }
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.getGetDateTimeToString() in //src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptParameterModel.cs:line 96 at Fluid.Accessors.PropertyInfoAccessor.InvokergAwaited|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(Listg__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.getGetDateTimeToString() in //src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptParameterModel.cs:line 96
at Fluid.Accessors.PropertyInfoAccessor.Invokerg 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.getGetDateTimeToString() in //src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptParameterModel.cs:line 96
at Fluid.Accessors.PropertyInfoAccessor.Invokerb__1590() 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
2.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(ValueTask
1 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.Invoker
2.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, IReadOnlyList
1 statements, Int32 startIndex) at Fluid.FluidTemplateExtensions.1 arguments, TextWriter writer, TextEncoder encoder, TemplateContext context) at Fluid.Parser.ParserTagStatement
1.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, ValueTask
1 incompleteStatementTask, TextWriter writer, TextEncoder encoder, TemplateContext context, Int32 statementStartIndex) at Fluid.Parser.FluidTemplate.Awaited(ValueTask1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList
1 statements, Int32 startIndex) at Fluid.FluidTemplateExtensions.2.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(ValueTask
1 task, TextWriter writer, TextEncoder encoder, TemplateContext context, IReadOnlyList`1 statements, Int32 startIndex) at Fluid.FluidTemplateExtensions.2.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(ValueTask
1 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() --- End of inner exception stack trace --- at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate.Render() at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidParser.RenderTemplate(List
1 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(ValueTask
1 conditionTask, ValueTask1 incompleteStatementTask, TextWriter writer, TextEncoder encoder, TemplateContext context, Int32 statementStartIndex) at Fluid.Parser.FluidTemplate.Awaited(ValueTask
1 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() --- 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, IEnumerable
1 operations)+MoveNext() in //src/NSwag.CodeGeneration.TypeScript/TypeScriptClientGenerator.cs:line 112 at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable
1 collection) at NSwag.CodeGeneration.ClientGeneratorBase`3.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.ClientGeneratorBase
3.GenerateFile() in /_/src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 65 at NSwag.Commands.CodeGeneration.SwaggerToTypeScriptClientCommand.