NSwag生成单个客户端类

问题描述

使用NSwagStudio生成C#客户端代码(不在文件中)时,它会生成仅使用其中的所有控制器方法生成一个客户端类和相应接口的方式。 但是,当尝试使用NSwag.MSBuild做相同的事情时,它将为每个控制器生成单独的部分类/接口。

这里是nswag.json

{
"openApiToCSharpClient": {
  "clientBaseClass": "BillingBaseClient","configurationClass": "Connectionoptions","generateClientClasses": true,"generateClientInterfaces": true,"clientBaseInterface": null,"injectHttpClient": true,"disposeHttpClient": true,"protectedMethods": [
  ],"generateExceptionClasses": true,"exceptionClass": "ApiException","wrapDtoExceptions": true,"useHttpClientCreationMethod": false,"httpClientType": "System.Net.Http.HttpClient","useHttpRequestMessageCreationMethod": true,"useBaseUrl": true,"generateBaseUrlProperty": false,"generateSyncmethods": false,"exposeJsonSerializerSettings": false,"clientClassAccessModifier": "public","typeAccessModifier": "public","generateContractsOutput": false,"contractsNamespace": null,"contractsOutputFilePath": null,"parameterDateTimeFormat": "s","parameterDateFormat": "yyyy-MM-dd","generateUpdateJsonSerializerSettingsMethod": true,"useRequestAndResponseSerializationSettings": false,"serializeTypeinformation": false,"queryNullValue": "","className": "BillingClient","operationGenerationMode": "MultipleClientsFromOperationId","additionalNamespaceUsages": [
  ],"additionalContractNamespaceUsages": [
  ],"generateOptionalParameters": true,"generateJsonMethods": true,"enforceFlagEnums": false,"parameterarrayType": "System.Collections.Generic.IEnumerable","parameterDictionaryType": "System.Collections.Generic.IDictionary","responseArrayType": "System.Collections.Generic.ICollection","responseDictionaryType": "System.Collections.Generic.IDictionary","wrapResponses": false,"wrapResponseMethods": [
  ],"generateResponseClasses": true,"responseClass": "SwaggerResponse","namespace": "ServiceTitan.Billing.Api.Client","requiredPropertiesMustbedefined": true,"dateType": "System.DateTimeOffset","jsonConverters": null,"anyType": "object","dateTimeType": "System.DateTimeOffset","timeType": "System.TimeSpan","timeSpanType": "System.TimeSpan","arrayType": "System.Collections.Generic.ICollection","arrayInstanceType": "System.Collections.ObjectModel.Collection","dictionaryType": "System.Collections.Generic.IDictionary","dictionaryInstanceType": "System.Collections.Generic.Dictionary","arrayBaseType": "System.Collections.ObjectModel.Collection","dictionaryBaseType": "System.Collections.Generic.Dictionary","classstyle": "Poco","generateDefaultValues": true,"generateDataAnnotations": true,"excludedTypeNames": [
  ],"excludedParameterNames": [
  ],"handleReferences": false,"generateImmutableArrayProperties": false,"generateImmutableDictionaryProperties": false,"jsonSerializerSettingsTransformationMethod": null,"inlineNamedArrays": false,"inlineNamedDictionaries": false,"inlineNamedTuples": true,"inlineNamedAny": false,"generateDtoTypes": true,"generateOptionalPropertiesAsNullable": false,"templateDirectory": null,"typeNameGeneratorType": null,"propertyNameGeneratorType": null,"enumNameGeneratorType": null,"serviceHost": null,"serviceSchemes": null,"output": "BillingClient.g.cs"
  }
}

那么我不知道告诉NSwag生成单个类/接口哪个选项?

解决方法

您需要更改的选项是 string xpath = "//div[ @id='attendance_no']"; var doc = web.Load(@"C:\Users\PC\Desktop\projese302\newtmp.html"); HtmlNode node = doc.DocumentNode.SelectSingleNode(xpath); node.InnerHtml = node.InnerHtml.Replace(node.InnerText (string)dataGridView1.Rows[1].Cells["Sayı"].Value); ,您的 nswag.json 文件中已有该选项,但如果您想为多个控制器提供一个接口,则需要将其值更改为 operationGenerationModeSingleClientFromOperationId 这是您当前设置的内容,将为每个控制器生成一个类。