Generate constructors for Model types (#3332)

This PR generates constructors for model types. 

Fixes: https://github.com/Azure/autorest.csharp/issues/4474

---------

Co-authored-by: ShivangiReja <shivangi.reja@microsoft.com>
This commit is contained in:
ShivangiReja 2024-05-14 10:46:10 -07:00 коммит произвёл GitHub
Родитель b477dc35a3
Коммит 30f66f04a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
16 изменённых файлов: 695 добавлений и 13 удалений

Просмотреть файл

@ -261,12 +261,16 @@ namespace Microsoft.Generator.CSharp
if (IsList)
{
return new CSharpType(CodeModelPlugin.Instance.Configuration.ApiTypes.ChangeTrackingListType, Arguments);
return new CSharpType(typeof(List<>), Arguments);
// Generate ChangeTrackingList type - https://github.com/microsoft/typespec/issues/3324
// return new CSharpType(CodeModelPlugin.Instance.Configuration.ApiTypes.ChangeTrackingListType, Arguments);
}
if (IsDictionary)
{
return new CSharpType(CodeModelPlugin.Instance.Configuration.ApiTypes.ChangeTrackingDictionaryType, Arguments);
return new CSharpType(typeof(Dictionary<,>), Arguments);
// Generate ChangeTrackingDictionary type - https://github.com/microsoft/typespec/issues/3324
//return new CSharpType(CodeModelPlugin.Instance.Configuration.ApiTypes.ChangeTrackingDictionaryType, Arguments);
}
}

Просмотреть файл

@ -15,6 +15,7 @@ namespace Microsoft.Generator.CSharp
internal const string ConvenienceValue = "Convenience";
internal const string ProtocolValue = "Protocol";
internal const string CreateMessageValue = "CreateMessage";
internal const string ConstructorValue = "Constructor";
private readonly string _value;
@ -41,6 +42,11 @@ namespace Microsoft.Generator.CSharp
/// </summary>
public static CSharpMethodKinds CreateMessage { get; } = new CSharpMethodKinds(CreateMessageValue);
/// <summary>
/// Constructor method kind.
/// </summary>
public static CSharpMethodKinds Constructor { get; } = new CSharpMethodKinds(ConstructorValue);
/// <summary> Determines if two <see cref="CSharpMethodKinds"/> values are the same. </summary>
public static bool operator ==(CSharpMethodKinds left, CSharpMethodKinds right) => left.Equals(right);
/// <summary> Determines if two <see cref="CSharpMethodKinds"/> values are not the same. </summary>

Просмотреть файл

@ -121,5 +121,201 @@ namespace Microsoft.Generator.CSharp
return null;
}
protected override CSharpMethod[] BuildConstructors()
{
List<CSharpMethod> constructors = new List<CSharpMethod>();
var initializationConstructor = BuildInitializationConstructor();
if (initializationConstructor != null)
{
constructors.Add(initializationConstructor);
}
var serializationConstructor = BuildSerializationConstructor();
bool serializationParametersMatchInitialization = initializationConstructor != null &&
initializationConstructor.Signature.Parameters.SequenceEqual(serializationConstructor.Signature.Parameters, Parameter.EqualityComparerByType);
if (!serializationParametersMatchInitialization)
{
constructors.Add(serializationConstructor);
}
if (initializationConstructor?.Signature.Parameters.Count > 0)
{
var emptyConstructor = BuildEmptyConstructor();
constructors.Add(emptyConstructor);
}
return constructors.ToArray();
}
private IReadOnlyList<Parameter> BuildConstructorParameters(bool isSerializationConstructor)
{
List<Parameter> constructorParameters = new List<Parameter>();
foreach (var property in _inputModel.Properties)
{
CSharpType propertyType = CodeModelPlugin.Instance.TypeFactory.CreateCSharpType(property.Type);
var initializationValue = GetPropertyInitializationValue(property, propertyType);
var parameterValidation = GetParameterValidation(property, propertyType);
var parameter = new Parameter(
Name: property.Name.ToVariableName(),
Description: FormattableStringHelpers.FromString(property.Description),
Type: propertyType,
DefaultValue: null,
Validation: parameterValidation,
Initializer: null);
// All properties should be included in the serialization ctor
if (isSerializationConstructor)
{
constructorParameters.Add(parameter with { Validation = ValidationType.None });
}
else
{
// For classes, only required + not readonly + not initialization value + not discriminator could get into the public ctor
// For structs, all properties must be set in the public ctor
if (IsStruct || (property is { IsRequired: true, IsDiscriminator: false } && initializationValue == null))
{
if (!property.IsReadOnly)
{
constructorParameters.Add(parameter with { Type = parameter.Type.InputType });
}
}
}
}
return constructorParameters;
}
private static ValidationType GetParameterValidation(InputModelProperty property, CSharpType propertyType)
{
// We do not validate a parameter when it is a value type (struct or int, etc)
if (propertyType.IsValueType)
{
return ValidationType.None;
}
// or it is readonly
if (property.IsReadOnly)
{
return ValidationType.None;
}
// or it is optional
if (!property.IsRequired)
{
return ValidationType.None;
}
// or it is nullable
if (propertyType.IsNullable)
{
return ValidationType.None;
}
return ValidationType.AssertNotNull;
}
private CSharpMethod? BuildInitializationConstructor()
{
if (_inputModel.IsUnknownDiscriminatorModel)
{
return null;
}
var accessibility = DeclarationModifiers.HasFlag(TypeSignatureModifiers.Abstract)
? MethodSignatureModifiers.Protected
: _inputModel.Usage.HasFlag(InputModelTypeUsage.Input)
? MethodSignatureModifiers.Public
: MethodSignatureModifiers.Internal;
var constructorParameters = BuildConstructorParameters(false);
var constructor = new CSharpMethod(
signature: new ConstructorSignature(
Type,
$"Initializes a new instance of {Type:C}",
null,
accessibility,
constructorParameters),
body: new MethodBodyStatement[]
{
new ParameterValidationBlock(constructorParameters),
GetPropertyInitializers(constructorParameters)
},
kind: CSharpMethodKinds.Constructor);
return constructor;
}
private CSharpMethod BuildSerializationConstructor()
{
var constructorParameters = BuildConstructorParameters(true);
return new CSharpMethod(
signature: new ConstructorSignature(
Type,
$"Initializes a new instance of {Type:C}",
null,
MethodSignatureModifiers.Internal,
constructorParameters),
body: new MethodBodyStatement[]
{
new ParameterValidationBlock(constructorParameters),
GetPropertyInitializers(constructorParameters)
},
kind: CSharpMethodKinds.Constructor);
}
private MethodBodyStatement GetPropertyInitializers(IReadOnlyList<Parameter> parameters)
{
List<MethodBodyStatement> methodBodyStatements = new();
Dictionary<string, Parameter> parameterMap = parameters.ToDictionary(
parameter => parameter.Name,
parameter => parameter);
foreach (var property in Properties)
{
ValueExpression? initializationValue = null;
if (parameterMap.TryGetValue(property.Name.ToVariableName(), out var parameter) || IsStruct)
{
if (parameter != null)
{
initializationValue = new ParameterReference(parameter);
if (CSharpType.RequiresToList(parameter.Type, property.Type))
{
initializationValue = parameter.Type.IsNullable ?
Linq.ToList(new NullConditionalExpression(initializationValue)) :
Linq.ToList(initializationValue);
}
}
}
else if (initializationValue == null && property.Type.IsCollection)
{
initializationValue = New.Instance(property.Type.PropertyInitializationType);
}
if (initializationValue != null)
{
methodBodyStatements.Add(Assign(new MemberExpression(null, property.Name), initializationValue));
}
}
return methodBodyStatements;
}
private CSharpMethod BuildEmptyConstructor()
{
var accessibility = IsStruct ? MethodSignatureModifiers.Public : MethodSignatureModifiers.Internal;
return new CSharpMethod(
signature: new ConstructorSignature(Type, $"Initializes a new instance of {Type:C} for deserialization.", null, accessibility, Array.Empty<Parameter>()),
body: new MethodBodyStatement(),
kind: CSharpMethodKinds.Constructor);
}
}
}

Просмотреть файл

@ -80,6 +80,11 @@ namespace Microsoft.Generator.CSharp
return nameBuilder.ToString();
}
[return: NotNullIfNotNull(nameof(name))]
public static string ToVariableName(this string name) => ToCleanName(name, isCamelCase: false);
public static GetPathPartsEnumerator GetPathParts(string? path) => new GetPathPartsEnumerator(path);
public ref struct GetPathPartsEnumerator

Просмотреть файл

@ -267,6 +267,40 @@ namespace Microsoft.Generator.CSharp
CodeModelPlugin.Instance.CodeWriterExtensionMethods.WriteMethod(this, method);
}
public CodeWriter WriteMethodDocumentation(MethodSignatureBase methodBase)
{
if (methodBase.IsRawSummaryText)
{
return WriteRawXmlDocumentation(methodBase.Description);
}
if (methodBase.NonDocumentComment is { } comment)
{
WriteLine($"// {comment}");
}
if (methodBase.SummaryText is { } summaryText)
{
WriteXmlDocumentationSummary(summaryText);
}
return WriteMethodDocumentationSignature(methodBase);
}
public CodeWriter WriteMethodDocumentationSignature(MethodSignatureBase methodBase)
{
WriteXmlDocumentationParameters(methodBase.Modifiers.HasFlag(MethodSignatureModifiers.Public) ? methodBase.Parameters : methodBase.Parameters.Where(p => p.Description is not null));
WriteXmlDocumentationRequiredParametersException(methodBase.Parameters);
WriteXmlDocumentationNonEmptyParametersException(methodBase.Parameters);
if (methodBase is MethodSignature { ReturnDescription: { } } method)
{
WriteXmlDocumentationReturns(method.ReturnDescription);
}
return this;
}
public void WriteProperty(PropertyDeclaration property)
{
if (!CurrentLine.IsEmpty)

Просмотреть файл

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
@ -25,6 +25,8 @@ namespace Microsoft.Generator.CSharp
ArgumentNullException.ThrowIfNull(writer, nameof(writer));
ArgumentNullException.ThrowIfNull(method, nameof(method));
writer.WriteMethodDocumentation(method.Signature);
if (method.Body is { } body)
{
using (writer.WriteMethodDeclaration(method.Signature))

Просмотреть файл

@ -68,7 +68,6 @@ namespace Microsoft.Generator.CSharp.Writers
{
WriteFields();
_writer.WriteLine($"// Add Constructors"); // https://github.com/Azure/autorest.csharp/issues/4474
WriteConstructors();
WriteProperties();

Просмотреть файл

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Generator.CSharp.Input;
using Moq;
@ -110,5 +111,84 @@ namespace Microsoft.Generator.CSharp.Tests
true);
}
}
private CSharpType GetCSharpType(InputType type)
{
switch (type)
{
case InputPrimitiveType:
{
var primitiveType = (InputPrimitiveType)type;
if (primitiveType.Kind is InputTypeKind.String)
return new CSharpType(typeof(string));
if (primitiveType.Kind is InputTypeKind.Int32)
return new CSharpType(typeof(int));
throw new ArgumentException("Unsupported input type.");
}
case InputList:
return new CSharpType(typeof(IList<string>));
case InputDictionary:
return new CSharpType(typeof(IDictionary<string, string>));
case InputIntrinsicType:
return new CSharpType(typeof(BinaryData));
default:
throw new ArgumentException("Unsupported input type.");
}
}
[Test]
public void BuildConstructor_ValidateConstructors()
{
var mockPluginInstance = new Mock<CodeModelPlugin>(_generatorContext) { };
var mockTypeFactory = new Mock<TypeFactory>() { };
var properties = new List<InputModelProperty>{
new InputModelProperty("requiredString", "requiredString", "", InputPrimitiveType.String, true, false, false),
new InputModelProperty("OptionalInt", "optionalInt", "", InputPrimitiveType.Int32, false, false, false),
new InputModelProperty("requiredCollection", "requiredCollection", "", new InputList("List", new InputPrimitiveType(InputTypeKind.String, false), false, false), true, false, false),
new InputModelProperty("requiredDictionary", "requiredDictionary", "", new InputDictionary("Dictionary", new InputPrimitiveType(InputTypeKind.String, false), new InputPrimitiveType(InputTypeKind.String, false), false), true, false, false),
new InputModelProperty("optionalUnknown", "optional unknown", "", new InputIntrinsicType(InputIntrinsicTypeKind.Unknown), false, false, false),
};
mockTypeFactory.Setup(t => t.CreateCSharpType(It.IsAny<InputType>())).Returns((InputType inputType) =>
{
// Lookup the inputType in the list and return the corresponding CSharpType
var inputModelProperty = properties.Where(prop => prop.Type.Name == inputType.Name).FirstOrDefault();
if (inputModelProperty != null)
{
return GetCSharpType(inputModelProperty.Type);
}
else
{
throw new ArgumentException("Unsupported input type.");
}
});
mockPluginInstance.SetupGet(p => p.TypeFactory).Returns(mockTypeFactory.Object);
_mockPlugin?.SetValue(null, mockPluginInstance.Object);
var inputModel = new InputModelType("TestModel", "TestModel", "public", null, "Test model.", InputModelTypeUsage.RoundTrip, properties, null, Array.Empty<InputModelType>(), null, null, null, false);
var modelTypeProvider = new ModelTypeProvider(inputModel, null);
var ctors = modelTypeProvider.Constructors;
Assert.IsNotNull(ctors);
Assert.AreEqual(3, ctors.Count);
var initializationCtor = ctors[0];
Assert.AreEqual(MethodSignatureModifiers.Public, initializationCtor.Signature.Modifiers);
Assert.AreEqual(3, initializationCtor.Signature.Parameters.Count);
var serializationCtor = ctors[1];
Assert.AreEqual(MethodSignatureModifiers.Internal, serializationCtor.Signature.Modifiers);
Assert.AreEqual(5, serializationCtor.Signature.Parameters.Count);
var emptyCtor = ctors[2];
Assert.AreEqual(MethodSignatureModifiers.Internal, emptyCtor.Signature.Modifiers);
Assert.AreEqual(0, emptyCtor.Signature.Parameters.Count);
}
}
}

Просмотреть файл

@ -2,11 +2,29 @@
#nullable disable
using System;
namespace UnbrandedTypeSpec.Models
{
public partial class Friend
{
// Add Constructors
/// <summary> Initializes a new instance of <see cref="Friend"/>. </summary>
/// <param name="name"> name of the NotFriend. </param>
/// <exception cref="ArgumentNullException"> <paramref name="name"/> is null. </exception>
public Friend(string name)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
Name = name;
}
/// <summary> Initializes a new instance of <see cref="Friend"/> for deserialization. </summary>
internal Friend()
{
}
/// <summary> name of the NotFriend. </summary>
public string Name { get; set; }

Просмотреть файл

@ -8,7 +8,25 @@ namespace UnbrandedTypeSpec.Models
{
public partial class ModelWithFormat
{
// Add Constructors
/// <summary> Initializes a new instance of <see cref="ModelWithFormat"/>. </summary>
/// <param name="sourceUrl"> url format. </param>
/// <param name="guid"> uuid format. </param>
/// <exception cref="ArgumentNullException"> <paramref name="sourceUrl"/> is null. </exception>
public ModelWithFormat(System.Uri sourceUrl, Guid guid)
{
if (sourceUrl == null)
{
throw new ArgumentNullException(nameof(sourceUrl));
}
SourceUrl = sourceUrl;
Guid = guid;
}
/// <summary> Initializes a new instance of <see cref="ModelWithFormat"/> for deserialization. </summary>
internal ModelWithFormat()
{
}
/// <summary> url format. </summary>
public System.Uri SourceUrl { get; set; }

Просмотреть файл

@ -6,7 +6,21 @@ namespace UnbrandedTypeSpec.Models
{
public partial class ModelWithRequiredNullableProperties
{
// Add Constructors
/// <summary> Initializes a new instance of <see cref="ModelWithRequiredNullableProperties"/>. </summary>
/// <param name="requiredNullablePrimitive"> required nullable primitive type. </param>
/// <param name="requiredExtensibleEnum"> required nullable extensible enum type. </param>
/// <param name="requiredFixedEnum"> required nullable fixed enum type. </param>
public ModelWithRequiredNullableProperties(int? requiredNullablePrimitive, string requiredExtensibleEnum, string requiredFixedEnum)
{
RequiredNullablePrimitive = requiredNullablePrimitive;
RequiredExtensibleEnum = requiredExtensibleEnum;
RequiredFixedEnum = requiredFixedEnum;
}
/// <summary> Initializes a new instance of <see cref="ModelWithRequiredNullableProperties"/> for deserialization. </summary>
internal ModelWithRequiredNullableProperties()
{
}
/// <summary> required nullable primitive type. </summary>
public int? RequiredNullablePrimitive { get; set; }

Просмотреть файл

@ -2,11 +2,29 @@
#nullable disable
using System;
namespace UnbrandedTypeSpec.Models
{
public partial class ProjectedModel
{
// Add Constructors
/// <summary> Initializes a new instance of <see cref="ProjectedModel"/>. </summary>
/// <param name="name"> name of the ModelWithProjectedName. </param>
/// <exception cref="ArgumentNullException"> <paramref name="name"/> is null. </exception>
public ProjectedModel(string name)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
Name = name;
}
/// <summary> Initializes a new instance of <see cref="ProjectedModel"/> for deserialization. </summary>
internal ProjectedModel()
{
}
/// <summary> name of the ModelWithProjectedName. </summary>
public string Name { get; set; }

Просмотреть файл

@ -6,7 +6,10 @@ namespace UnbrandedTypeSpec.Models
{
public partial class ReturnsAnonymousModelResponse
{
// Add Constructors
/// <summary> Initializes a new instance of <see cref="ReturnsAnonymousModelResponse"/>. </summary>
internal ReturnsAnonymousModelResponse()
{
}
// Add Methods

Просмотреть файл

@ -4,12 +4,129 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace UnbrandedTypeSpec.Models
{
public partial class RoundTripModel
{
// Add Constructors
/// <summary> Initializes a new instance of <see cref="RoundTripModel"/>. </summary>
/// <param name="requiredString"> Required string, illustrating a reference type property. </param>
/// <param name="requiredInt"> Required int, illustrating a value type property. </param>
/// <param name="requiredCollection"> Required collection of enums. </param>
/// <param name="requiredDictionary"> Required dictionary of enums. </param>
/// <param name="requiredModel"> Required model. </param>
/// <param name="requiredUnknown"> required unknown. </param>
/// <param name="requiredRecordUnknown"> required record of unknown. </param>
/// <param name="modelWithRequiredNullable"> this is a model with required nullable properties. </param>
/// <param name="requiredBytes"> Required bytes. </param>
/// <exception cref="ArgumentNullException"> <paramref name="requiredString"/>, <paramref name="requiredCollection"/>, <paramref name="requiredDictionary"/>, <paramref name="requiredModel"/>, <paramref name="requiredUnknown"/>, <paramref name="requiredRecordUnknown"/>, <paramref name="modelWithRequiredNullable"/> or <paramref name="requiredBytes"/> is null. </exception>
public RoundTripModel(string requiredString, int requiredInt, IEnumerable<string> requiredCollection, IDictionary<string, string> requiredDictionary, Thing requiredModel, System.BinaryData requiredUnknown, IDictionary<string, System.BinaryData> requiredRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, System.BinaryData requiredBytes)
{
if (requiredString == null)
{
throw new ArgumentNullException(nameof(requiredString));
}
if (requiredCollection == null)
{
throw new ArgumentNullException(nameof(requiredCollection));
}
if (requiredDictionary == null)
{
throw new ArgumentNullException(nameof(requiredDictionary));
}
if (requiredModel == null)
{
throw new ArgumentNullException(nameof(requiredModel));
}
if (requiredUnknown == null)
{
throw new ArgumentNullException(nameof(requiredUnknown));
}
if (requiredRecordUnknown == null)
{
throw new ArgumentNullException(nameof(requiredRecordUnknown));
}
if (modelWithRequiredNullable == null)
{
throw new ArgumentNullException(nameof(modelWithRequiredNullable));
}
if (requiredBytes == null)
{
throw new ArgumentNullException(nameof(requiredBytes));
}
RequiredString = requiredString;
RequiredInt = requiredInt;
RequiredCollection = requiredCollection.ToList();
RequiredDictionary = requiredDictionary;
RequiredModel = requiredModel;
IntExtensibleEnumCollection = new List<int>();
FloatExtensibleEnumCollection = new List<int>();
FloatFixedEnumCollection = new List<float>();
IntFixedEnumCollection = new List<int>();
RequiredUnknown = requiredUnknown;
RequiredRecordUnknown = requiredRecordUnknown;
OptionalRecordUnknown = new Dictionary<string, System.BinaryData>();
ReadOnlyRequiredRecordUnknown = new Dictionary<string, System.BinaryData>();
ReadOnlyOptionalRecordUnknown = new Dictionary<string, System.BinaryData>();
ModelWithRequiredNullable = modelWithRequiredNullable;
RequiredBytes = requiredBytes;
}
/// <summary> Initializes a new instance of <see cref="RoundTripModel"/>. </summary>
/// <param name="requiredString"> Required string, illustrating a reference type property. </param>
/// <param name="requiredInt"> Required int, illustrating a value type property. </param>
/// <param name="requiredCollection"> Required collection of enums. </param>
/// <param name="requiredDictionary"> Required dictionary of enums. </param>
/// <param name="requiredModel"> Required model. </param>
/// <param name="intExtensibleEnum"> this is an int based extensible enum. </param>
/// <param name="intExtensibleEnumCollection"> this is a collection of int based extensible enum. </param>
/// <param name="floatExtensibleEnum"> this is a float based extensible enum. </param>
/// <param name="floatExtensibleEnumCollection"> this is a collection of float based extensible enum. </param>
/// <param name="floatFixedEnum"> this is a float based fixed enum. </param>
/// <param name="floatFixedEnumCollection"> this is a collection of float based fixed enum. </param>
/// <param name="intFixedEnum"> this is a int based fixed enum. </param>
/// <param name="intFixedEnumCollection"> this is a collection of int based fixed enum. </param>
/// <param name="stringFixedEnum"> this is a string based fixed enum. </param>
/// <param name="requiredUnknown"> required unknown. </param>
/// <param name="optionalUnknown"> optional unknown. </param>
/// <param name="requiredRecordUnknown"> required record of unknown. </param>
/// <param name="optionalRecordUnknown"> optional record of unknown. </param>
/// <param name="readOnlyRequiredRecordUnknown"> required readonly record of unknown. </param>
/// <param name="readOnlyOptionalRecordUnknown"> optional readonly record of unknown. </param>
/// <param name="modelWithRequiredNullable"> this is a model with required nullable properties. </param>
/// <param name="requiredBytes"> Required bytes. </param>
internal RoundTripModel(string requiredString, int requiredInt, IList<string> requiredCollection, IDictionary<string, string> requiredDictionary, Thing requiredModel, int intExtensibleEnum, IList<int> intExtensibleEnumCollection, int floatExtensibleEnum, IList<int> floatExtensibleEnumCollection, float floatFixedEnum, IList<float> floatFixedEnumCollection, int intFixedEnum, IList<int> intFixedEnumCollection, string stringFixedEnum, System.BinaryData requiredUnknown, System.BinaryData optionalUnknown, IDictionary<string, System.BinaryData> requiredRecordUnknown, IDictionary<string, System.BinaryData> optionalRecordUnknown, IDictionary<string, System.BinaryData> readOnlyRequiredRecordUnknown, IDictionary<string, System.BinaryData> readOnlyOptionalRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, System.BinaryData requiredBytes)
{
RequiredString = requiredString;
RequiredInt = requiredInt;
RequiredCollection = requiredCollection;
RequiredDictionary = requiredDictionary;
RequiredModel = requiredModel;
IntExtensibleEnum = intExtensibleEnum;
IntExtensibleEnumCollection = intExtensibleEnumCollection;
FloatExtensibleEnum = floatExtensibleEnum;
FloatExtensibleEnumCollection = floatExtensibleEnumCollection;
FloatFixedEnum = floatFixedEnum;
FloatFixedEnumCollection = floatFixedEnumCollection;
IntFixedEnum = intFixedEnum;
IntFixedEnumCollection = intFixedEnumCollection;
StringFixedEnum = stringFixedEnum;
RequiredUnknown = requiredUnknown;
OptionalUnknown = optionalUnknown;
RequiredRecordUnknown = requiredRecordUnknown;
OptionalRecordUnknown = optionalRecordUnknown;
ReadOnlyRequiredRecordUnknown = readOnlyRequiredRecordUnknown;
ReadOnlyOptionalRecordUnknown = readOnlyOptionalRecordUnknown;
ModelWithRequiredNullable = modelWithRequiredNullable;
RequiredBytes = requiredBytes;
}
/// <summary> Initializes a new instance of <see cref="RoundTripModel"/> for deserialization. </summary>
internal RoundTripModel()
{
}
/// <summary> Required string, illustrating a reference type property. </summary>
public string RequiredString { get; set; }

Просмотреть файл

@ -4,12 +4,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace UnbrandedTypeSpec.Models
{
public partial class Thing
{
// Add Constructors
/// <summary> Initializes a new instance of <see cref="Thing"/>. </summary>
/// <param name="name"> name of the Thing. </param>
/// <param name="requiredUnion"> required Union. </param>
/// <param name="requiredBadDescription"> description with xml <|endoftext|>. </param>
/// <param name="requiredNullableList"> required nullable collection. </param>
/// <exception cref="ArgumentNullException"> <paramref name="name"/>, <paramref name="requiredUnion"/> or <paramref name="requiredBadDescription"/> is null. </exception>
public Thing(string name, System.BinaryData requiredUnion, string requiredBadDescription, IEnumerable<int> requiredNullableList)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (requiredUnion == null)
{
throw new ArgumentNullException(nameof(requiredUnion));
}
if (requiredBadDescription == null)
{
throw new ArgumentNullException(nameof(requiredBadDescription));
}
Name = name;
RequiredUnion = requiredUnion;
RequiredBadDescription = requiredBadDescription;
OptionalNullableList = new List<int>();
RequiredNullableList = requiredNullableList?.ToList();
}
/// <summary> Initializes a new instance of <see cref="Thing"/>. </summary>
/// <param name="name"> name of the Thing. </param>
/// <param name="requiredUnion"> required Union. </param>
/// <param name="requiredLiteralString"> required literal string. </param>
/// <param name="requiredLiteralInt"> required literal int. </param>
/// <param name="requiredLiteralFloat"> required literal float. </param>
/// <param name="requiredLiteralBool"> required literal bool. </param>
/// <param name="optionalLiteralString"> optional literal string. </param>
/// <param name="optionalLiteralInt"> optional literal int. </param>
/// <param name="optionalLiteralFloat"> optional literal float. </param>
/// <param name="optionalLiteralBool"> optional literal bool. </param>
/// <param name="requiredBadDescription"> description with xml <|endoftext|>. </param>
/// <param name="optionalNullableList"> optional nullable collection. </param>
/// <param name="requiredNullableList"> required nullable collection. </param>
internal Thing(string name, System.BinaryData requiredUnion, string requiredLiteralString, int requiredLiteralInt, float requiredLiteralFloat, bool requiredLiteralBool, string optionalLiteralString, int optionalLiteralInt, float optionalLiteralFloat, bool optionalLiteralBool, string requiredBadDescription, IList<int> optionalNullableList, IList<int> requiredNullableList)
{
Name = name;
RequiredUnion = requiredUnion;
RequiredLiteralString = requiredLiteralString;
RequiredLiteralInt = requiredLiteralInt;
RequiredLiteralFloat = requiredLiteralFloat;
RequiredLiteralBool = requiredLiteralBool;
OptionalLiteralString = optionalLiteralString;
OptionalLiteralInt = optionalLiteralInt;
OptionalLiteralFloat = optionalLiteralFloat;
OptionalLiteralBool = optionalLiteralBool;
RequiredBadDescription = requiredBadDescription;
OptionalNullableList = optionalNullableList;
RequiredNullableList = requiredNullableList;
}
/// <summary> Initializes a new instance of <see cref="Thing"/> for deserialization. </summary>
internal Thing()
{
}
/// <summary> name of the Thing. </summary>
public string Name { get; set; }

Просмотреть файл

@ -8,81 +8,186 @@ namespace UnbrandedTypeSpec.Models
{
public partial class UnbrandedTypeSpecClient
{
// Add Constructors
// Add Methods
/// <summary> Return hi. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="headParameter"></param>
/// <param name="queryParameter"></param>
/// <param name="optionalQuery"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="headParameter"/>, <paramref name="queryParameter"/> or <paramref name="accept"/> is null. </exception>
internal void CreateSayHiRequest(System.Uri unbrandedTypeSpecUrl, string headParameter, string queryParameter, string optionalQuery, string accept)
{
}
/// <summary> Return hi again. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="p1"></param>
/// <param name="contentType"></param>
/// <param name="p2"></param>
/// <param name="action"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="p1"/>, <paramref name="contentType"/>, <paramref name="p2"/>, <paramref name="action"/> or <paramref name="accept"/> is null. </exception>
internal void CreateHelloAgainRequest(System.Uri unbrandedTypeSpecUrl, string p1, string contentType, string p2, RoundTripModel action, string accept)
{
}
/// <summary> Return hi again. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="action"></param>
/// <param name="accept"></param>
/// <param name="contentType"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="p1"/>, <paramref name="p2"/>, <paramref name="action"/>, <paramref name="accept"/> or <paramref name="contentType"/> is null. </exception>
internal void CreateNoContentTypeRequest(System.Uri unbrandedTypeSpecUrl, string p1, string p2, RoundTripModel action, string accept, string contentType)
{
}
/// <summary> Return hi in demo2. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/> or <paramref name="accept"/> is null. </exception>
internal void CreateHelloDemo2Request(System.Uri unbrandedTypeSpecUrl, string accept)
{
}
/// <summary> Create with literal value. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="body"></param>
/// <param name="accept"></param>
/// <param name="contentType"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="body"/>, <paramref name="accept"/> or <paramref name="contentType"/> is null. </exception>
internal void CreateCreateLiteralRequest(System.Uri unbrandedTypeSpecUrl, Thing body, string accept, string contentType)
{
}
/// <summary> Send literal parameters. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="p1"/>, <paramref name="p2"/>, <paramref name="p3"/> or <paramref name="accept"/> is null. </exception>
internal void CreateHelloLiteralRequest(System.Uri unbrandedTypeSpecUrl, string p1, int p2, bool p3, string accept)
{
}
/// <summary> top level method. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="action"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="action"/> or <paramref name="accept"/> is null. </exception>
internal void CreateTopActionRequest(System.Uri unbrandedTypeSpecUrl, DateTimeOffset action, string accept)
{
}
/// <summary> top level method2. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/> or <paramref name="accept"/> is null. </exception>
internal void CreateTopAction2Request(System.Uri unbrandedTypeSpecUrl, string accept)
{
}
/// <summary> top level patch. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="body"></param>
/// <param name="accept"></param>
/// <param name="contentType"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="body"/>, <paramref name="accept"/> or <paramref name="contentType"/> is null. </exception>
internal void CreatePatchActionRequest(System.Uri unbrandedTypeSpecUrl, Thing body, string accept, string contentType)
{
}
/// <summary> body parameter without body decorator. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="Thing"> A model with a few properties of literal types. </param>
/// <param name="accept"></param>
/// <param name="contentType"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="Thing"/>, <paramref name="accept"/> or <paramref name="contentType"/> is null. </exception>
internal void CreateAnonymousBodyRequest(System.Uri unbrandedTypeSpecUrl, Thing Thing, string accept, string contentType)
{
}
/// <summary> Model can have its friendly name. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="Friend"> this is not a friendly model but with a friendly name. </param>
/// <param name="accept"></param>
/// <param name="contentType"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="Friend"/>, <paramref name="accept"/> or <paramref name="contentType"/> is null. </exception>
internal void CreateFriendlyModelRequest(System.Uri unbrandedTypeSpecUrl, Friend Friend, string accept, string contentType)
{
}
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="repeatabilityFirstSent"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/> or <paramref name="accept"/> is null. </exception>
internal void CreateAddTimeHeaderRequest(System.Uri unbrandedTypeSpecUrl, DateTimeOffset repeatabilityFirstSent, string accept)
{
}
/// <summary> parameter has string format. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="subscriptionId"></param>
/// <param name="body"></param>
/// <param name="contentType"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="subscriptionId"/>, <paramref name="body"/>, <paramref name="contentType"/> or <paramref name="accept"/> is null. </exception>
internal void CreateStringFormatRequest(System.Uri unbrandedTypeSpecUrl, Guid subscriptionId, ModelWithFormat body, string contentType, string accept)
{
}
/// <summary> Model can have its projected name. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="ProjectedModel"> this is a model with a projected name. </param>
/// <param name="accept"></param>
/// <param name="contentType"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="ProjectedModel"/>, <paramref name="accept"/> or <paramref name="contentType"/> is null. </exception>
internal void CreateProjectedNameModelRequest(System.Uri unbrandedTypeSpecUrl, ProjectedModel ProjectedModel, string accept, string contentType)
{
}
/// <summary> return anonymous model. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/> or <paramref name="accept"/> is null. </exception>
internal void CreateReturnsAnonymousModelRequest(System.Uri unbrandedTypeSpecUrl, string accept)
{
}
/// <summary> get extensible enum. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/> or <paramref name="accept"/> is null. </exception>
internal void CreateGetUnknownValueRequest(System.Uri unbrandedTypeSpecUrl, string accept)
{
}
/// <summary> When set protocol false and convenient true, then the protocol method should be internal. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="body"></param>
/// <param name="accept"></param>
/// <param name="contentType"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="body"/>, <paramref name="accept"/> or <paramref name="contentType"/> is null. </exception>
internal void CreateInternalProtocolRequest(System.Uri unbrandedTypeSpecUrl, Thing body, string accept, string contentType)
{
}
/// <summary> When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/> or <paramref name="accept"/> is null. </exception>
internal void CreateStillConvenientRequest(System.Uri unbrandedTypeSpecUrl, string accept)
{
}
/// <summary> head as boolean. </summary>
/// <param name="unbrandedTypeSpecUrl"></param>
/// <param name="id"></param>
/// <param name="accept"></param>
/// <exception cref="ArgumentNullException"> <paramref name="unbrandedTypeSpecUrl"/>, <paramref name="id"/> or <paramref name="accept"/> is null. </exception>
internal void CreateHeadAsBooleanRequest(System.Uri unbrandedTypeSpecUrl, string id, string accept)
{
}