-
Notifications
You must be signed in to change notification settings - Fork 334
Open
Labels
bugSomething isn't workingSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharpIssue for the C# client emitter: @typespec/http-client-csharp
Description
Describe the bug
Pre-existing public constructors should not be missing from the generated code. This should be another Back Compat scenario. See Backward Compatibility Support for more details.
Generating Azure.Search.Documents have the issue where a public constructor is missing, for instance, this is what the previously generated code from autorest looks like:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System;
using System.Collections.Generic;
namespace Azure.Search.Documents.Indexes.Models
{
/// <summary>
/// Abstract base type for data identities.
/// Please note <see cref="SearchIndexerDataIdentity"/> is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
/// The available derived classes include <see cref="SearchIndexerDataNoneIdentity"/> and <see cref="SearchIndexerDataUserAssignedIdentity"/>.
/// </summary>
public abstract partial class SearchIndexerDataIdentity
{
/// <summary>
/// Keeps track of any properties unknown to the library.
/// <para>
/// To assign an object to the value of this property use <see cref="BinaryData.FromObjectAsJson{T}(T, System.Text.Json.JsonSerializerOptions?)"/>.
/// </para>
/// <para>
/// To assign an already formatted json string to this property use <see cref="BinaryData.FromString(string)"/>.
/// </para>
/// <para>
/// Examples:
/// <list type="bullet">
/// <item>
/// <term>BinaryData.FromObjectAsJson("foo")</term>
/// <description>Creates a payload of "foo".</description>
/// </item>
/// <item>
/// <term>BinaryData.FromString("\"foo\"")</term>
/// <description>Creates a payload of "foo".</description>
/// </item>
/// <item>
/// <term>BinaryData.FromObjectAsJson(new { key = "value" })</term>
/// <description>Creates a payload of { "key": "value" }.</description>
/// </item>
/// <item>
/// <term>BinaryData.FromString("{\"key\": \"value\"}")</term>
/// <description>Creates a payload of { "key": "value" }.</description>
/// </item>
/// </list>
/// </para>
/// </summary>
private protected IDictionary<string, BinaryData> _serializedAdditionalRawData;
/// <summary> Initializes a new instance of <see cref="SearchIndexerDataIdentity"/>. </summary>
public SearchIndexerDataIdentity()
{
}
/// <summary> Initializes a new instance of <see cref="SearchIndexerDataIdentity"/>. </summary>
/// <param name="oDataType"> A URI fragment specifying the type of identity. </param>
/// <param name="serializedAdditionalRawData"> Keeps track of any properties unknown to the library. </param>
internal SearchIndexerDataIdentity(string oDataType, IDictionary<string, BinaryData> serializedAdditionalRawData)
{
ODataType = oDataType;
_serializedAdditionalRawData = serializedAdditionalRawData;
}
/// <summary> A URI fragment specifying the type of identity. </summary>
internal string ODataType { get; set; }
}
}and the new generated model looks like:
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System;
using System.Collections.Generic;
namespace Azure.Search.Documents.Models
{
/// <summary>
/// Abstract base type for data identities.
/// Please note this is the abstract base class. The derived classes available for instantiation are: <see cref="SearchIndexerDataNoneIdentity"/> and <see cref="SearchIndexerDataUserAssignedIdentity"/>.
/// </summary>
public abstract partial class SearchIndexerDataIdentity
{
/// <summary> Keeps track of any properties unknown to the library. </summary>
private protected readonly IDictionary<string, BinaryData> _additionalBinaryDataProperties;
/// <summary> Initializes a new instance of <see cref="SearchIndexerDataIdentity"/>. </summary>
/// <param name="odataType"> A URI fragment specifying the type of identity. </param>
private protected SearchIndexerDataIdentity(string odataType)
{
OdataType = odataType;
}
/// <summary> Initializes a new instance of <see cref="SearchIndexerDataIdentity"/>. </summary>
/// <param name="odataType"> A URI fragment specifying the type of identity. </param>
/// <param name="additionalBinaryDataProperties"> Keeps track of any properties unknown to the library. </param>
internal SearchIndexerDataIdentity(string odataType, IDictionary<string, BinaryData> additionalBinaryDataProperties)
{
OdataType = odataType;
_additionalBinaryDataProperties = additionalBinaryDataProperties;
}
/// <summary> A URI fragment specifying the type of identity. </summary>
internal string OdataType { get; set; }
}
}Note that public SearchIndexerDataIdentity() is missing.
We should include an scenario for back-compat where if a public constructor is missing then it gets generated, in order to avoid extra customizations and breaking changes.
Reproduction
Regenerate an existing autorest-based SDK with the new emitter, like Azure.Search.Documents
Checklist
- Follow our Code of Conduct
- Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
Copilot
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharpIssue for the C# client emitter: @typespec/http-client-csharp