Open dub-survivor opened 2 years ago
I have a similar problem after updating NSwag from v13.13.2.0 to v13.15.10.0 (and later to v13.16.0.0). I am getting an error while generating TypeScript files. Everything worked fine in 13.13.2.0 version.
I found out that changing "Date Time Type" from "MomentJS" to "Date", "String" or "Luxon" in settings solves the issue but I want to keep MomentJS.
My nswag.json
:
{
"runtime": "Net50",
"defaultVariables": null,
"documentGenerator": {
"fromDocument": {
"json": "",
"url": "http://localhost:4816/swagger/v1/swagger.json",
"output": null
}
},
"codeGenerators": {
"openApiToTypeScriptClient": {
"className": "{controller}Service",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 2.7,
"template": "Angular",
"promiseType": "Promise",
"httpClass": "HttpClient",
"useSingletonProvider": false,
"injectionTokenType": "InjectionToken",
"rxJsVersion": 6.0,
"dateTimeType": "MomentJS",
"nullValue": "Undefined",
"generateClientClasses": true,
"generateClientInterfaces": false,
"generateOptionalParameters": false,
"exportTypes": true,
"wrapDtoExceptions": false,
"exceptionClass": "SwaggerException",
"clientBaseClass": null,
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"protectedMethods": [],
"configurationClass": null,
"useTransformOptionsMethod": false,
"useTransformResultMethod": false,
"generateDtoTypes": true,
"operationGenerationMode": "MultipleClientsFromOperationId",
"markOptionalProperties": true,
"generateCloneMethod": false,
"typeStyle": "Class",
"classTypes": [],
"extendedClasses": [],
"extensionCode": null,
"generateDefaultValues": true,
"excludedTypeNames": [],
"excludedParameterNames": [],
"handleReferences": false,
"generateConstructorInterface": true,
"convertConstructorInterfaceData": false,
"importRequiredTypes": true,
"useGetBaseUrlMethod": false,
"baseUrlTokenName": "API_BASE_URL",
"queryNullValue": "",
"inlineNamedDictionaries": false,
"inlineNamedAny": false,
"templateDirectory": null,
"typeNameGeneratorType": null,
"propertyNameGeneratorType": null,
"enumNameGeneratorType": null,
"serviceHost": null,
"serviceSchemes": null,
"output": "../../Web/src/app/core/services/service-proxies.ts"
}
}
}
This is re-creatable by creating a new asp.net Core Web Api using Visual Studio 2022 (not sure if this matters) and .net 6.0. This will generate the WeatherForecast API. Add NSwag.AspNetCore nuget package. Add a DateTime parameter to the Get method.
The Program.cs file is altered to generate Swagger v2 output
The NSwag code generator is set to output a Typescript client, using Angular Template (RxJs version 6, TypeScript version 2.7) and Moment JS Date Time type. The exception is occurring in the TypeScriptParameterModel , GetDateTimeToString method. The _schema member is null. This error possibly occurs in any version of NSwagStudio greater than v13.15.9.0. It definitely occurs in v13.15.10.0 and v13.16.0.0
Regards