I have a ASP.NET Core 6.0 and Angular 13 & TypeScript 4.5 project.
I use Swagger and NSwag for create TypeScript clients.
My swagger.json like as below:
{
"openapi": "3.0.1",
"info": {
"title": "AdamBadam.Api",
"version": "1.0"
},
"paths": {
"/api/v1/Adam/GetData": {
"get": {
"tags": [
"Adam"
],
"parameters": [
{
"name": "id",
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/AdamListResponse"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/AdamListResponse"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/AdamListResponse"
}
}
}
}
}
}
},
"/api/v1/Badam/GetData": {
"get": {
"tags": [
"Badam"
],
"parameters": [
{
"name": "id",
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "PageNumber",
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
},
{
"name": "PageSize",
"in": "query",
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/BadamResponse"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/BadamResponse"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/BadamResponse"
}
}
}
}
}
}
},
And my nswag config file like as below:
{
"runtime": "Net80",
"defaultVariables": null,
"documentGenerator": {
"fromDocument": {
"json": "",
"url": "http://localhost:8080/swagger/v1/swagger.json",
"output": null,
"newLineBehavior": "Auto"
}
},
"codeGenerators": {
"openApiToTypeScriptClient": {
"className": "{controller}HttpService",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 4.5,
"template": "Angular",
"promiseType": "Promise",
"httpClass": "HttpClient",
"withCredentials": false,
"useSingletonProvider": false,
"injectionTokenType": "InjectionToken",
"rxJsVersion": 6.0,
"dateTimeType": "Date",
"nullValue": "Undefined",
"generateClientClasses": true,
"generateClientInterfaces": true,
"generateOptionalParameters": false,
"exportTypes": true,
"wrapDtoExceptions": true,
"exceptionClass": "ApiException",
"clientBaseClass": null,
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"protectedMethods": [],
"configurationClass": null,
"useTransformOptionsMethod": false,
"useTransformResultMethod": false,
"generateDtoTypes": true,
"operationGenerationMode": "MultipleClientsFromFirstTagAndOperationId",
"markOptionalProperties": true,
"generateCloneMethod": false,
"typeStyle": "Class",
"enumStyle": "Enum",
"useLeafType": false,
"classTypes": [],
"extendedClasses": [],
"extensionCode": "",
"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": "templates",
"serviceHost": null,
"serviceSchemes": null,
"output": "http-services.ts",
"newLineBehavior": "Auto"
}
}
}
NSwag create two different TypeScript clients. It is good. But NSwag add "2" suffix to BadamHttpService's GetData method.
For example, my clients are like as below:
AdamHttpService.GetData BadamHttpService.GetData2
If I create another controller that has GetData action, NSwag will create GetData3 method.
Also, I changed operationGenerationMode from MultipleClientsFromFirstTagAndOperationId to MultipleClientsFromOperationId, but NSwag create only one client in this situation.
How can I fix it ?