Skip to content

Commit

Permalink
Populate client description (#6117)
Browse files Browse the repository at this point in the history
Fixes #6116
  • Loading branch information
JoshLove-msft authored Feb 24, 2025
1 parent f523b08 commit f90c2d7
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.TypeSpec.Generator.Providers;
using Microsoft.TypeSpec.Generator.Snippets;
using Microsoft.TypeSpec.Generator.Statements;
using Microsoft.TypeSpec.Generator.Utilities;
using static Microsoft.TypeSpec.Generator.Snippets.Snippet;

namespace Microsoft.TypeSpec.Generator.ClientModel.Providers
Expand Down Expand Up @@ -48,6 +49,8 @@ private record OAuth2Fields(FieldProvider AuthField, FieldProvider Authorization

private Lazy<ParameterProvider?> ClientOptionsParameter { get; }

protected override FormattableString Description { get; }

// for mocking
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
protected ClientProvider()
Expand All @@ -63,6 +66,7 @@ public ClientProvider(InputClient inputClient)
_publicCtorDescription = $"Initializes a new instance of {Name}.";
ClientOptions = new Lazy<ClientOptionsProvider?>(() => _inputClient.Parent is null ? new ClientOptionsProvider(_inputClient, this) : null);
ClientOptionsParameter = new Lazy<ParameterProvider?>(() => ClientOptions.Value != null ? ScmKnownParameters.ClientOptions(ClientOptions.Value.Type) : null);
Description = DocHelpers.GetFormattableDescription(_inputClient.Summary, _inputClient.Doc) ?? FormattableStringHelpers.Empty;

var apiKey = _inputAuth?.ApiKey;
var keyCredentialType = ScmCodeModelPlugin.Instance.TypeFactory.ClientPipelineApi.KeyCredentialType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,18 @@ public void NullClientProviderIsNotAddedToLibrary()
Assert.IsEmpty(plugin.Object.OutputLibrary.TypeProviders.OfType<ClientProvider>());
}

[TestCase]
public void ClientProviderSummaryIsPopulated()
{
var plugin = MockHelpers.LoadMockPlugin(
clients: () => [InputFactory.Client("test", clientNamespace: "test", doc: "client description")]);

var client = plugin.Object.OutputLibrary.TypeProviders.OfType<ClientProvider>().SingleOrDefault();
Assert.IsNotNull(client);

Assert.AreEqual("/// <summary> client description. </summary>\n", client!.XmlDocs.Summary!.ToDisplayString());
}

private static InputClient GetEnumQueryParamClient()
=> InputFactory.Client(
TestClientName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Sample
{
/// <summary></summary>
/// <summary> TestClient description. </summary>
public partial class TestClient
{
/// <summary> Initializes a new instance of Animal. </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Sample
{
/// <summary></summary>
/// <summary> AnimalClient description. </summary>
public partial class Animal
{
/// <summary> Initializes a new instance of Dog. </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Sample
{
/// <summary></summary>
/// <summary> DogClient description. </summary>
public partial class Dog
{
/// <summary> Initializes a new instance of Husky. </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Sample
{
/// <summary></summary>
/// <summary> TestClient description. </summary>
public partial class TestClient
{
internal TestClient(global::System.Uri endpoint) : this(endpoint, new global::Sample.TestClientOptions())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Sample
{
/// <summary></summary>
/// <summary> TestClient description. </summary>
public partial class TestClient
{
public virtual global::System.ClientModel.ClientResult Operation(global::Sample.Models.InputEnum queryParam, global::System.Threading.CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Sample
{
/// <summary></summary>
/// <summary> TestClient description. </summary>
public partial class TestClient
{
public virtual async global::System.Threading.Tasks.Task<global::System.ClientModel.ClientResult> OperationAsync(global::Sample.Models.InputEnum queryParam, global::System.Threading.CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace UnbrandedTypeSpec
{
/// <summary></summary>
/// <summary> This is a sample typespec project. </summary>
public partial class UnbrandedTypeSpecClient
{
private readonly Uri _endpoint;
Expand Down

0 comments on commit f90c2d7

Please sign in to comment.