From 75b432d03260cba531e61b1b585e2b627537ae4e Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Wed, 26 Feb 2025 09:03:44 +0000 Subject: [PATCH] CodeGen from PR 31398 in Azure/azure-rest-api-specs Merge 4278934e7073d84fc8da9a6e81dae3b5678a2acd into 88e8a93c6eb6b1c36a56568d22ca12a78c5a48b0 --- .../api/Azure.Messaging.WebPubSub.net8.0.cs | 9 + ...zure.Messaging.WebPubSub.netstandard2.0.cs | 9 + .../src/Generated/Docs/WebPubSubClient.xml | 53 ++++++ .../src/Generated/WebPubSubClient.cs | 164 ++++++++++++++++++ .../Azure.Messaging.WebPubSub/src/autorest.md | 5 +- .../Samples/Samples_WebPubSubClient.cs | 72 ++++++++ 6 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Docs/WebPubSubClient.xml create mode 100644 sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubClient.cs create mode 100644 sdk/webpubsub/Azure.Messaging.WebPubSub/tests/Generated/Samples/Samples_WebPubSubClient.cs diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.net8.0.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.net8.0.cs index b25c8a36916f..57edb47c41e6 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.net8.0.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.net8.0.cs @@ -5,6 +5,15 @@ public static partial class ClientConnectionFilter public static string Create(System.FormattableString filter) { throw null; } public static string Create(System.FormattableString filter, System.IFormatProvider formatProvider) { throw null; } } + public partial class WebPubSubClient + { + protected WebPubSubClient() { } + public WebPubSubClient(string endpoint) { } + public WebPubSubClient(string endpoint, Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions options) { } + public virtual Azure.Core.Pipeline.HttpPipeline Pipeline { get { throw null; } } + public virtual Azure.Pageable GetConnectionsInGroups(string hub, string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null, Azure.RequestContext context = null) { throw null; } + public virtual Azure.AsyncPageable GetConnectionsInGroupsAsync(string hub, string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null, Azure.RequestContext context = null) { throw null; } + } public enum WebPubSubClientProtocol { Default = 0, diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.netstandard2.0.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.netstandard2.0.cs index b25c8a36916f..57edb47c41e6 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.netstandard2.0.cs +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/api/Azure.Messaging.WebPubSub.netstandard2.0.cs @@ -5,6 +5,15 @@ public static partial class ClientConnectionFilter public static string Create(System.FormattableString filter) { throw null; } public static string Create(System.FormattableString filter, System.IFormatProvider formatProvider) { throw null; } } + public partial class WebPubSubClient + { + protected WebPubSubClient() { } + public WebPubSubClient(string endpoint) { } + public WebPubSubClient(string endpoint, Azure.Messaging.WebPubSub.WebPubSubServiceClientOptions options) { } + public virtual Azure.Core.Pipeline.HttpPipeline Pipeline { get { throw null; } } + public virtual Azure.Pageable GetConnectionsInGroups(string hub, string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null, Azure.RequestContext context = null) { throw null; } + public virtual Azure.AsyncPageable GetConnectionsInGroupsAsync(string hub, string group, int? maxpagesize = default(int?), int? maxCount = default(int?), string continuationToken = null, Azure.RequestContext context = null) { throw null; } + } public enum WebPubSubClientProtocol { Default = 0, diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Docs/WebPubSubClient.xml b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Docs/WebPubSubClient.xml new file mode 100644 index 000000000000..405f84576ae5 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Docs/WebPubSubClient.xml @@ -0,0 +1,53 @@ + + + + + +This sample shows how to call GetConnectionsInGroupsAsync and parse the result. +"); + +await foreach (BinaryData item in client.GetConnectionsInGroupsAsync("", "")) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); +} +]]> +This sample shows how to call GetConnectionsInGroupsAsync with all parameters and parse the result. +"); + +await foreach (BinaryData item in client.GetConnectionsInGroupsAsync("", "", maxpagesize: 1234, maxCount: 1234, continuationToken: "")) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); + Console.WriteLine(result.GetProperty("userId").ToString()); +} +]]> + + + +This sample shows how to call GetConnectionsInGroups and parse the result. +"); + +foreach (BinaryData item in client.GetConnectionsInGroups("", "")) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); +} +]]> +This sample shows how to call GetConnectionsInGroups with all parameters and parse the result. +"); + +foreach (BinaryData item in client.GetConnectionsInGroups("", "", maxpagesize: 1234, maxCount: 1234, continuationToken: "")) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); + Console.WriteLine(result.GetProperty("userId").ToString()); +} +]]> + + + \ No newline at end of file diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubClient.cs new file mode 100644 index 000000000000..feea197e1bfd --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubClient.cs @@ -0,0 +1,164 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Autorest.CSharp.Core; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.Messaging.WebPubSub +{ + // Data plane generated client. + /// The WebPubSub service client. + public partial class WebPubSubClient + { + private readonly HttpPipeline _pipeline; + private readonly string _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of WebPubSubClient for mocking. + protected WebPubSubClient() + { + } + + /// Initializes a new instance of WebPubSubClient. + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// is null. + public WebPubSubClient(string endpoint) : this(endpoint, new WebPubSubServiceClientOptions()) + { + } + + /// Initializes a new instance of WebPubSubClient. + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// The options for configuring the client. + /// is null. + public WebPubSubClient(string endpoint, WebPubSubServiceClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + options ??= new WebPubSubServiceClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), Array.Empty(), new ResponseClassifier()); + _endpoint = endpoint; + _apiVersion = options.Version; + } + + /// + /// [Protocol Method] List connections in a group. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore. + /// Target group name, whose length should be greater than 0 and less than 1025. + /// The maximum number of connections to include in a single response. It should be between 1 and 200. + /// The maximum number of connections to return. If the value is not set, then all the connections in a group are returned. + /// A token that allows the client to retrieve the next page of results. This parameter is provided by the service in the response of a previous request when there are additional results to be fetched. Clients should include the continuationToken in the next request to receive the subsequent page of data. If this parameter is omitted, the server will return the first page of results. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The from the service containing a list of objects. Details of the body schema for each item in the collection are in the Remarks section below. + /// + public virtual AsyncPageable GetConnectionsInGroupsAsync(string hub, string group, int? maxpagesize = null, int? maxCount = null, string continuationToken = null, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(hub, nameof(hub)); + Argument.AssertNotNullOrEmpty(group, nameof(group)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetConnectionsInGroupsRequest(hub, group, pageSizeHint, maxCount, continuationToken, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetConnectionsInGroupsNextPageRequest(nextLink, hub, group, pageSizeHint, maxCount, continuationToken, context); + return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "WebPubSubClient.GetConnectionsInGroups", "value", "nextLink", maxpagesize, context); + } + + /// + /// [Protocol Method] List connections in a group. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore. + /// Target group name, whose length should be greater than 0 and less than 1025. + /// The maximum number of connections to include in a single response. It should be between 1 and 200. + /// The maximum number of connections to return. If the value is not set, then all the connections in a group are returned. + /// A token that allows the client to retrieve the next page of results. This parameter is provided by the service in the response of a previous request when there are additional results to be fetched. Clients should include the continuationToken in the next request to receive the subsequent page of data. If this parameter is omitted, the server will return the first page of results. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The from the service containing a list of objects. Details of the body schema for each item in the collection are in the Remarks section below. + /// + public virtual Pageable GetConnectionsInGroups(string hub, string group, int? maxpagesize = null, int? maxCount = null, string continuationToken = null, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(hub, nameof(hub)); + Argument.AssertNotNullOrEmpty(group, nameof(group)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetConnectionsInGroupsRequest(hub, group, pageSizeHint, maxCount, continuationToken, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetConnectionsInGroupsNextPageRequest(nextLink, hub, group, pageSizeHint, maxCount, continuationToken, context); + return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "WebPubSubClient.GetConnectionsInGroups", "value", "nextLink", maxpagesize, context); + } + + internal HttpMessage CreateGetConnectionsInGroupsRequest(string hub, string group, int? maxpagesize, int? maxCount, string continuationToken, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(_endpoint, false); + uri.AppendPath("/api/hubs/", false); + uri.AppendPath(hub, true); + uri.AppendPath("/groups/", false); + uri.AppendPath(group, true); + uri.AppendPath("/connections", false); + if (maxpagesize != null) + { + uri.AppendQuery("maxpagesize", maxpagesize.Value, true); + } + if (maxCount != null) + { + uri.AppendQuery("top", maxCount.Value, true); + } + if (continuationToken != null) + { + uri.AppendQuery("continuationToken", continuationToken, true); + } + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateGetConnectionsInGroupsNextPageRequest(string nextLink, string hub, string group, int? maxpagesize, int? maxCount, string continuationToken, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(_endpoint, false); + uri.AppendRawNextLink(nextLink, false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/autorest.md b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/autorest.md index 576a2507a5a4..f340bf66a03f 100644 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/autorest.md +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/autorest.md @@ -8,8 +8,8 @@ Run `dotnet build /t:GenerateCode` to generate code. ## Swagger Source(s) ``` yaml title: WebPubSubServiceClient -input-file: -- https://github.com/Azure/azure-rest-api-specs/blob/356aa5174e8eec6ed904bf5ff104595aec8c0411/specification/webpubsub/data-plane/WebPubSub/stable/2024-01-01/webpubsub.json +require: +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/webpubsub/data-plane/readme.md credential-types: AzureKeyCredential credential-header-name: Ocp-Apim-Subscription-Key @@ -345,3 +345,4 @@ directive: where: $.paths["/api/hubs/{hub}/connections/{connectionId}/groups"].delete.parameters["0"] transform: $["x-ms-parameter-location"] = "client" ``` + diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/tests/Generated/Samples/Samples_WebPubSubClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/tests/Generated/Samples/Samples_WebPubSubClient.cs new file mode 100644 index 000000000000..3a17a0746628 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/tests/Generated/Samples/Samples_WebPubSubClient.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure.Identity; +using NUnit.Framework; + +namespace Azure.Messaging.WebPubSub.Samples +{ + public partial class Samples_WebPubSubClient + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetConnectionsInGroups_ShortVersion() + { + WebPubSubClient client = new WebPubSubClient(""); + + foreach (BinaryData item in client.GetConnectionsInGroups("", "")) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetConnectionsInGroups_ShortVersion_Async() + { + WebPubSubClient client = new WebPubSubClient(""); + + await foreach (BinaryData item in client.GetConnectionsInGroupsAsync("", "")) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetConnectionsInGroups_AllParameters() + { + WebPubSubClient client = new WebPubSubClient(""); + + foreach (BinaryData item in client.GetConnectionsInGroups("", "", maxpagesize: 1234, maxCount: 1234, continuationToken: "")) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); + Console.WriteLine(result.GetProperty("userId").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetConnectionsInGroups_AllParameters_Async() + { + WebPubSubClient client = new WebPubSubClient(""); + + await foreach (BinaryData item in client.GetConnectionsInGroupsAsync("", "", maxpagesize: 1234, maxCount: 1234, continuationToken: "")) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("connectionId").ToString()); + Console.WriteLine(result.GetProperty("userId").ToString()); + } + } + } +}