Skip to content

Commit c3741d5

Browse files
committed
Merge branch 'feature/v3' of https://github.com/Azure/autorest.csharp into SyncMGC4031
2 parents 4527368 + 68e44c3 commit c3741d5

File tree

14 files changed

+42
-135
lines changed

14 files changed

+42
-135
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AutoRest.CSharp/Common/Input/InputTypes/Examples/ExampleMockValueBuilder.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ internal class ExampleMockValueBuilder
1717

1818
private readonly static ConcurrentDictionary<InputType, InputExampleValue> _cache = new();
1919

20-
public static InputClientExample BuildClientExample(InputClient client, bool useAllParameters)
21-
{
22-
_cache.Clear();
23-
var clientParameterExamples = new List<InputParameterExample>();
24-
foreach (var parameter in client.Parameters)
25-
{
26-
if (!useAllParameters && !parameter.IsRequired)
27-
{
28-
continue;
29-
}
30-
var parameterExample = BuildParameterExample(parameter, useAllParameters);
31-
clientParameterExamples.Add(parameterExample);
32-
}
33-
34-
return new(client, clientParameterExamples);
35-
}
36-
3720
public static InputOperationExample BuildOperationExample(InputOperation operation, bool useAllParameters)
3821
{
3922
_cache.Clear();

src/AutoRest.CSharp/Common/Input/InputTypes/Examples/InputClientExample.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
7-
using AutoRest.CSharp.Common.Input.Examples;
86

97
namespace AutoRest.CSharp.Common.Input;
108

119
internal record InputClient(string Name, string Description, IReadOnlyList<InputOperation> Operations, IReadOnlyList<InputParameter> Parameters, string? Parent, IReadOnlyList<InputDecoratorInfo>? Decorators = null)
1210
{
1311
private readonly string? _key;
1412

15-
// No field in record can be lazy initialized - it breaks discovery in dictionary
16-
private readonly Dictionary<string, InputClientExample> _examples = new();
17-
1813
public string Key
1914
{
2015
get => _key ?? Name;
@@ -24,17 +19,4 @@ public string Key
2419
public IReadOnlyList<InputOperation> Operations { get; internal set; } = Operations ?? Array.Empty<InputOperation>();
2520

2621
public InputClient() : this(string.Empty, string.Empty, Array.Empty<InputOperation>(), Array.Empty<InputParameter>(), null) { }
27-
28-
public IReadOnlyDictionary<string, InputClientExample> Examples => EnsureExamples();
29-
30-
private IReadOnlyDictionary<string, InputClientExample> EnsureExamples()
31-
{
32-
if (!_examples.Any())
33-
{
34-
_examples[ExampleMockValueBuilder.ShortVersionMockExampleKey] = ExampleMockValueBuilder.BuildClientExample(this, false);
35-
_examples[ExampleMockValueBuilder.MockExampleAllParameterKey] = ExampleMockValueBuilder.BuildClientExample(this, true);
36-
}
37-
38-
return _examples;
39-
}
4022
}

src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ private static ClientInfo CreateClientInfo(InputClient ns, SourceInputModel? sou
265265
INamedTypeSymbol? existingType;
266266
if (sourceInputModel == null || (existingType = sourceInputModel.FindForType(clientNamespace, clientName)) == null)
267267
{
268-
return new ClientInfo(ns.Name, clientName, clientNamespace, clientDescription, operations, clientParameters, resourceParameters, ns.Examples);
268+
return new ClientInfo(ns.Name, clientName, clientNamespace, clientDescription, operations, clientParameters, resourceParameters);
269269
}
270270

271271
clientName = existingType.Name;
272272
clientNamespace = existingType.ContainingNamespace.ToDisplayString();
273-
return new ClientInfo(ns.Name, clientName, clientNamespace, clientDescription, existingType, operations, clientParameters, resourceParameters, ns.Examples);
273+
return new ClientInfo(ns.Name, clientName, clientNamespace, clientDescription, existingType, operations, clientParameters, resourceParameters);
274274
}
275275

276276
private IReadOnlyList<ClientInfo> SetHierarchy(IReadOnlyDictionary<string, ClientInfo> clientInfosByName)
@@ -297,9 +297,8 @@ private IReadOnlyList<ClientInfo> SetHierarchy(IReadOnlyDictionary<string, Clien
297297
var infoForEndpoint = topLevelClients.FirstOrDefault(c => c.ClientParameters.Any(p => p.IsEndpoint));
298298
var endpointParameter = infoForEndpoint?.ClientParameters.FirstOrDefault(p => p.IsEndpoint);
299299
var clientParameters = topLevelClients.SelectMany(c => c.ClientParameters.Where(p => !p.IsRequired || p.IsApiVersion || p.IsEndpoint)).Distinct().ToArray();
300-
var clientExamples = infoForEndpoint?.Examples ?? new Dictionary<string, InputClientExample>();
301300

302-
topLevelClientInfo = new ClientInfo(clientName, clientNamespace, clientParameters, clientExamples);
301+
topLevelClientInfo = new ClientInfo(clientName, clientNamespace, clientParameters);
303302
}
304303

305304
foreach (var clientInfo in topLevelClients)
@@ -438,7 +437,6 @@ private IEnumerable<LowLevelClient> CreateClients(IEnumerable<ClientInfo> client
438437
_rootNamespace.Auth,
439438
_sourceInputModel,
440439
clientOptions,
441-
clientInfo.Examples,
442440
typeFactory)
443441
{
444442
SubClients = subClients
@@ -461,31 +459,6 @@ private class ClientInfo
461459
public INamedTypeSymbol? ExistingType { get; }
462460
public IReadOnlyList<InputOperation> Operations { get; }
463461

464-
private IReadOnlyDictionary<string, InputClientExample> _initialExamples;
465-
private IReadOnlyDictionary<string, InputClientExample>? _examples;
466-
public IReadOnlyDictionary<string, InputClientExample> Examples => _examples ??= EnsureExamples();
467-
468-
private IReadOnlyDictionary<string, InputClientExample> EnsureExamples()
469-
{
470-
// pick up all examples from child client infos here, since we might promote some parameters from child clients
471-
var examples = new Dictionary<string, InputClientExample>();
472-
foreach (var (key, example) in _initialExamples)
473-
{
474-
var clientParameterExamples = new List<InputParameterExample>(example.ClientParameters);
475-
foreach (var child in Children)
476-
{
477-
if (child.Examples.TryGetValue(key, out var childExamples))
478-
{
479-
clientParameterExamples.AddRange(childExamples.ClientParameters);
480-
}
481-
}
482-
483-
examples.Add(key, new(example.Client, clientParameterExamples));
484-
}
485-
486-
return examples;
487-
}
488-
489462
private IReadOnlyList<InputParameter>? _clientParameters;
490463
private IReadOnlyList<InputParameter> _initClientParameters;
491464
public IReadOnlyList<InputParameter> ClientParameters => _clientParameters ??= EnsureClientParameters();
@@ -506,12 +479,12 @@ private IReadOnlyList<InputParameter> EnsureClientParameters()
506479
public IList<ClientInfo> Children { get; }
507480
public IList<InputOperation> Requests { get; }
508481

509-
public ClientInfo(string operationGroupKey, string clientName, string clientNamespace, string clientDescription, IReadOnlyList<InputOperation> operations, IReadOnlyList<InputParameter> clientParameters, ISet<InputParameter> resourceParameters, IReadOnlyDictionary<string, InputClientExample> examples)
510-
: this(operationGroupKey, clientName, clientNamespace, clientDescription, null, operations, clientParameters, resourceParameters, examples)
482+
public ClientInfo(string operationGroupKey, string clientName, string clientNamespace, string clientDescription, IReadOnlyList<InputOperation> operations, IReadOnlyList<InputParameter> clientParameters, ISet<InputParameter> resourceParameters)
483+
: this(operationGroupKey, clientName, clientNamespace, clientDescription, null, operations, clientParameters, resourceParameters)
511484
{
512485
}
513486

514-
public ClientInfo(string operationGroupKey, string clientName, string clientNamespace, string clientDescription, INamedTypeSymbol? existingType, IReadOnlyList<InputOperation> operations, IReadOnlyList<InputParameter> clientParameters, ISet<InputParameter> resourceParameters, IReadOnlyDictionary<string, InputClientExample> examples)
487+
public ClientInfo(string operationGroupKey, string clientName, string clientNamespace, string clientDescription, INamedTypeSymbol? existingType, IReadOnlyList<InputOperation> operations, IReadOnlyList<InputParameter> clientParameters, ISet<InputParameter> resourceParameters)
515488
{
516489
OperationGroupKey = operationGroupKey;
517490
Name = clientName;
@@ -523,10 +496,9 @@ public ClientInfo(string operationGroupKey, string clientName, string clientName
523496
ResourceParameters = resourceParameters;
524497
Children = new List<ClientInfo>();
525498
Requests = new List<InputOperation>();
526-
_initialExamples = examples;
527499
}
528500

529-
public ClientInfo(string clientName, string clientNamespace, IReadOnlyList<InputParameter> clientParameters, IReadOnlyDictionary<string, InputClientExample> examples)
501+
public ClientInfo(string clientName, string clientNamespace, IReadOnlyList<InputParameter> clientParameters)
530502
{
531503
OperationGroupKey = string.Empty;
532504
Name = clientName;
@@ -538,7 +510,6 @@ public ClientInfo(string clientName, string clientNamespace, IReadOnlyList<Input
538510
ResourceParameters = new HashSet<InputParameter>();
539511
Children = new List<ClientInfo>();
540512
Requests = new List<InputOperation>();
541-
_initialExamples = examples;
542513
}
543514
}
544515
}

src/AutoRest.CSharp/LowLevel/Output/LowLevelClient.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ internal class LowLevelClient : TypeProvider
2727
private readonly string _libraryName;
2828
private readonly TypeFactory _typeFactory;
2929
private readonly IEnumerable<InputParameter> _clientParameters;
30-
private readonly IReadOnlyDictionary<string, InputClientExample> _clientParameterExamples;
3130
private readonly InputAuth _authorization;
3231
private readonly IEnumerable<InputOperation> _operations;
3332

@@ -60,7 +59,7 @@ private LowLevelClient GetTopLevelClient(LowLevelClient client)
6059
return GetTopLevelClient(client.ParentClient);
6160
}
6261

63-
public LowLevelClient(string name, string ns, string description, string libraryName, LowLevelClient? parentClient, IEnumerable<InputOperation> operations, IEnumerable<InputParameter> clientParameters, InputAuth authorization, SourceInputModel? sourceInputModel, ClientOptionsTypeProvider clientOptions, IReadOnlyDictionary<string, InputClientExample> examples, TypeFactory typeFactory)
62+
public LowLevelClient(string name, string ns, string description, string libraryName, LowLevelClient? parentClient, IEnumerable<InputOperation> operations, IEnumerable<InputParameter> clientParameters, InputAuth authorization, SourceInputModel? sourceInputModel, ClientOptionsTypeProvider clientOptions, TypeFactory typeFactory)
6463
: base(ns, sourceInputModel)
6564
{
6665
_libraryName = libraryName;
@@ -73,7 +72,6 @@ public LowLevelClient(string name, string ns, string description, string library
7372
ClientOptions = clientOptions;
7473

7574
_clientParameters = clientParameters;
76-
_clientParameterExamples = examples;
7775
_authorization = authorization;
7876
_operations = operations;
7977

@@ -120,7 +118,7 @@ public IEnumerable<LowLevelClientMethod> CustomMethods()
120118

121119
public static IEnumerable<LowLevelClientMethod> BuildMethods(LowLevelClient? client, TypeFactory typeFactory, IEnumerable<InputOperation> operations, ClientFields fields, string namespaceName, string clientName, SourceInputModel? sourceInputModel)
122120
{
123-
var builders = operations.ToDictionary(o => o, o => new OperationMethodChainBuilder(client, o, namespaceName, clientName, fields, typeFactory, sourceInputModel, client?._clientParameterExamples));
121+
var builders = operations.ToDictionary(o => o, o => new OperationMethodChainBuilder(client, o, namespaceName, clientName, fields, typeFactory, sourceInputModel));
124122
foreach (var (_, builder) in builders)
125123
{
126124
builder.BuildNextPageMethod(builders);

src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ internal class OperationMethodChainBuilder
4040
private readonly string _clientName;
4141
private readonly LowLevelClient? _client;
4242
private readonly ClientFields _fields;
43-
private readonly IReadOnlyDictionary<string, InputClientExample>? _clientParameterExamples;
4443
private readonly TypeFactory _typeFactory;
4544
private readonly SourceInputModel? _sourceInputModel;
4645
private readonly List<ParameterChain> _orderedParameters;
@@ -54,13 +53,12 @@ internal class OperationMethodChainBuilder
5453

5554
private InputOperation Operation { get; }
5655

57-
public OperationMethodChainBuilder(LowLevelClient? client, InputOperation operation, string namespaceName, string clientName, ClientFields fields, TypeFactory typeFactory, SourceInputModel? sourceInputModel, IReadOnlyDictionary<string, InputClientExample>? clientParameterExamples)
56+
public OperationMethodChainBuilder(LowLevelClient? client, InputOperation operation, string namespaceName, string clientName, ClientFields fields, TypeFactory typeFactory, SourceInputModel? sourceInputModel)
5857
{
5958
_client = client;
6059
_namespaceName = namespaceName;
6160
_clientName = clientName;
6261
_fields = fields;
63-
_clientParameterExamples = clientParameterExamples;
6462
_typeFactory = typeFactory;
6563
_sourceInputModel = sourceInputModel;
6664
_orderedParameters = new List<ParameterChain>();
@@ -126,7 +124,7 @@ private void BuildSamples(LowLevelClientMethod method, List<DpgOperationSample>
126124
{
127125
// we do not generate any sample if these variables are null
128126
// they are only null when HLC calling methods in this class
129-
if (_clientParameterExamples == null || _client == null)
127+
if (_client == null)
130128
return;
131129
var shouldGenerateSample = DpgOperationSample.ShouldGenerateSample(_client, method.ProtocolMethodSignature);
132130

@@ -136,35 +134,30 @@ private void BuildSamples(LowLevelClientMethod method, List<DpgOperationSample>
136134
// short version samples
137135
var shouldGenerateShortVersion = DpgOperationSample.ShouldGenerateShortVersion(_client, method);
138136

139-
foreach (var (exampleKey, clientExample) in _clientParameterExamples)
137+
foreach (var (exampleKey, operationExample) in Operation.Examples)
140138
{
141139
if (!shouldGenerateShortVersion && exampleKey != ExampleMockValueBuilder.ShortVersionMockExampleKey)
142140
continue; // skip the short example when we decide not to generate it
143141

144-
if (Operation.Examples.TryGetValue(exampleKey, out var operationExample))
142+
// add protocol method sample
143+
samples.Add(new(
144+
_client,
145+
_typeFactory,
146+
method,
147+
operationExample,
148+
false,
149+
exampleKey));
150+
151+
// add convenience method sample
152+
if (method.ConvenienceMethod != null && method.ConvenienceMethod.Signature.Modifiers.HasFlag(Public))
145153
{
146-
// add protocol method sample
147154
samples.Add(new(
148155
_client,
149156
_typeFactory,
150157
method,
151-
clientExample.ClientParameters,
152158
operationExample,
153-
false,
159+
true,
154160
exampleKey));
155-
156-
// add convenience method sample
157-
if (method.ConvenienceMethod != null && method.ConvenienceMethod.Signature.Modifiers.HasFlag(Public))
158-
{
159-
samples.Add(new(
160-
_client,
161-
_typeFactory,
162-
method,
163-
clientExample.ClientParameters,
164-
operationExample,
165-
true,
166-
exampleKey));
167-
}
168161
}
169162
}
170163
}

0 commit comments

Comments
 (0)