NSwag command line to generate cs client issue #4937
Unanswered
peterhoang
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to generate the C# client files after the build of my solution so I have the following in my main csproj file:
And the nswag.json:
{ "runtime": "Net80", "defaultVariables": "GeneratedFilesOutputPath=..\\Client", "documentGenerator": { "aspNetCoreToOpenApi": { "project": "Web.Api.csproj", "msBuildProjectExtensionsPath": null, "runtime": "", "targetFramework": "", "noBuild": true, "verbose": true, "workingDirectory": null, "requireParametersWithoutDefault": true, "apiGroupNames": null, "defaultPropertyNameHandling": "CamelCase", "defaultReferenceTypeNullHandling": "Null", "defaultDictionaryValueReferenceTypeNullHandling": "NotNull", "defaultResponseReferenceTypeNullHandling": "NotNull", "defaultEnumHandling": "Integer", "flattenInheritanceHierarchy": false, "generateKnownTypes": true, "generateEnumMappingDescription": false, "generateXmlObjects": false, "generateAbstractProperties": true, "generateAbstractSchemas": true, "ignoreObsoleteProperties": false, "allowReferencesWithProperties": false, "excludedTypeNames": [], "serviceHost": null, "serviceBasePath": null, "serviceSchemes": [], "infoTitle": null, "infoDescription": null, "infoVersion": "1.0.0", "documentTemplate": null, "documentProcessorTypes": [], "operationProcessorTypes": [], "typeNameGeneratorType": null, "schemaNameGeneratorType": null, "contractResolverType": null, "serializerSettingsType": null, "useDocumentProvider": false, "documentName": "v1", "aspNetCoreEnvironment": null, "createWebHostBuilderMethod": null, "startupType": null, "allowNullableBodyParameters": true, "output": null, "outputType": "OpenApi3", "newLineBehavior": "Auto", "assemblyPaths": [], "assemblyConfig": null, "referencePaths": [], "useNuGetCache": false } }, "codeGenerators": { "openApiToCSharpClient": { "clientBaseClass": null, "configurationClass": null, "generateClientClasses": true, "suppressClientClassesOutput": false, "generateClientInterfaces": true, "suppressClientInterfacesOutput": false, "clientBaseInterface": null, "injectHttpClient": true, "disposeHttpClient": true, "protectedMethods": [], "generateExceptionClasses": true, "exceptionClass": "SwaggerException", "wrapDtoExceptions": true, "useHttpClientCreationMethod": false, "httpClientType": "System.Net.Http.HttpClient", "useHttpRequestMessageCreationMethod": false, "useBaseUrl": true, "generateBaseUrlProperty": true, "generateSyncMethods": false, "generatePrepareRequestAndProcessResponseAsAsyncMethods": false, "exposeJsonSerializerSettings": false, "clientClassAccessModifier": "public", "typeAccessModifier": "public", "propertySetterAccessModifier": "", "generateNativeRecords": false, "generateContractsOutput": true, "contractsNamespace": "Client", "contractsOutputFilePath": "$(GeneratedFilesOutputPath)/Contracts.g.cs", "parameterDateTimeFormat": "s", "parameterDateFormat": "yyyy-MM-dd", "generateUpdateJsonSerializerSettingsMethod": true, "useRequestAndResponseSerializationSettings": false, "serializeTypeInformation": true, "queryNullValue": "", "className": "{controller}Client", "operationGenerationMode": "SingleClientFromOperationId", "additionalNamespaceUsages": [], "additionalContractNamespaceUsages": [], "generateOptionalParameters": false, "generateJsonMethods": true, "enforceFlagEnums": false, "parameterArrayType": "System.Collections.Generic.List", "parameterDictionaryType": "System.Collections.Generic.Dictionary", "responseArrayType": "System.Collections.Generic.List", "responseDictionaryType": "System.Collections.Generic.Dictionary", "wrapResponses": false, "wrapResponseMethods": [], "generateResponseClasses": true, "responseClass": "ClientResponse", "namespace": "Client", "requiredPropertiesMustBeDefined": true, "dateType": "System.DateTime", "jsonConverters": null, "anyType": "object", "dateTimeType": "System.DateTime", "timeType": "System.TimeSpan", "timeSpanType": "System.TimeSpan", "arrayType": "System.Collections.Generic.IList", "arrayInstanceType": "System.Collections.Generic.List", "dictionaryType": "System.Collections.Generic.IDictionary", "dictionaryInstanceType": "System.Collections.Generic.Dictionary", "arrayBaseType": "System.Collections.Generic.List", "dictionaryBaseType": "System.Collections.Generic.Dictionary", "classStyle": "Poco", "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, "serviceHost": null, "serviceSchemes": null, "output": "$(GeneratedFilesOutputPath)/Client.g.cs", "newLineBehavior": "Auto" } } }I will get a building error about an exception of a missing config (section) in my appsettings. This is by design as I have guards that throw exceptions when an expected configuration is missing in the appsettings.
Before this post build step, the dotnet web API builds and runs fine.
What am I missing or is the Nswag command line not an option for my situation (which I doubt because loading settings from appsettings is a common practice in the dotnet world)?
Beta Was this translation helpful? Give feedback.
All reactions