-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mgmt rest client #47665
base: main
Are you sure you want to change the base?
Mgmt rest client #47665
Changes from all commits
2c5351d
9d305ae
c78439d
ca523dd
203e7d9
860640c
c86a873
6cc79ab
bd478d1
42da174
4a9abc1
1f92b65
f031280
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} | ||
} |
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 and type as string | ||
parameters.Add(new InputParameter(parameter.Name, parameter.NameInRequest, parameter.Summary, parameter.Doc, InputPrimitiveType.String, parameter.Location, parameter.DefaultValue, InputOperationParameterKind.Method, parameter.IsRequired, parameter.IsApiVersion, parameter.IsResourceParameter, parameter.IsContentType, parameter.IsEndpoint, parameter.SkipUrlEncoding, parameter.Explode, parameter.ArraySerializationDelimiter, parameter.HeaderCollectionPrefix)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need to change the type of subscriptionId back to string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not quite following here, change subscriptionId type will break the public contract. |
||
} | ||
else | ||
{ | ||
parameters.Add(parameter); | ||
} | ||
} | ||
return parameters; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make both client and restclient internal, all the models referenced will be internalized during the postprocess.
Once we have the resource and collection in place, public reference will be in place and the referenced models will be kept public.
So, keep restclient public for now to make the referenced models public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we put this comment as a comment in the code? just in case we could remember it and enable this piece in the future when we have the resource/collection types to keep those models public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added TODO