RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.73k stars 1.29k forks source link

after Update to 14.x - How to get Enums generated again, like in 13.x Version? #4781

Closed mbarmettler closed 7 months ago

mbarmettler commented 7 months ago

Hi all,

i'm facing an issue with generating from c# Enum structures like this: export enum ChronoUserPersonalRights { NoRights = 0, ReadWrite = 1, ReadOnly = 2, }

since i updatet to .net 8 and had to update the nswag package to 14.x, im now getting the Enums wrongly generated like this: export enum ChronoUserPersonalRights { _0 = 0, _1 = 1, _2 = 2, }

with version 13.x from nswag i used the .NET Assembly Reflection to generate the needed models. Now i'm forced to use From Swagger Specification in Nswag Studio Tool.

what do i have to do, in order to get the codes generated like before?

here is my nswag.config: "runtime": "Net80", "defaultVariables": null, "documentGenerator": { "fromDocument": ..... } "codeGenerators": { "openApiToTypeScriptClient": { "className": "{controller}Client", "moduleName": "", "namespace": "", "typeScriptVersion": 2.7, "template": "Angular", "promiseType": "Promise", "httpClass": "HttpClient", "withCredentials": false, "useSingletonProvider": false, "injectionTokenType": "OpaqueToken", "rxJsVersion": 6.0, "dateTimeType": "String", "nullValue": "Undefined", "generateClientClasses": false, "generateClientInterfaces": false, "generateOptionalParameters": false, "exportTypes": true, "wrapDtoExceptions": false, "exceptionClass": "ApiException", "clientBaseClass": null, "wrapResponses": false, "wrapResponseMethods": [], "generateResponseClasses": true, "responseClass": "SwaggerResponse", "protectedMethods": [], "configurationClass": null, "useTransformOptionsMethod": false, "useTransformResultMethod": false, "generateDtoTypes": true, "operationGenerationMode": "MultipleClientsFromOperationId", "markOptionalProperties": true, "generateCloneMethod": false, "typeStyle": "Interface", "enumStyle": "Enum", "useLeafType": false, "classTypes": [], "extendedClasses": [], "extensionCode": null, "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": null, "typeNameGeneratorType": null, "propertyNameGeneratorType": null, "enumNameGeneratorType": null, "serviceHost": null, "serviceSchemes": null, "output": "../../webappbadge/src/app/core/models/client-models.ts", "newLineBehavior": "Auto" } } }

mbarmettler commented 7 months ago

after insertinng this in startup.cs: services.AddControllersWithViews().AddJsonOptions(o => o.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()) );

i get the enums differently - but the index numbers are missing: export enum ChronoUserRightsEnum { Firma = "Firma", Department = "Department", Person = "Person", Filiale = "Filiale", Group = "Group", Hierarchical = "Hierarchical", }

think its something small - but what?

thanks for any help

mbarmettler commented 7 months ago

enum issue solved by this: https://github.com/RicoSuter/NSwag/issues/1234