Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# CS1061 error generated because of Type naming collision. #3233

Closed
HowardvanRooijen opened this issue Aug 31, 2023 · 3 comments · Fixed by #3239
Closed

C# CS1061 error generated because of Type naming collision. #3233

HowardvanRooijen opened this issue Aug 31, 2023 · 3 comments · Fixed by #3239
Assignees
Labels
Csharp Pull requests that update .net code type:bug A broken experience WIP
Milestone

Comments

@HowardvanRooijen
Copy link

With Kiota v 1.6.0-preview.202308240001+e0fde4dcaca551c21c52a699c4ffdf5b1bc5b5b1

Using the following command:

kiota generate -l CSharp -c FirecrackerManagementClient -n Firecracker.Management -d https://raw.githubusercontent.com/firecracker-microvm/firecracker/main/src/api_server/swagger/firecracker.yaml -o "c:\temp\firecracker\client"

Which requires the following packages to compile:

dotnet add package Microsoft.Kiota.Abstractions --version 1.3.1
dotnet add package Microsoft.Kiota.Http.HttpClientLibrary --version 1.1.0
dotnet add package Microsoft.Kiota.Serialization.Form --version 1.0.1
dotnet add package Microsoft.Kiota.Serialization.Json --version 1.0.8
dotnet add package Microsoft.Kiota.Authentication.Azure --version 1.0.3
dotnet add package Microsoft.Kiota.Serialization.Text --version 1.0.3
dotnet add package Microsoft.Kiota.Serialization.Multipart --version 1.0.0

The following enum is generated:

// <auto-generated/>
using System.Runtime.Serialization;
using System;
namespace Firecracker.Management.Models {
    /// <summary>The CPU Template defines a set of flags to be disabled from the microvm so that the features exposed to the guest are the same as in the selected instance type.</summary>
    public enum CpuTemplate {
        [EnumMember(Value = "C3")]
        C3,
        [EnumMember(Value = "T2")]
        T2,
        [EnumMember(Value = "T2S")]
        T2S,
        [EnumMember(Value = "T2CL")]
        T2CL,
        [EnumMember(Value = "T2A")]
        T2A,
        [EnumMember(Value = "V1N1")]
        V1N1,
        [EnumMember(Value = "None")]
        None,
    }
}

But a CS1061 compiler error is generated for the following line in the constructor:

            CpuTemplate = CpuTemplate.None;

in the class:

// <auto-generated/>
using Microsoft.Kiota.Abstractions.Serialization;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
namespace Firecracker.Management.Models {
    /// <summary>
    /// Describes the number of vCPUs, memory size, SMT capabilities and the CPU template.
    /// </summary>
    public class MachineConfiguration : IAdditionalDataHolder, IParsable {
        /// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary>
        public IDictionary<string, object> AdditionalData { get; set; }
        /// <summary>The CPU Template defines a set of flags to be disabled from the microvm so that the features exposed to the guest are the same as in the selected instance type.</summary>
        public Firecracker.Management.Models.CpuTemplate? CpuTemplate { get; set; }
        /// <summary>Memory size of VM</summary>
        public int? MemSizeMib { get; set; }
        /// <summary>Flag for enabling/disabling simultaneous multithreading. Can be enabled only on x86.</summary>
        public bool? Smt { get; set; }
        /// <summary>Enable dirty page tracking. If this is enabled, then incremental guest memory snapshots can be created. These belong to diff snapshots, which contain, besides the microVM state, only the memory dirtied since a previous snapshot. Full snapshots each contain a full copy of the guest memory.</summary>
        public bool? TrackDirtyPages { get; set; }
        /// <summary>Number of vCPUs (either 1 or an even number)</summary>
        public int? VcpuCount { get; set; }
        /// <summary>
        /// Instantiates a new MachineConfiguration and sets the default values.
        /// </summary>
        public MachineConfiguration() {
            AdditionalData = new Dictionary<string, object>();
            CpuTemplate = CpuTemplate.None;
        }
        /// <summary>
        /// Creates a new instance of the appropriate class based on discriminator value
        /// </summary>
        /// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
        public static MachineConfiguration CreateFromDiscriminatorValue(IParseNode parseNode) {
            _ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
            return new MachineConfiguration();
        }
        /// <summary>
        /// The deserialization information for the current model
        /// </summary>
        public IDictionary<string, Action<IParseNode>> GetFieldDeserializers() {
            return new Dictionary<string, Action<IParseNode>> {
                {"cpu_template", n => { CpuTemplate = n.GetEnumValue<CpuTemplate>(); } },
                {"mem_size_mib", n => { MemSizeMib = n.GetIntValue(); } },
                {"smt", n => { Smt = n.GetBoolValue(); } },
                {"track_dirty_pages", n => { TrackDirtyPages = n.GetBoolValue(); } },
                {"vcpu_count", n => { VcpuCount = n.GetIntValue(); } },
            };
        }
        /// <summary>
        /// Serializes information the current object
        /// </summary>
        /// <param name="writer">Serialization writer to use to serialize this model</param>
        public void Serialize(ISerializationWriter writer) {
            _ = writer ?? throw new ArgumentNullException(nameof(writer));
            writer.WriteEnumValue<CpuTemplate>("cpu_template", CpuTemplate);
            writer.WriteIntValue("mem_size_mib", MemSizeMib);
            writer.WriteBoolValue("smt", Smt);
            writer.WriteBoolValue("track_dirty_pages", TrackDirtyPages);
            writer.WriteIntValue("vcpu_count", VcpuCount);
            writer.WriteAdditionalData(AdditionalData);
        }
    }
}

Because there is a naming collision between Firecracker.Management.Models.CpuTemplate and Firecracker.Management.Models.MachineConfiguration.CpuTemplate

The generated code in the constructor should be:

CpuTemplate = Firecracker.Management.Models.CpuTemplate.None;

Or equivalent type alias.

@baywet baywet added type:bug A broken experience Csharp Pull requests that update .net code labels Aug 31, 2023
@baywet baywet added this to Kiota Aug 31, 2023
@github-project-automation github-project-automation bot moved this to Todo in Kiota Aug 31, 2023
@baywet baywet added this to the Kiota v1.6 milestone Aug 31, 2023
@baywet
Copy link
Member

baywet commented Aug 31, 2023

Thanks for reporting this. @andrueastman to fully qualify enums in default values using the same rationale as properties.
(or you if you feel like submitting a PR)

defaultValue = $"{enumDefinition.Name.ToFirstCharacterUpperCase()}.{defaultValue.Trim('"').CleanupSymbolName().ToFirstCharacterUpperCase()}";

var propertyType = conventions.GetTypeString(codeElement.Type, codeElement);

@baywet
Copy link
Member

baywet commented Aug 31, 2023

@sebastienlevert we already PRd and just released that, any reason you re-open?

@baywet baywet closed this as completed Aug 31, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Kiota Aug 31, 2023
@sebastienlevert
Copy link
Contributor

I honestly have no clue. I guess I clicked sowhere I shouldn't 🙄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code type:bug A broken experience WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants