Skip to content

Collision on enum: The type or namespace 'Date' could not be found #6286

Open
@scott-the-programmer

Description

@scott-the-programmer

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

Hello!

I am trying to generate a C# SDK for a schema that has a "date" property that can be either "date" or an enum representing "now"

However, the spec produces a compile error as neither the enum (DateEnum) or Microsoft.Kiota.Abstractions is referenced

Expected behavior

In this case, perhaps a warning should be produced for the invalid union of an enum and a date, but at the very least Microsoft.Kiota.Abstractions should be imported so that the SDK builds and is usable

How to reproduce

Generate the SDK from the following spec

openapi: 3.0.0
info:
  title: Profile Operations API
  version: 1.0.0
  description: API for managing profile date operations

components:
  schemas:
    DateEnum:
      type: string
      enum:
        - date
    
    ProfileOperationUpdateOrCreateDate:
      type: object
      properties:
        operator:
          description: The type of operation to perform on a profile property.
          type: string
          enum:
            - create
            - update
        property_type:
          $ref: '#/components/schemas/DateEnum'
        property_key:
          type: string
        property_value:
          oneOf:
            - type: string
              format: date
            - enum:
                - today
      required:
        - operator
        - property_type
        - property_key
        - property_value

paths:
  /profile/date-operations:
    post:
      summary: Create or update profile date properties
      description: Endpoint to create or update date-based profile properties
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProfileOperationUpdateOrCreateDate'
      responses:
        '200':
          description: Operation successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
        '400':
          description: Invalid request
        '500':
          description: Server error

Observe a build error The type or namespace name 'Date' could not be found (are you missing a using directive or an assembly reference?)

// <auto-generated/>
#pragma warning disable CS0618
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions.Serialization;
using System.Collections.Generic;
using System.IO;
using System;
namespace KiotaTest.Models
{
    [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
    #pragma warning disable CS1591
    public partial class ProfileOperationUpdateOrCreateDate : IAdditionalDataHolder, IParsable
    #pragma warning restore CS1591
    {
        /// <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 type of operation to perform on a profile property.</summary>
        public global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_operator? Operator { get; set; }
        /// <summary>The property_key property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
        public string? PropertyKey { get; set; }
#nullable restore
#else
        public string PropertyKey { get; set; }
#endif
        /// <summary>The property_type property</summary>
        public global::KiotaTest.Models.DateEnum? PropertyType { get; set; }
        /// <summary>The property_value property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
        public global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value? PropertyValue { get; set; }
#nullable restore
#else
        public global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value PropertyValue { get; set; }
#endif
        /// <summary>
        /// Instantiates a new <see cref="global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate"/> and sets the default values.
        /// </summary>
        public ProfileOperationUpdateOrCreateDate()
        {
            AdditionalData = new Dictionary<string, object>();
        }
        /// <summary>
        /// Creates a new instance of the appropriate class based on discriminator value
        /// </summary>
        /// <returns>A <see cref="global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate"/></returns>
        /// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
        public static global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate CreateFromDiscriminatorValue(IParseNode parseNode)
        {
            _ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
            return new global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate();
        }
        /// <summary>
        /// The deserialization information for the current model
        /// </summary>
        /// <returns>A IDictionary&lt;string, Action&lt;IParseNode&gt;&gt;</returns>
        public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
        {
            return new Dictionary<string, Action<IParseNode>>
            {
                { "operator", n => { Operator = n.GetEnumValue<global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_operator>(); } },
                { "property_key", n => { PropertyKey = n.GetStringValue(); } },
                { "property_type", n => { PropertyType = n.GetEnumValue<global::KiotaTest.Models.DateEnum>(); } },
                { "property_value", n => { PropertyValue = n.GetObjectValue<global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value>(global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value.CreateFromDiscriminatorValue); } },
            };
        }
        /// <summary>
        /// Serializes information the current object
        /// </summary>
        /// <param name="writer">Serialization writer to use to serialize this model</param>
        public virtual void Serialize(ISerializationWriter writer)
        {
            _ = writer ?? throw new ArgumentNullException(nameof(writer));
            writer.WriteEnumValue<global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_operator>("operator", Operator);
            writer.WriteStringValue("property_key", PropertyKey);
            writer.WriteEnumValue<global::KiotaTest.Models.DateEnum>("property_type", PropertyType);
            writer.WriteObjectValue<global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value>("property_value", PropertyValue);
            writer.WriteAdditionalData(AdditionalData);
        }
        /// <summary>
        /// Composed type wrapper for classes <see cref="Date"/>, <see cref="global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_property_valueMember1"/>
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")]
        public partial class ProfileOperationUpdateOrCreateDate_property_value : IComposedTypeWrapper, IParsable
        {
            /// <summary>Composed type representation for type <see cref="Date"/></summary>
            public DateEnum? DateOnly { get; set; }
            /// <summary>Composed type representation for type <see cref="global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_property_valueMember1"/></summary>
            public global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_property_valueMember1? ProfileOperationUpdateOrCreateDatePropertyValueMember1 { get; set; }
            /// <summary>
            /// Creates a new instance of the appropriate class based on discriminator value
            /// </summary>
            /// <returns>A <see cref="global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value"/></returns>
            /// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
            public static global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value CreateFromDiscriminatorValue(IParseNode parseNode)
            {
                _ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
                var mappingValue = parseNode.GetChildNode("")?.GetStringValue();
                var result = new global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate.ProfileOperationUpdateOrCreateDate_property_value();
                if(parseNode.GetEnumValue<global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_property_valueMember1>() is global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_property_valueMember1 profileOperationUpdateOrCreateDatePropertyValueMember1Value)
                {
                    result.ProfileOperationUpdateOrCreateDatePropertyValueMember1 = profileOperationUpdateOrCreateDatePropertyValueMember1Value;
                }
                else if(parseNode.GetDateValue() is Date dateOnlyValue)
                {
                    result.DateOnly = dateOnlyValue;
                }
                return result;
            }
            /// <summary>
            /// The deserialization information for the current model
            /// </summary>
            /// <returns>A IDictionary&lt;string, Action&lt;IParseNode&gt;&gt;</returns>
            public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
            {
                return new Dictionary<string, Action<IParseNode>>();
            }
            /// <summary>
            /// Serializes information the current object
            /// </summary>
            /// <param name="writer">Serialization writer to use to serialize this model</param>
            public virtual void Serialize(ISerializationWriter writer)
            {
                _ = writer ?? throw new ArgumentNullException(nameof(writer));
                if(ProfileOperationUpdateOrCreateDatePropertyValueMember1 != null)
                {
                    writer.WriteEnumValue<global::KiotaTest.Models.ProfileOperationUpdateOrCreateDate_property_valueMember1>(null, ProfileOperationUpdateOrCreateDatePropertyValueMember1);
                }
                else if(DateOnly != null)
                {
                    writer.WriteDateValue(null, DateOnly);
                }
            }
        }
    }
}
#pragma warning restore CS0618

Open API description file

No response

Kiota Version

1.23.0+e148ba500009faf72a57883f905e1ca922add0e2

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

Adding the Microsoft.Kiota.Abstractions import will manually resolve the issue

Configuration

All OSes as far as I can tell, but i've tested it on the following

  • OS: Windows, OSX, Ubuntu 22.04
  • Arch: x64, ARM64

Debug output

Click to expand log ```
</details>


### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    CsharpPull requests that update .net codeWIPtype:bugA broken experience

    Type

    No type

    Projects

    Status

    In Progress 🚧

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions