RicoSuter / NSwag

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

Generate client that does not compile #4396

Open nicomartinezsage opened 1 year ago

nicomartinezsage commented 1 year ago

We are using NSwag version 13.18.2 to generate a client for the CloudFlare api. The command used is

openapi2csclient /input:"https://raw.githubusercontent.com/cloudflare/api-schemas/main/openapi.json" /namespace:SampleNameSpace.Client.DecoratedProxy /output:"C:/.automation/nswag/Proxy.generated.cs" /clientClassAccessModifier:internal /typeAccessModifier:public  /generateOptionalPropertiesAsNullable:true /generateNullableReferenceTypes:true

but the generated code cannot be compiled,

it generates methods like;

        /// <summary>
        /// Create Secondary Zone Configuration
        /// </summary>
        /// <remarks>
        /// Create secondary zone configuration for incoming zone transfers.
        /// </remarks>
        /// <returns>Create Secondary Zone Configuration response</returns>
        /// <exception cref="ApiException">A server side error occurred.</exception>
        public virtual System.Threading.Tasks.Task<Single_response_incoming> SecondaryDns(SecondaryZone)CreateSecondaryZoneConfigurationAsync(IdentifierKjRn97d3 zone_identifier, DnsSecondarySecondaryZone body)
        {
            return SecondaryDns(SecondaryZone)CreateSecondaryZoneConfigurationAsync(zone_identifier, body, System.Threading.CancellationToken.None);
        }

methodname with (

pbolduc commented 1 year ago

The reason this occurs is because CloudFlare has those characters in the operationId,

"operationId":"secondary-dns-(-secondary-zone)-create-secondary-zone-configuration"

The OpenAPI spec just says the operationId must be unique but does not constrain the valid characters. NSwag must not of expected these extra characters. I guess the function that converts from operationId to a method should take this into account.