-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
194 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureArmVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Generator.CSharp.ClientModel; | ||
using Microsoft.Generator.CSharp.ClientModel.Providers; | ||
using Microsoft.Generator.CSharp.Primitives; | ||
using Microsoft.Generator.CSharp.Providers; | ||
using System.IO; | ||
|
||
namespace Azure.Generator | ||
{ | ||
// only apply for MPG | ||
internal class AzureArmVisitor : ScmLibraryVisitor | ||
{ | ||
/// <inheritdoc/> | ||
protected override TypeProvider? Visit(TypeProvider type) | ||
{ | ||
if (type is ClientProvider) | ||
{ | ||
type.Update(modifiers: TransfromPublicModifiersToInternal(type), relativeFilePath: TransformRelativeFilePathForClient(type)); | ||
} | ||
// TODO: uncomment this once resources are generated | ||
//if (type is RestClientProvider) | ||
//{ | ||
// type.Update(modifiers: TransfromModifiers(type), relativeFilePath: TransformRelativeFilePathForRestClient(type)); | ||
//} | ||
return type; | ||
} | ||
|
||
private static string TransformRelativeFilePathForClient(TypeProvider type) | ||
=> Path.Combine("src", "Generated", "RestOperations", $"{type.Name}RestOperations.cs"); | ||
|
||
private static string TransformRelativeFilePathForRestClient(TypeProvider type) | ||
=> Path.Combine("src", "Generated", "RestOperations", $"{type.Name}.RestClient.cs"); | ||
|
||
private static TypeSignatureModifiers TransfromPublicModifiersToInternal(TypeProvider type) | ||
{ | ||
var modifiers = type.DeclarationModifiers; | ||
if (modifiers.HasFlag(TypeSignatureModifiers.Public)) | ||
{ | ||
modifiers &= ~TypeSignatureModifiers.Public; | ||
modifiers |= TypeSignatureModifiers.Internal; | ||
} | ||
|
||
return modifiers; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...client-csharp/generator/Azure.Generator/src/InputTransformation/InputClientTransformer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Generator.CSharp.Input; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Azure.Generator.InputTransformation | ||
{ | ||
internal static class InputClientTransformer | ||
{ | ||
public static InputClient TransformInputClient(InputClient client) | ||
{ | ||
var operationsToKeep = new List<InputOperation>(); | ||
foreach (var operation in client.Operations) | ||
{ | ||
// operations_list has been covered in Azure.ResourceManager already, we don't need to generate it in the client | ||
if (operation.CrossLanguageDefinitionId != "Azure.ResourceManager.Operations.list") | ||
{ | ||
var transformedOperation = new InputOperation(operation.Name, operation.ResourceName, operation.Summary, operation.Doc, operation.Deprecated, operation.Accessibility, TransformInputOperationParameters(operation), operation.Responses, operation.HttpMethod, operation.RequestBodyMediaType, operation.Uri, operation.Path, operation.ExternalDocsUrl, operation.RequestMediaTypes, operation.BufferResponse, operation.LongRunning, operation.Paging, operation.GenerateProtocolMethod, operation.GenerateConvenienceMethod, operation.CrossLanguageDefinitionId); | ||
operationsToKeep.Add(transformedOperation); | ||
} | ||
} | ||
return new InputClient(client.Name, client.Summary, client.Doc, operationsToKeep, client.Parameters, client.Parent); | ||
} | ||
|
||
private static IReadOnlyList<InputParameter> TransformInputOperationParameters(InputOperation operation) | ||
{ | ||
var parameters = new List<InputParameter>(); | ||
foreach (var parameter in operation.Parameters) | ||
{ | ||
if (parameter.NameInRequest.Equals("subscriptionId", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
// Always set subscriptionId to method parameter | ||
parameters.Add(new InputParameter(parameter.Name, parameter.NameInRequest, parameter.Summary, parameter.Doc, parameter.Type, parameter.Location, parameter.DefaultValue, InputOperationParameterKind.Method, parameter.IsRequired, parameter.IsApiVersion, parameter.IsResourceParameter, parameter.IsContentType, parameter.IsEndpoint, parameter.SkipUrlEncoding, parameter.Explode, parameter.ArraySerializationDelimiter, parameter.HeaderCollectionPrefix)); | ||
} | ||
else | ||
{ | ||
parameters.Add(parameter); | ||
} | ||
} | ||
return parameters; | ||
} | ||
} | ||
} |
17 changes: 9 additions & 8 deletions
17
...client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.RestClient.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 5 additions & 4 deletions
9
...sharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.RestClient.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.