Anonymous
NSwag запустите проект API .NET 8 в Command="$(NSwagExe_Net80) запустите NSwag.json /variables:Configuration=$(Configura
Сообщение
Anonymous » 10 май 2024, 05:38
В проекте Dotnet API недавно мы обновляем версию .NET с 6 до 8.
В новой версии приложения в файле nswag.json
изменен с «webApiToOpenApi» на «aspNetCoreToOpenApi».
Вот мой файл nswag.json:
Код: Выделить всё
{
"runtime": "Net80",
"defaultVariables": "Configuration=Release,OutDir=bin/Release/net8.0/,HomeDir=%USERPROFILE%",
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project": "AppServices.csproj",
"controllerNames": [],
"isAspNetCore": true,
"resolveJsonOptions": false,
"defaultUrlTemplate": "api/{controller}/{id?}",
"addMissingPathParameters": false,
"includedVersions": null,
"defaultPropertyNameHandling": "CamelCase",
"defaultReferenceTypeNullHandling": "Null",
"defaultDictionaryValueReferenceTypeNullHandling": "NotNull",
"defaultResponseReferenceTypeNullHandling": "Null",
"defaultEnumHandling": "Integer",
"flattenInheritanceHierarchy": false,
"generateKnownTypes": true,
"generateEnumMappingDescription": false,
"generateXmlObjects": false,
"generateAbstractProperties": false,
"generateAbstractSchemas": true,
"ignoreObsoleteProperties": false,
"allowReferencesWithProperties": false,
"excludedTypeNames": [],
"serviceHost": null,
"serviceBasePath": null,
"serviceSchemes": [],
"infoTitle": "App Content Services",
"infoDescription": null,
"infoVersion": "1.0.0",
"documentTemplate": null,
"documentProcessorTypes": [],
"operationProcessorTypes": [],
"typeNameGeneratorType": null,
"schemaNameGeneratorType": null,
"contractResolverType": null,
"serializerSettingsType": null,
"useDocumentProvider": true,
"documentName": "v1",
"aspNetCoreEnvironment": null,
"createWebHostBuilderMethod": null,
"startupType": null,
"allowNullableBodyParameters": true,
"output": null,
"outputType": "Swagger2",
"newLineBehavior": "Auto",
"assemblyPaths": [],
"assemblyConfig": null,
"referencePaths": [
"$(HomeDir)/.nuget/packages"
],
"validateEnums": false,
"generateEnums": false,
"msBuildProjectExtensionsPath": null,
"configuration": null,
"runtime": null,
"targetFramework": null,
"noBuild": true,
"msBuildOutputPath": null,
"verbose": true,
"workingDirectory": null,
"requireParametersWithoutDefault": false,
"apiGroupNames": null,
"useNuGetCache": false
}
},
"codeGenerators": {
"openApiToCSharpClient": {
"clientBaseClass": "",
"configurationClass": "",
"generateClientClasses": true,
"generateClientInterfaces": true,
"clientBaseInterface": null,
"injectHttpClient": true,
"disposeHttpClient": true,
"protectedMethods": [],
"generateExceptionClasses": true,
"exceptionClass": "SwaggerException",
"wrapDtoExceptions": true,
"useHttpClientCreationMethod": true,
"httpClientType": "System.Net.Http.HttpClient",
"useHttpRequestMessageCreationMethod": false,
"useBaseUrl": false,
"generateBaseUrlProperty": true,
"generateSyncMethods": true,
"generatePrepareRequestAndProcessResponseAsAsyncMethods": 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": "{controller}Client",
"operationGenerationMode": "MultipleClientsFromOperationId",
"additionalNamespaceUsages": [],
"additionalContractNamespaceUsages": [],
"generateOptionalParameters": false,
"generateJsonMethods": true,
"enforceFlagEnums": false,
"parameterArrayType": "System.Collections.Generic.IEnumerable",
"parameterDictionaryType": "System.Collections.Generic.IDictionary",
"responseArrayType": "System.Collections.Generic.List",
"responseDictionaryType": "System.Collections.Generic.Dictionary",
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"namespace": "AppService.Clients",
"requiredPropertiesMustBeDefined": true,
"dateType": "System.DateTime",
"jsonConverters": null,
"anyType": "object",
"dateTimeType": "System.DateTime",
"timeType": "System.TimeSpan",
"timeSpanType": "System.TimeSpan",
"arrayType": "System.Collections.Generic.List",
"arrayInstanceType": null,
"dictionaryType": "System.Collections.Generic.Dictionary",
"dictionaryInstanceType": null,
"arrayBaseType": "System.Collections.Generic.List",
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
"classStyle": "Inpc",
"jsonLibrary": "NewtonsoftJson",
"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,
"generateNullableReferenceTypes": false,
"templateDirectory": null,
"typeNameGeneratorType": null,
"propertyNameGeneratorType": null,
"enumNameGeneratorType": null,
"serviceHost": null,
"serviceSchemes": null,
"output": "../AppServices.Clients/GeneratedClients.cs",
"newLineBehavior": "Auto",
"validateEnums": false,
"generateEnums": false
}
}
}
Но при выполнении приведенной ниже команды приложение запускается.
и создайте приведенный ниже журнал:
Код: Выделить всё
10>NSwag command line tool for .NET Core Net80, toolchain v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
10>Visit http://NSwag.org for more information.
10>NSwag bin directory: C:\.....\packages\nswag.msbuild\14.0.7\tools\Net80
10>
10>Executing file 'NSwag.json' with variables 'Configuration=Release,OutDir=bin\Release\net8.0\,HomeDir=C:\Users\MA0021'...
10>Launcher directory: C:\Users\MA0021\.nuget\packages\nswag.msbuild\14.0.7\tools\Net80
10>init main
10>Configuring to Use DbConfigurationSource.
10>info: DbConfigurationProvider[0]
10> DbConfigurationProvider - Static Logger Configured
10>info: WebHostBootstrapper[0]
10> WebHostBootstrapper - Static Logger Configured
10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[3]
10> Hosting starting
10>dbug: Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory[12]
10> Registered model binder providers, in the following order: Microsoft.AspNetCore.Mvc.ModelBinding.......
10>dbug: Microsoft.AspNetCore.Mvc.Razor.Compilation.DefaultViewCompiler[4]
10> Initializing Razor view compiler with no compiled views.
10>info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
10> User profile is available. Using 'C:\Users\MA0021\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
10>dbug: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[37]
10> Reading data from file 'C:\Users\MA0021\AppData\Local\ASP.NET\DataProtection-Keys\key-8b371780-fd9d-496b-bb67-2db2152258dc.xml'.
................
10>dbug: Microsoft.AspNetCore.DataProtection.Internal.DataProtectionHostedService[65]
10> Key ring with default key {8b371780-fd9d-496b-bb67-2db2152258dc} was loaded during application startup.
10>dbug: Microsoft.AspNetCore.Server.Kestrel[0]
10> No listening endpoints were configured. Binding to http://localhost:5000 by default.
10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[4]
10> Hosting started
10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[13]
10> Loaded hosting startup assembly AppServices
10>Hosting environment: Production
10>Content root path: C:\xxxxProj\AppServices
10>Now listening on: http://localhost:5000
10>Application started. Press Ctrl+C to shut down.
10>info: DbConfigurationProvider[0]
10> DbConfigurationProvider - Static Logger Configured
10>info: WebHostBootstrapper[0]
10> WebHostBootstrapper - Static Logger Configured
10>trce: DbConfigurationProvider[0]
10> OnReloadTimerElapsed Triggered
10>Application is shutting down...
10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[5]
10> Hosting shutdown
10>Done.
10>
10>Duration: 00:00:34.7767604
10>Done building project "AppServices.csproj".
Пытался добавить приведенные ниже параметры в nswag, но приложение все равно запускается.
Код: Выделить всё
"validateEnums": false, "generateEnums": false,
Чего-нибудь не хватает?
Подробнее здесь:
https://stackoverflow.com/questions/784 ... nswag-json
1715308682
Anonymous
В проекте Dotnet API недавно мы обновляем версию .NET с 6 до 8. В новой версии приложения в файле nswag.json [code]"documentGenerator"Механизм [/code] изменен с «webApiToOpenApi» на «aspNetCoreToOpenApi». Вот мой файл nswag.json: [code]{ "runtime": "Net80", "defaultVariables": "Configuration=Release,OutDir=bin/Release/net8.0/,HomeDir=%USERPROFILE%", "documentGenerator": { "aspNetCoreToOpenApi": { "project": "AppServices.csproj", "controllerNames": [], "isAspNetCore": true, "resolveJsonOptions": false, "defaultUrlTemplate": "api/{controller}/{id?}", "addMissingPathParameters": false, "includedVersions": null, "defaultPropertyNameHandling": "CamelCase", "defaultReferenceTypeNullHandling": "Null", "defaultDictionaryValueReferenceTypeNullHandling": "NotNull", "defaultResponseReferenceTypeNullHandling": "Null", "defaultEnumHandling": "Integer", "flattenInheritanceHierarchy": false, "generateKnownTypes": true, "generateEnumMappingDescription": false, "generateXmlObjects": false, "generateAbstractProperties": false, "generateAbstractSchemas": true, "ignoreObsoleteProperties": false, "allowReferencesWithProperties": false, "excludedTypeNames": [], "serviceHost": null, "serviceBasePath": null, "serviceSchemes": [], "infoTitle": "App Content Services", "infoDescription": null, "infoVersion": "1.0.0", "documentTemplate": null, "documentProcessorTypes": [], "operationProcessorTypes": [], "typeNameGeneratorType": null, "schemaNameGeneratorType": null, "contractResolverType": null, "serializerSettingsType": null, "useDocumentProvider": true, "documentName": "v1", "aspNetCoreEnvironment": null, "createWebHostBuilderMethod": null, "startupType": null, "allowNullableBodyParameters": true, "output": null, "outputType": "Swagger2", "newLineBehavior": "Auto", "assemblyPaths": [], "assemblyConfig": null, "referencePaths": [ "$(HomeDir)/.nuget/packages" ], "validateEnums": false, "generateEnums": false, "msBuildProjectExtensionsPath": null, "configuration": null, "runtime": null, "targetFramework": null, "noBuild": true, "msBuildOutputPath": null, "verbose": true, "workingDirectory": null, "requireParametersWithoutDefault": false, "apiGroupNames": null, "useNuGetCache": false } }, "codeGenerators": { "openApiToCSharpClient": { "clientBaseClass": "", "configurationClass": "", "generateClientClasses": true, "generateClientInterfaces": true, "clientBaseInterface": null, "injectHttpClient": true, "disposeHttpClient": true, "protectedMethods": [], "generateExceptionClasses": true, "exceptionClass": "SwaggerException", "wrapDtoExceptions": true, "useHttpClientCreationMethod": true, "httpClientType": "System.Net.Http.HttpClient", "useHttpRequestMessageCreationMethod": false, "useBaseUrl": false, "generateBaseUrlProperty": true, "generateSyncMethods": true, "generatePrepareRequestAndProcessResponseAsAsyncMethods": 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": "{controller}Client", "operationGenerationMode": "MultipleClientsFromOperationId", "additionalNamespaceUsages": [], "additionalContractNamespaceUsages": [], "generateOptionalParameters": false, "generateJsonMethods": true, "enforceFlagEnums": false, "parameterArrayType": "System.Collections.Generic.IEnumerable", "parameterDictionaryType": "System.Collections.Generic.IDictionary", "responseArrayType": "System.Collections.Generic.List", "responseDictionaryType": "System.Collections.Generic.Dictionary", "wrapResponses": false, "wrapResponseMethods": [], "generateResponseClasses": true, "responseClass": "SwaggerResponse", "namespace": "AppService.Clients", "requiredPropertiesMustBeDefined": true, "dateType": "System.DateTime", "jsonConverters": null, "anyType": "object", "dateTimeType": "System.DateTime", "timeType": "System.TimeSpan", "timeSpanType": "System.TimeSpan", "arrayType": "System.Collections.Generic.List", "arrayInstanceType": null, "dictionaryType": "System.Collections.Generic.Dictionary", "dictionaryInstanceType": null, "arrayBaseType": "System.Collections.Generic.List", "dictionaryBaseType": "System.Collections.Generic.Dictionary", "classStyle": "Inpc", "jsonLibrary": "NewtonsoftJson", "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, "generateNullableReferenceTypes": false, "templateDirectory": null, "typeNameGeneratorType": null, "propertyNameGeneratorType": null, "enumNameGeneratorType": null, "serviceHost": null, "serviceSchemes": null, "output": "../AppServices.Clients/GeneratedClients.cs", "newLineBehavior": "Auto", "validateEnums": false, "generateEnums": false } } } [/code] Но при выполнении приведенной ниже команды приложение запускается. [code][/code] и создайте приведенный ниже журнал: [code]10>NSwag command line tool for .NET Core Net80, toolchain v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0)) 10>Visit http://NSwag.org for more information. 10>NSwag bin directory: C:\.....\packages\nswag.msbuild\14.0.7\tools\Net80 10> 10>Executing file 'NSwag.json' with variables 'Configuration=Release,OutDir=bin\Release\net8.0\,HomeDir=C:\Users\MA0021'... 10>Launcher directory: C:\Users\MA0021\.nuget\packages\nswag.msbuild\14.0.7\tools\Net80 10>init main 10>Configuring to Use DbConfigurationSource. 10>info: DbConfigurationProvider[0] 10> DbConfigurationProvider - Static Logger Configured 10>info: WebHostBootstrapper[0] 10> WebHostBootstrapper - Static Logger Configured 10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[3] 10> Hosting starting 10>dbug: Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory[12] 10> Registered model binder providers, in the following order: Microsoft.AspNetCore.Mvc.ModelBinding....... 10>dbug: Microsoft.AspNetCore.Mvc.Razor.Compilation.DefaultViewCompiler[4] 10> Initializing Razor view compiler with no compiled views. 10>info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63] 10> User profile is available. Using 'C:\Users\MA0021\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. 10>dbug: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[37] 10> Reading data from file 'C:\Users\MA0021\AppData\Local\ASP.NET\DataProtection-Keys\key-8b371780-fd9d-496b-bb67-2db2152258dc.xml'. ................ 10>dbug: Microsoft.AspNetCore.DataProtection.Internal.DataProtectionHostedService[65] 10> Key ring with default key {8b371780-fd9d-496b-bb67-2db2152258dc} was loaded during application startup. 10>dbug: Microsoft.AspNetCore.Server.Kestrel[0] 10> No listening endpoints were configured. Binding to http://localhost:5000 by default. 10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[4] 10> Hosting started 10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[13] 10> Loaded hosting startup assembly AppServices 10>Hosting environment: Production 10>Content root path: C:\xxxxProj\AppServices 10>Now listening on: http://localhost:5000 10>Application started. Press Ctrl+C to shut down. 10>info: DbConfigurationProvider[0] 10> DbConfigurationProvider - Static Logger Configured 10>info: WebHostBootstrapper[0] 10> WebHostBootstrapper - Static Logger Configured 10>trce: DbConfigurationProvider[0] 10> OnReloadTimerElapsed Triggered 10>Application is shutting down... 10>dbug: Microsoft.AspNetCore.Hosting.Diagnostics[5] 10> Hosting shutdown 10>Done. 10> 10>Duration: 00:00:34.7767604 10>Done building project "AppServices.csproj". [/code] Пытался добавить приведенные ниже параметры в nswag, но приложение все равно запускается. [code] "validateEnums": false, "generateEnums": false,[/code] Чего-нибудь не хватает? Подробнее здесь: [url]https://stackoverflow.com/questions/78457756/nswag-start-the-net-8-api-project-in-command-nswagexe-net80-run-nswag-json[/url]