Skip to content

Commit e84e7b2

Browse files
committed
remove decrators parameter from construtor
1 parent c3741d5 commit e84e7b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+207
-205
lines changed

src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ private InputModelType GetOrCreateModel(ObjectSchema schema)
386386
DiscriminatorValue: schema.DiscriminatorValue,
387387
DiscriminatorProperty: schema.Discriminator?.Property is { } discriminatorProperty ? GetOrCreateProperty(discriminatorProperty) : null,
388388
DiscriminatedSubtypes: discriminatedSubtypes,
389-
AdditionalProperties: dictionarySchema is not null ? GetOrCreateType(dictionarySchema.ElementType, false) : null,
390-
Decorators: Array.Empty<InputDecoratorInfo>())
389+
AdditionalProperties: dictionarySchema is not null ? GetOrCreateType(dictionarySchema.ElementType, false) : null)
391390
{
392391
Serialization = GetSerialization(schema, usage),
393392
SpecName = schema.Language.Default.SerializedName ?? schema.Language.Default.Name
@@ -434,7 +433,6 @@ private InputModelProperty GetOrCreateProperty(Property property)
434433
IsRequired: property.IsRequired,
435434
IsReadOnly: property.IsReadOnly,
436435
IsDiscriminator: property.IsDiscriminator ?? false,
437-
Decorators: Array.Empty<InputDecoratorInfo>(),
438436
FlattenedNames: property.FlattenedNames.ToList());
439437
_propertiesCache.Add(property, inputProperty);
440438

@@ -595,27 +593,27 @@ private InputType GetOrCreateType(Schema schema, string? format, bool isNullable
595593
ByteArraySchema { Type: AllSchemaTypes.ByteArray, Format: ByteArraySchemaFormat.Byte } => InputPrimitiveType.Base64.WithNullable(isNullable),
596594
{ Type: AllSchemaTypes.Credential } => InputPrimitiveType.String.WithNullable(isNullable),
597595
{ Type: AllSchemaTypes.Date } => InputPrimitiveType.PlainDate.WithNullable(isNullable),
598-
DateTimeSchema { Type: AllSchemaTypes.DateTime, Format: DateTimeSchemaFormat.DateTime } => new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
599-
DateTimeSchema { Type: AllSchemaTypes.DateTime, Format: DateTimeSchemaFormat.DateTimeRfc1123 } => new InputDateTimeType(DateTimeKnownEncoding.Rfc7231, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
600-
{ Type: AllSchemaTypes.DateTime } => new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
601-
DurationSchema when format == XMsFormat.DurationConstant => new InputDurationType(DurationKnownEncoding.Constant, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
602-
{ Type: AllSchemaTypes.Duration } => new InputDurationType(DurationKnownEncoding.Iso8601, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
596+
DateTimeSchema { Type: AllSchemaTypes.DateTime, Format: DateTimeSchemaFormat.DateTime } => new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String).WithNullable(isNullable),
597+
DateTimeSchema { Type: AllSchemaTypes.DateTime, Format: DateTimeSchemaFormat.DateTimeRfc1123 } => new InputDateTimeType(DateTimeKnownEncoding.Rfc7231, InputPrimitiveType.String).WithNullable(isNullable),
598+
{ Type: AllSchemaTypes.DateTime } => new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String).WithNullable(isNullable),
599+
DurationSchema when format == XMsFormat.DurationConstant => new InputDurationType(DurationKnownEncoding.Constant, InputPrimitiveType.String).WithNullable(isNullable),
600+
{ Type: AllSchemaTypes.Duration } => new InputDurationType(DurationKnownEncoding.Iso8601, InputPrimitiveType.String).WithNullable(isNullable),
603601
NumberSchema { Type: AllSchemaTypes.Number, Precision: 32 } => InputPrimitiveType.Float32.WithNullable(isNullable),
604602
NumberSchema { Type: AllSchemaTypes.Number, Precision: 128 } => InputPrimitiveType.Decimal128.WithNullable(isNullable),
605603
{ Type: AllSchemaTypes.Number } => InputPrimitiveType.Float64.WithNullable(isNullable),
606604
NumberSchema { Type: AllSchemaTypes.Integer, Precision: 64 } => InputPrimitiveType.Int64.WithNullable(isNullable),
607605
{ Type: AllSchemaTypes.Integer } => InputPrimitiveType.Int32.WithNullable(isNullable),
608606
{ Type: AllSchemaTypes.Time } => InputPrimitiveType.PlainTime.WithNullable(isNullable),
609-
{ Type: AllSchemaTypes.Unixtime } => new InputDateTimeType(DateTimeKnownEncoding.UnixTimestamp, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
607+
{ Type: AllSchemaTypes.Unixtime } => new InputDateTimeType(DateTimeKnownEncoding.UnixTimestamp, InputPrimitiveType.String).WithNullable(isNullable),
610608
{ Type: AllSchemaTypes.Uri } => InputPrimitiveType.Url.WithNullable(isNullable),
611609
{ Type: AllSchemaTypes.Uuid } => InputPrimitiveType.Uuid.WithNullable(isNullable),
612610
{ Type: AllSchemaTypes.String } when format == XMsFormat.ArmId => InputPrimitiveType.ResourceIdentifier.WithNullable(isNullable),
613611
{ Type: AllSchemaTypes.String } when format == XMsFormat.AzureLocation => InputPrimitiveType.AzureLocation.WithNullable(isNullable),
614612
{ Type: AllSchemaTypes.String } when format == XMsFormat.ContentType => InputPrimitiveType.ContentType.WithNullable(isNullable),
615-
{ Type: AllSchemaTypes.String } when format == XMsFormat.DateTime => new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
616-
{ Type: AllSchemaTypes.String } when format == XMsFormat.DateTimeRFC1123 => new InputDateTimeType(DateTimeKnownEncoding.Rfc7231, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
617-
{ Type: AllSchemaTypes.String } when format == XMsFormat.DateTimeUnix => new InputDateTimeType(DateTimeKnownEncoding.UnixTimestamp, InputPrimitiveType.Int64, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
618-
{ Type: AllSchemaTypes.String } when format == XMsFormat.DurationConstant => new InputDurationType(DurationKnownEncoding.Constant, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
613+
{ Type: AllSchemaTypes.String } when format == XMsFormat.DateTime => new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String).WithNullable(isNullable),
614+
{ Type: AllSchemaTypes.String } when format == XMsFormat.DateTimeRFC1123 => new InputDateTimeType(DateTimeKnownEncoding.Rfc7231, InputPrimitiveType.String).WithNullable(isNullable),
615+
{ Type: AllSchemaTypes.String } when format == XMsFormat.DateTimeUnix => new InputDateTimeType(DateTimeKnownEncoding.UnixTimestamp, InputPrimitiveType.Int64).WithNullable(isNullable),
616+
{ Type: AllSchemaTypes.String } when format == XMsFormat.DurationConstant => new InputDurationType(DurationKnownEncoding.Constant, InputPrimitiveType.String).WithNullable(isNullable),
619617
{ Type: AllSchemaTypes.String } when format == XMsFormat.ETag => InputPrimitiveType.ETag.WithNullable(isNullable),
620618
{ Type: AllSchemaTypes.String } when format == XMsFormat.IPAddress => InputPrimitiveType.IPAddress.WithNullable(isNullable),
621619
{ Type: AllSchemaTypes.String } when format == XMsFormat.ResourceType => InputPrimitiveType.ResourceType.WithNullable(isNullable),
@@ -631,8 +629,8 @@ private InputType GetOrCreateType(Schema schema, string? format, bool isNullable
631629
ConstantSchema constantSchema => CreateConstant(constantSchema, format, isNullable).Type,
632630
ChoiceSchema choiceSchema => GetInputTypeForChoiceSchema(choiceSchema),
633631
SealedChoiceSchema choiceSchema => GetInputTypeForChoiceSchema(choiceSchema),
634-
ArraySchema array => new InputListType(array.Name, array.Extensions?.IsEmbeddingsVector == true ? "Azure.Core.EmbeddingVector" : "TypeSpec.Array", GetOrCreateType(array.ElementType, array.NullableItems ?? false), Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
635-
DictionarySchema dictionary => new InputDictionaryType(dictionary.Name, InputPrimitiveType.String, GetOrCreateType(dictionary.ElementType, dictionary.NullableItems ?? false), Array.Empty<InputDecoratorInfo>()).WithNullable(isNullable),
632+
ArraySchema array => new InputListType(array.Name, array.Extensions?.IsEmbeddingsVector == true ? "Azure.Core.EmbeddingVector" : "TypeSpec.Array", GetOrCreateType(array.ElementType, array.NullableItems ?? false)).WithNullable(isNullable),
633+
DictionarySchema dictionary => new InputDictionaryType(dictionary.Name, InputPrimitiveType.String, GetOrCreateType(dictionary.ElementType, dictionary.NullableItems ?? false)).WithNullable(isNullable),
636634
ObjectSchema objectSchema => CreateTypeForObjectSchema(objectSchema),
637635

638636
_ => throw new InvalidCastException($"Unknown schema type {schema.GetType()}")
@@ -676,19 +674,19 @@ private InputType CreateTypeForObjectSchema(ObjectSchema objectSchema)
676674
XMsFormat.DataFactoryElementOfInt => CreateDataFactoryElementInputType(isNullable, InputPrimitiveType.Int32),
677675
XMsFormat.DataFactoryElementOfDouble => CreateDataFactoryElementInputType(isNullable, InputPrimitiveType.Float64),
678676
XMsFormat.DataFactoryElementOfBool => CreateDataFactoryElementInputType(isNullable, InputPrimitiveType.Boolean),
679-
XMsFormat.DataFactoryElementOfListOfT => CreateDataFactoryElementInputType(isNullable, new InputListType(name, "TypeSpec.Array", GetOrCreateType(elementType!, false), Array.Empty<InputDecoratorInfo>())),
680-
XMsFormat.DataFactoryElementOfListOfString => CreateDataFactoryElementInputType(isNullable, new InputListType(name, "TypeSpec.Array", InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>())),
681-
XMsFormat.DataFactoryElementOfKeyValuePairs => CreateDataFactoryElementInputType(isNullable, new InputDictionaryType(name, InputPrimitiveType.String, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>())),
682-
XMsFormat.DataFactoryElementOfDateTime => CreateDataFactoryElementInputType(isNullable, new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String, Array.Empty<InputDecoratorInfo>())),
677+
XMsFormat.DataFactoryElementOfListOfT => CreateDataFactoryElementInputType(isNullable, new InputListType(name, "TypeSpec.Array", GetOrCreateType(elementType!, false))),
678+
XMsFormat.DataFactoryElementOfListOfString => CreateDataFactoryElementInputType(isNullable, new InputListType(name, "TypeSpec.Array", InputPrimitiveType.String)),
679+
XMsFormat.DataFactoryElementOfKeyValuePairs => CreateDataFactoryElementInputType(isNullable, new InputDictionaryType(name, InputPrimitiveType.String, InputPrimitiveType.String)),
680+
XMsFormat.DataFactoryElementOfDateTime => CreateDataFactoryElementInputType(isNullable, new InputDateTimeType(DateTimeKnownEncoding.Rfc3339, InputPrimitiveType.String)),
683681
XMsFormat.DataFactoryElementOfDuration => CreateDataFactoryElementInputType(isNullable, InputPrimitiveType.PlainTime),
684682
XMsFormat.DataFactoryElementOfUri => CreateDataFactoryElementInputType(isNullable, InputPrimitiveType.Url),
685-
XMsFormat.DataFactoryElementOfKeyObjectValuePairs => CreateDataFactoryElementInputType(isNullable, new InputDictionaryType(name, InputPrimitiveType.String, InputPrimitiveType.Any, Array.Empty<InputDecoratorInfo>())),
683+
XMsFormat.DataFactoryElementOfKeyObjectValuePairs => CreateDataFactoryElementInputType(isNullable, new InputDictionaryType(name, InputPrimitiveType.String, InputPrimitiveType.Any)),
686684
_ => null
687685
};
688686
}
689687

690688
private static InputType CreateDataFactoryElementInputType(bool isNullable, InputType argumentType)
691-
=> new InputModelType("DataFactoryElement", "Azure.Core.Resources.DataFactoryElement", null, null, null, InputModelTypeUsage.None, Array.Empty<InputModelProperty>(), null, Array.Empty<InputModelType>(), null, null, new Dictionary<string, InputModelType>(), null, Array.Empty<InputDecoratorInfo>(), new List<InputType> { argumentType }).WithNullable(isNullable);
689+
=> new InputModelType("DataFactoryElement", "Azure.Core.Resources.DataFactoryElement", null, null, null, InputModelTypeUsage.None, Array.Empty<InputModelProperty>(), null, Array.Empty<InputModelType>(), null, null, new Dictionary<string, InputModelType>(), null, new List<InputType> { argumentType }).WithNullable(isNullable);
692690

693691
private InputConstant CreateConstant(ConstantSchema constantSchema, string? format, bool isNullable)
694692
{
@@ -732,8 +730,7 @@ private InputEnumType CreateEnumType(Schema schema, PrimitiveSchema choiceType,
732730
Usage: GetUsage(usage),
733731
ValueType: (InputPrimitiveType)CreateType(choiceType, schema.Extensions?.Format, false),
734732
Values: choices.Select(CreateEnumValue).ToList(),
735-
IsExtensible: isExtensible,
736-
Decorators: Array.Empty<InputDecoratorInfo>()
733+
IsExtensible: isExtensible
737734
)
738735
{
739736
Serialization = GetSerialization(schema, usage)
@@ -870,7 +867,7 @@ public bool Equals(SecurityScheme? x, SecurityScheme? y)
870867
public int GetHashCode(SecurityScheme obj) =>
871868
obj switch
872869
{
873-
AzureKeySecurityScheme azure => HashCode.Combine(azure.Type, azure.HeaderName, Array.Empty<InputDecoratorInfo>()),
870+
AzureKeySecurityScheme azure => HashCode.Combine(azure.Type, azure.HeaderName),
874871
AADTokenSecurityScheme aad => GetAADTokenSecurityHashCode(aad),
875872
_ => HashCode.Combine(obj.Type)
876873
};

src/AutoRest.CSharp/Common/Input/InputTypes/InputClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace AutoRest.CSharp.Common.Input;
88

9-
internal record InputClient(string Name, string Description, IReadOnlyList<InputOperation> Operations, IReadOnlyList<InputParameter> Parameters, string? Parent, IReadOnlyList<InputDecoratorInfo>? Decorators = null)
9+
internal record InputClient(string Name, string Description, IReadOnlyList<InputOperation> Operations, IReadOnlyList<InputParameter> Parameters, string? Parent)
1010
{
1111
private readonly string? _key;
1212

@@ -17,6 +17,7 @@ public string Key
1717
}
1818

1919
public IReadOnlyList<InputOperation> Operations { get; internal set; } = Operations ?? Array.Empty<InputOperation>();
20+
public IReadOnlyList<InputDecoratorInfo> Decorators { get; internal set; } = new List<InputDecoratorInfo>();
2021

2122
public InputClient() : this(string.Empty, string.Empty, Array.Empty<InputOperation>(), Array.Empty<InputParameter>(), null) { }
2223
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
64
namespace AutoRest.CSharp.Common.Input;
75

8-
internal record InputDateTimeType(DateTimeKnownEncoding Encode, InputPrimitiveType WireType, IReadOnlyList<InputDecoratorInfo>? Decorators = null) : InputType("DateTime", Decorators);
6+
internal record InputDateTimeType(DateTimeKnownEncoding Encode, InputPrimitiveType WireType) : InputType("DateTime");
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
64
namespace AutoRest.CSharp.Common.Input;
75

8-
internal record InputDictionaryType(string Name, InputType KeyType, InputType ValueType, IReadOnlyList<InputDecoratorInfo>? Decorators = null) : InputType(Name, Decorators) { }
6+
internal record InputDictionaryType(string Name, InputType KeyType, InputType ValueType) : InputType(Name) { }
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
64
namespace AutoRest.CSharp.Common.Input;
75

8-
internal record InputDurationType(DurationKnownEncoding Encode, InputPrimitiveType WireType, IReadOnlyList<InputDecoratorInfo>? Decorators = null) : InputType("Duration", Decorators);
6+
internal record InputDurationType(DurationKnownEncoding Encode, InputPrimitiveType WireType) : InputType("Duration");

src/AutoRest.CSharp/Common/Input/InputTypes/InputEnumType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
namespace AutoRest.CSharp.Common.Input;
77

8-
internal record InputEnumType(string Name, string CrossLanguageDefinitionId, string? Accessibility, string? Deprecated, string Description, InputModelTypeUsage Usage, InputPrimitiveType ValueType, IReadOnlyList<InputEnumTypeValue> Values, bool IsExtensible, IReadOnlyList<InputDecoratorInfo>? Decorators = null)
9-
: InputType(Name, Decorators);
8+
internal record InputEnumType(string Name, string CrossLanguageDefinitionId, string? Accessibility, string? Deprecated, string Description, InputModelTypeUsage Usage, InputPrimitiveType ValueType, IReadOnlyList<InputEnumTypeValue> Values, bool IsExtensible)
9+
: InputType(Name);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Collections.Generic;
5+
46
namespace AutoRest.CSharp.Common.Input;
57

68
internal record InputEnumTypeValue(string Name, object Value, string? Description)
79
{
810
public virtual string GetJsonValueString() => GetValueString();
911
public string GetValueString() => (Value.ToString() ?? string.Empty);
1012

11-
public string Name { get; internal set;} = Name;
13+
public string Name { get; internal set; } = Name;
14+
public IReadOnlyList<InputDecoratorInfo> Decorators { get; internal set; } = new List<InputDecoratorInfo>();
1215
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
64
namespace AutoRest.CSharp.Common.Input;
75

8-
internal record InputListType(string Name, string CrossLanguageDefinitionId, InputType ValueType, IReadOnlyList<InputDecoratorInfo>? Decorators = null) : InputType(Name, Decorators);
6+
internal record InputListType(string Name, string CrossLanguageDefinitionId, InputType ValueType) : InputType(Name);

src/AutoRest.CSharp/Common/Input/InputTypes/InputLiteralType.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
64
namespace AutoRest.CSharp.Common.Input;
75

8-
internal record InputLiteralType(InputType ValueType, object Value, IReadOnlyList<InputDecoratorInfo>? Decorators = null) : InputType("Literal", Decorators) // TODO -- name?
6+
internal record InputLiteralType(InputType ValueType, object Value) : InputType("Literal") // TODO -- name?
97
{
108
// Those two types are actually same, can we merge them?
119
public static implicit operator InputConstant(InputLiteralType literal) => new(literal.Value, literal.ValueType);

src/AutoRest.CSharp/Common/Input/InputTypes/InputModelProperty.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
namespace AutoRest.CSharp.Common.Input;
88

9-
internal record InputModelProperty(string Name, string SerializedName, string Description, InputType Type, InputConstant? ConstantValue, bool IsRequired, bool IsReadOnly, bool IsDiscriminator, IReadOnlyList<InputDecoratorInfo>? Decorators = null, IReadOnlyList<string>? FlattenedNames = null)
9+
internal record InputModelProperty(string Name, string SerializedName, string Description, InputType Type, InputConstant? ConstantValue, bool IsRequired, bool IsReadOnly, bool IsDiscriminator, IReadOnlyList<string>? FlattenedNames = null)
1010
{
1111
public FormattableString? DefaultValue { get; init; }
1212

1313
public string Name { get; internal set; } = Name;
14+
public IReadOnlyList<InputDecoratorInfo> Decorators { get; internal set; } = new List<InputDecoratorInfo>();
1415
}

0 commit comments

Comments
 (0)