Я использую NSwag
для генерации кода TypeScript. Сгенерированный код nswag отправляет значение NULL, когда я использую Nullable int в веб-API.
Как запретить NSwag
генерировать этот код или разрешить .NET Core 3.1 принять его в качестве допустимого значения?
http://localhost:4000/api/SurveyManagement/UpdateRouteSurvey?toSurveyId=null
Сгенерированный код TypeScript:
updateRouteSurvey(toSurveyId: number | null): Observable<void> {
let url_ = this.baseUrl + "/api/SurveyManagement/UpdateRouteSurvey?";
if (toSurveyId === undefined)
throw new Error("The parameter 'toSurveyId' must be defined.");
else
url_ += "toSurveyId=" + encodeURIComponent("" + toSurveyId) + "&";
url_ = url_.replace(/[?&]$/, "");
...
Интерфейс API C #
[HttpPost(nameof(UpdateRouteSurvey))]
public async Task UpdateRouteSurvey(int? toSurveyId) =>
await _manageSurveyService.UpdateRouteSurvey(toSurveyId);
Конфигурация NSwag
"openApiToTypeScriptClient": {
"className": "{controller}Client",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 2.7,
"template": "Angular",
"promiseType": "Promise",
"httpClass": "HttpClient",
"useSingletonProvider": false,
"injectionTokenType": "InjectionToken",
"rxJsVersion": 6.0,
"dateTimeType": "Date",
"nullValue": "Null",
"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": false,
"generateCloneMethod": false,
"typeStyle": "Interface",
"classTypes": [],
"extendedClasses": [],
"extensionCode": null,
"generateDefaultValues": false,
"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,
}