diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 83330bdf54..c11b8f2803 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -56,3 +56,17 @@ jobs: config: '.markdownlint.json' globs: | **/*.md + + - name: Setup Node + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: '24.x' + + - name: Install Spectral + run: npm install --global "@stoplight/spectral-cli@${SPECTRAL_VERSION}" + env: + # renovate: datasource=npm packageName=@stoplight/spectral-cli + SPECTRAL_VERSION: '6.15.0' + + - name: Run Spectral + run: spectral lint "./test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/*" --display-only-failures --fail-severity error --format github-actions diff --git a/.spectral.yaml b/.spectral.yaml new file mode 100644 index 0000000000..7d9855d6a6 --- /dev/null +++ b/.spectral.yaml @@ -0,0 +1 @@ +extends: ['spectral:oas'] diff --git a/Directory.Packages.props b/Directory.Packages.props index 499bc1f00a..1b60a12dfd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -15,6 +15,7 @@ + @@ -22,6 +23,7 @@ + diff --git a/Swashbuckle.AspNetCore.slnx b/Swashbuckle.AspNetCore.slnx index 4e75d24a73..5ba846053c 100644 --- a/Swashbuckle.AspNetCore.slnx +++ b/Swashbuckle.AspNetCore.slnx @@ -77,6 +77,7 @@ + diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs index f76d8cfd9a..acc20e3d70 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs @@ -66,22 +66,10 @@ private IOpenApiSchema GenerateSchemaForMember( { var requiredAttribute = customAttributes.OfType().FirstOrDefault(); - var nullable = IsNullable(requiredAttribute, dataProperty, memberInfo); - - if (usingAllOf) - { - // When using AllOf to extend reference schemas, we need to adjust the schema to represent - // nullability correctly as a property can't be null AND a specific type at the same time. - // See https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/3649. - if (nullable) - { - concrete.OneOf = schema.AllOf; - concrete.OneOf.Add(new OpenApiSchema { Type = JsonSchemaType.Null }); - concrete.AllOf = null; - } - } - else + // "nullable" cannot be used without "type" + if (!usingAllOf) { + var nullable = IsNullable(requiredAttribute, dataProperty, memberInfo); SetNullable(concrete, nullable); } diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/ClientGenerator.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/ClientGenerator.cs index 6748caf788..2bc79a1f29 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/ClientGenerator.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/ClientGenerator.cs @@ -73,22 +73,30 @@ public async Task CompileAsync(string location) public async Task GenerateFromStringAsync(ClientGeneratorTool generator, string openApiDocument) { - TemporaryDirectory project; + TemporaryDirectory project = null; - switch (generator) + try + { + switch (generator) + { + case ClientGeneratorTool.Kiota: + project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]); + await GenerateClientFromStringWithKiotaAsync(project.Path, openApiDocument, outputHelper); + break; + + case ClientGeneratorTool.NSwag: + project = await GenerateProjectAsync(["Newtonsoft.Json"]); + await GenerateClientFromStringWithNSwagAsync(project.Path, openApiDocument); + break; + + default: + throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported."); + } + } + catch (Exception) { - case ClientGeneratorTool.Kiota: - project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]); - await GenerateClientFromStringWithKiotaAsync(project.Path, openApiDocument, outputHelper); - break; - - case ClientGeneratorTool.NSwag: - project = await GenerateProjectAsync(["Newtonsoft.Json"]); - await GenerateClientFromStringWithNSwagAsync(project.Path, openApiDocument); - break; - - default: - throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported."); + project?.Dispose(); + throw; } return project; @@ -96,22 +104,30 @@ public async Task GenerateFromStringAsync(ClientGeneratorToo public async Task GenerateFromUrlAsync(ClientGeneratorTool generator, string openApiDocumentUrl) { - TemporaryDirectory project; + TemporaryDirectory project = null; - switch (generator) + try + { + switch (generator) + { + case ClientGeneratorTool.Kiota: + project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]); + await GenerateClientFromUrlWithKiotaAsync(project.Path, openApiDocumentUrl, outputHelper); + break; + + case ClientGeneratorTool.NSwag: + project = await GenerateProjectAsync(["Newtonsoft.Json"]); + await GenerateClientFromUrlWithNSwagAsync(project.Path, openApiDocumentUrl); + break; + + default: + throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported."); + } + } + catch (Exception) { - case ClientGeneratorTool.Kiota: - project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]); - await GenerateClientFromUrlWithKiotaAsync(project.Path, openApiDocumentUrl, outputHelper); - break; - - case ClientGeneratorTool.NSwag: - project = await GenerateProjectAsync(["Newtonsoft.Json"]); - await GenerateClientFromUrlWithNSwagAsync(project.Path, openApiDocumentUrl); - break; - - default: - throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported."); + project?.Dispose(); + throw; } return project; @@ -283,7 +299,7 @@ private static string GetNuGetPackageVersion(string name) var ns = project.Root.GetDefaultNamespace(); var version = project - .Root? + .Root .Elements(ns + "ItemGroup") .Elements(ns + "PackageVersion") .Select((p) => diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/CodeGenerationTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/CodeGenerationTests.cs index d79992ee1a..1c556d9279 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/CodeGenerationTests.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/CodeGenerationTests.cs @@ -1,8 +1,14 @@ #if NET10_0_OR_GREATER using System.Reflection; -using System.Text.Json; +using System.Security.Cryptography; +using System.Text; +using Microsoft.AspNetCore.Http; +using Microsoft.Kiota.Abstractions.Authentication; +using Microsoft.Kiota.Http.HttpClientLibrary; using Microsoft.OpenApi; +using TodoApp.Client; +using TodoApp.Client.Models; namespace Swashbuckle.AspNetCore.IntegrationTests; @@ -15,28 +21,17 @@ public static TheoryData SnapshotTestCases() { var testCases = new TheoryData(); - foreach (var path in Directory.EnumerateFiles(Path.Combine(GetProjectRoot(), "snapshots"), "*.txt", SearchOption.AllDirectories)) + foreach (var testCase in SnapshotTestData.Snapshots()) { + var path = testCase.Data.Item1; + var documentVersion = testCase.Data.Item2; + // Deduplicate by ignoring snapshots for other TFMs if (!path.EndsWith(".DotNet10_0.verified.txt", StringComparison.Ordinal)) { continue; } - using var snapshot = File.OpenRead(path); - using var document = JsonDocument.Parse(snapshot); - - if (!document.RootElement.TryGetProperty("openapi", out var property) && - !document.RootElement.TryGetProperty("swagger", out property)) - { - continue; - } - - if (!Version.TryParse(property.GetString(), out var documentVersion)) - { - continue; - } - var version = documentVersion switch { { Major: 2 } => OpenApiSpecVersion.OpenApi2_0, @@ -65,16 +60,284 @@ public static TheoryData SnapshotTestCases() [Theory] [MemberData(nameof(SnapshotTestCases))] - public async Task OpenApiDocument_Generates_Valid_Client_Code_From_Snapshot(ClientGeneratorTool tool, string path) + public async Task GeneratesValidClient(ClientGeneratorTool tool, string snapshot) { // Arrange var generator = new ClientGenerator(outputHelper); - var document = await File.ReadAllTextAsync(path, TestContext.Current.CancellationToken); + var snapshotPath = Path.Combine(SnapshotTestData.SnapshotsPath(), snapshot); + + var document = await File.ReadAllTextAsync(snapshotPath, TestContext.Current.CancellationToken); using var project = await generator.GenerateFromStringAsync(tool, document); // Act and Assert await generator.CompileAsync(project.Path); + + var hash = SHA256.HashData(Encoding.UTF8.GetBytes($"{tool}:{snapshot}")); + var hashString = Convert.ToHexString(hash).ToLowerInvariant()[..16]; + + outputHelper.WriteLine($"{nameof(tool)}={tool}, {nameof(snapshot)}={snapshot} [{hashString}]"); + + await VerifyDirectory( + project.Path, + pattern: "*.cs", + include: (p) => !p.Contains("bin") && !p.Contains("obj"), + options: new() { RecurseSubdirectories = true }) + .UseDirectory("snapshots") + .UseFileName($"{nameof(GeneratesValidClient)}_{hashString}"); + } + + [Fact] + public async Task Can_Manage_Todo_Items_With_Api() + { + // Arrange + await WithTodoAppClientAsync(async (client) => + { + var cancellationToken = TestContext.Current.CancellationToken; + + // Act - Get all the items + var items = await client.Api.Items.GetAsync(cancellationToken: cancellationToken); + + // Assert - There should be no items + Assert.NotNull(items); + Assert.NotNull(items.Items); + + var beforeCount = items.Items.Count; + + // Arrange + var text = "Buy eggs"; + + // Act - Add a new item + var createdItem = await client.Api.Items.PostAsync( + new() { Text = text }, + cancellationToken: cancellationToken); + + // Assert - An item was created + Assert.NotNull(createdItem); + Assert.NotEqual(default, createdItem.Id); + + // Arrange - Get the new item's URL and Id + var itemId = createdItem.Id; + + // Act - Get the item + var item = await client.Api.Items[new(itemId)].GetAsync(cancellationToken: cancellationToken); + + // Assert - Verify the item was created correctly + Assert.NotNull(item); + Assert.Equal(itemId, item.Id); + Assert.Null(item.CompletedAt); + Assert.NotEqual(default, item.CreatedAt); + Assert.Equal(item.CreatedAt.Value, item.LastUpdated); + Assert.Null(item.Priority); + Assert.Equal(text, item.Text); + + // Act - Update the item to be high priority + await client.Api.Items[new(itemId)].Priority.PatchAsync( + new() { Priority = TodoPriority.High }, + cancellationToken: cancellationToken); + + item = await client.Api.Items[new(itemId)].GetAsync(cancellationToken: cancellationToken); + + Assert.NotNull(item); + Assert.Equal(itemId, item.Id); + Assert.Null(item.CompletedAt); + Assert.NotEqual(default, item.CreatedAt); + Assert.Equal(item.CreatedAt.Value, item.LastUpdated); + Assert.Equal(TodoPriority.High, item.Priority); + Assert.Equal(text, item.Text); + + // Act - Mark the item as being completed + await client.Api.Items[new(itemId)].Complete.PostAsync(cancellationToken: cancellationToken); + + item = await client.Api.Items[new(itemId)].GetAsync(cancellationToken: cancellationToken); + + Assert.NotNull(item); + Assert.Equal(itemId, item.Id); + Assert.Equal(text, item.Text); + Assert.NotNull(item.CompletedAt); + Assert.Equal(item.CompletedAt.Value, item.LastUpdated); + Assert.True(item.CompletedAt.Value > item.CreatedAt); + + // Act - Get all the items + items = await client.Api.Items.GetAsync(cancellationToken: cancellationToken); + + // Assert - The item was completed + Assert.NotNull(items); + Assert.NotNull(items.Items); + Assert.Equal(beforeCount + 1, items.Items.Count); + Assert.Contains(items.Items, (x) => x.Id == itemId); + + item = items.Items.Last(); + + Assert.NotNull(item); + Assert.Equal(itemId, item.Id); + Assert.Equal(text, item.Text); + Assert.NotNull(item.CompletedAt); + Assert.Equal(item.CompletedAt.Value, item.LastUpdated); + Assert.True(item.CompletedAt.Value > item.CreatedAt); + + // Act - Delete the item + await client.Api.Items[new(itemId)].DeleteAsync(cancellationToken: cancellationToken); + + // Assert - The item no longer exists + items = await client.Api.Items.GetAsync(cancellationToken: cancellationToken); + + Assert.NotNull(items); + Assert.NotNull(items.Items); + Assert.Equal(beforeCount, items.Items.Count); + Assert.DoesNotContain(items.Items, (x) => x.Id == itemId); + + // Act + var problem = await Assert.ThrowsAsync( + () => client.Api.Items[new(itemId)].GetAsync(cancellationToken: cancellationToken)); + + // Assert + Assert.NotNull(problem); + Assert.Equal(StatusCodes.Status404NotFound, problem.Status); + Assert.Equal("Not Found", problem.Title); + Assert.Equal("Item not found.", problem.Detail); + Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problem.Type); + Assert.Null(problem.Instance); + + // Act + problem = await Assert.ThrowsAsync( + () => client.Api.Items[new(itemId)].Complete.PostAsync(cancellationToken: cancellationToken)); + + // Assert + Assert.NotNull(problem); + Assert.Equal(StatusCodes.Status404NotFound, problem.Status); + Assert.Equal("Not Found", problem.Title); + Assert.Equal("Item not found.", problem.Detail); + Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problem.Type); + Assert.Null(problem.Instance); + + // Act + problem = await Assert.ThrowsAsync( + () => client.Api.Items[new(itemId)].Priority.PatchAsync(new() { Priority = TodoPriority.Low }, cancellationToken: cancellationToken)); + + // Assert + Assert.NotNull(problem); + Assert.Equal(StatusCodes.Status404NotFound, problem.Status); + Assert.Equal("Not Found", problem.Title); + Assert.Equal("Item not found.", problem.Detail); + Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problem.Type); + Assert.Null(problem.Instance); + }); + } + + [Fact] + public async Task Cannot_Create_Todo_Item_With_No_Text() + { + // Arrange + await WithTodoAppClientAsync(async (client) => + { + var cancellationToken = TestContext.Current.CancellationToken; + + // Act + var problem = await Assert.ThrowsAsync( + () => client.Api.Items.PostAsync(new() { Text = string.Empty }, cancellationToken: cancellationToken)); + + // Assert + Assert.NotNull(problem); + Assert.Equal(StatusCodes.Status400BadRequest, problem.Status); + Assert.Equal("Bad Request", problem.Title); + Assert.Equal("No item text specified.", problem.Detail); + Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.1", problem.Type); + Assert.Null(problem.Instance); + }); + } + + [Fact] + public async Task Cannot_Complete_Todo_Item_Multiple_Times() + { + // Arrange + await WithTodoAppClientAsync(async (client) => + { + var cancellationToken = TestContext.Current.CancellationToken; + + var createdItem = await client.Api.Items.PostAsync( + new() { Text = "Something" }, + cancellationToken: cancellationToken); + + await client.Api.Items[new(createdItem.Id)].Complete.PostAsync(cancellationToken: cancellationToken); + + // Act + var problem = await Assert.ThrowsAsync( + () => client.Api.Items[new(createdItem.Id)].Complete.PostAsync(cancellationToken: cancellationToken)); + + // Assert + Assert.NotNull(problem); + Assert.Equal(StatusCodes.Status400BadRequest, problem.Status); + Assert.Equal("Bad Request", problem.Title); + Assert.Equal("Item already completed.", problem.Detail); + Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.1", problem.Type); + Assert.Null(problem.Instance); + }); + } + + [Fact] + public async Task Cannot_Complete_Deleted_Todo_Item() + { + // Arrange + await WithTodoAppClientAsync(async (client) => + { + var cancellationToken = TestContext.Current.CancellationToken; + + var createdItem = await client.Api.Items.PostAsync( + new() { Text = "Something" }, + cancellationToken: cancellationToken); + + await client.Api.Items[new(createdItem.Id)].DeleteAsync(cancellationToken: cancellationToken); + + // Act + var problem = await Assert.ThrowsAsync( + () => client.Api.Items[new(createdItem.Id)].Complete.PostAsync(cancellationToken: cancellationToken)); + + // Assert + Assert.NotNull(problem); + Assert.Equal(StatusCodes.Status404NotFound, problem.Status); + Assert.Equal("Not Found", problem.Title); + Assert.Equal("Item not found.", problem.Detail); + Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problem.Type); + Assert.Null(problem.Instance); + }); + } + + [Fact] + public async Task Cannot_Delete_Todo_Item_Multiple_Times() + { + // Arrange + await WithTodoAppClientAsync(async (client) => + { + var cancellationToken = TestContext.Current.CancellationToken; + + var createdItem = await client.Api.Items.PostAsync( + new() { Text = "Something" }, + cancellationToken: cancellationToken); + + await client.Api.Items[new(createdItem.Id)].DeleteAsync(cancellationToken: cancellationToken); + + // Act + var problem = await Assert.ThrowsAsync( + () => client.Api.Items[new(createdItem.Id)].DeleteAsync(cancellationToken: cancellationToken)); + + // Assert + Assert.NotNull(problem); + Assert.Equal(StatusCodes.Status404NotFound, problem.Status); + Assert.Equal("Not Found", problem.Title); + Assert.Equal("Item not found.", problem.Detail); + Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problem.Type); + Assert.Null(problem.Instance); + }); + } + + [Fact] + public async Task VerifyKiotaTodoAppClient() + { + await VerifyDirectory( + Path.Combine(GetProjectRoot(), "TodoClient"), + pattern: "*.cs", + options: new() { RecurseSubdirectories = true }).UseDirectory("snapshots"); } private static string GetProjectRoot() => @@ -82,6 +345,18 @@ private static string GetProjectRoot() => .GetCustomAttributes() .First((p) => p.Key is "ProjectRoot") .Value!; + + private static async Task WithTodoAppClientAsync(Func callback) + { + using var httpClient = SwaggerIntegrationTests.GetHttpClientForTestApplication(typeof(TodoApp.Program)); + + var provider = new AnonymousAuthenticationProvider(); + using var request = new HttpClientRequestAdapter(provider, httpClient: httpClient); + + var client = new TodoApiClient(request); + + await callback(client); + } } #endif diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SchemaTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SchemaTests.cs new file mode 100644 index 0000000000..38f9a8b083 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SchemaTests.cs @@ -0,0 +1,27 @@ +using NJsonSchema; + +namespace Swashbuckle.AspNetCore.IntegrationTests; + +public class SchemaTests +{ + [Theory] + [MemberData(nameof(SnapshotTestData.Snapshots), MemberType = typeof(SnapshotTestData))] + public async Task OpenApiDocumentsAreValid(string snapshot, Version version) + { + // Arrange + var cancellationToken = TestContext.Current.CancellationToken; + + var schemaPath = Path.Combine(SnapshotTestData.SchemasPath(), $"schema.{version.Major}.{version.Minor}.json"); + var snapshotPath = Path.Combine(SnapshotTestData.SnapshotsPath(), snapshot); + + var schema = await JsonSchema.FromFileAsync(schemaPath, cancellationToken); + var specification = await File.ReadAllTextAsync(snapshotPath, cancellationToken); + + // Act + var actual = schema.Validate(specification); + + // Assert + Assert.NotNull(actual); + Assert.Empty(actual); + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SnapshotTestData.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SnapshotTestData.cs new file mode 100644 index 0000000000..d4dc311a0a --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SnapshotTestData.cs @@ -0,0 +1,46 @@ +using System.Reflection; +using System.Text.Json; + +namespace Swashbuckle.AspNetCore.IntegrationTests; + +public static class SnapshotTestData +{ + private static string _projectRoot = + typeof(SnapshotTestData).Assembly + .GetCustomAttributes() + .First((p) => p.Key is "ProjectRoot") + .Value!; + + public static string SnapshotsPath() => Path.Combine(_projectRoot, "snapshots"); + + public static string SchemasPath() => Path.Combine(_projectRoot, "schemas"); + + public static TheoryData Snapshots() + { + var testCases = new TheoryData(); + var snapshotsPath = Path.Combine(_projectRoot, "snapshots"); + + foreach (var path in Directory.EnumerateFiles(snapshotsPath, "*.txt", SearchOption.AllDirectories)) + { + using var snapshot = File.OpenRead(path); + using var document = JsonDocument.Parse(snapshot); + + if (!document.RootElement.TryGetProperty("openapi", out var property) && + !document.RootElement.TryGetProperty("swagger", out property)) + { + continue; + } + + if (!Version.TryParse(property.GetString(), out var version)) + { + continue; + } + + var relativePath = Path.GetRelativePath(snapshotsPath, path); + + testCases.Add(relativePath, version); + } + + return testCases; + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs index d992e8261e..bba415e2ef 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs @@ -117,6 +117,7 @@ public async Task SwaggerMiddleware_CanBeConfiguredMultipleTimes( [InlineData(typeof(MinimalApp.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(MinimalAppWithNullableEnums.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(MvcWithNullable.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(TodoApp.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")] [InlineData(typeof(WebApi.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(WebApi.Aot.Program), "/swagger/v1/swagger.json")] diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj b/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj index a963d5d5eb..c77f8cbb1a 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj @@ -17,21 +17,27 @@ + + - + - + + + + + diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/ApiRequestBuilder.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/ApiRequestBuilder.cs new file mode 100644 index 0000000000..41b43725aa --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/ApiRequestBuilder.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +using TodoApp.Client.Api.Items; +namespace TodoApp.Client.Api +{ + /// + /// Builds and executes requests for operations under \api + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ApiRequestBuilder : BaseRequestBuilder + { + /// The items property + public global::TodoApp.Client.Api.Items.ItemsRequestBuilder Items + { + get => new global::TodoApp.Client.Api.Items.ItemsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Find/FindRequestBuilder.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Find/FindRequestBuilder.cs new file mode 100644 index 0000000000..88a9b963c9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Find/FindRequestBuilder.cs @@ -0,0 +1,94 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Find +{ + /// + /// Builds and executes requests for operations under \api\items\find + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FindRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FindRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/find?IsCompleted={IsCompleted}&Text={Text}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FindRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/find?IsCompleted={IsCompleted}&Text={Text}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Find.FindRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Find.FindRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class FindRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + /// Gets or sets a value indicating whether to search completed Todo items. + public bool? IsCompleted { get; set; } + /// Gets or sets the text of the filter. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/GetAfter/GetAfterRequestBuilder.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/GetAfter/GetAfterRequestBuilder.cs new file mode 100644 index 0000000000..08a2cd13ad --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/GetAfter/GetAfterRequestBuilder.cs @@ -0,0 +1,86 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.GetAfter +{ + /// + /// Builds and executes requests for operations under \api\items\getAfter + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class GetAfterRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public GetAfterRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/getAfter?value={value}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public GetAfterRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/getAfter?value={value}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class GetAfterRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + [QueryParameter("value")] + public DateTimeOffset? Value { get; set; } + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/Complete/CompleteRequestBuilder.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/Complete/CompleteRequestBuilder.cs new file mode 100644 index 0000000000..d60b464e51 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/Complete/CompleteRequestBuilder.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Item.Complete +{ + /// + /// Builds and executes requests for operations under \api\items\{id}\complete + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CompleteRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CompleteRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/complete", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CompleteRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/complete", rawUrl) + { + } + /// + /// Marks the todo item with the specified ID as complete. + /// + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToPostRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Marks the todo item with the specified ID as complete. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/ItemsItemRequestBuilder.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/ItemsItemRequestBuilder.cs new file mode 100644 index 0000000000..7a7d75d5df --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/ItemsItemRequestBuilder.cs @@ -0,0 +1,142 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Api.Items.Item.Complete; +using TodoApp.Client.Api.Items.Item.Priority; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Item +{ + /// + /// Builds and executes requests for operations under \api\items\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsItemRequestBuilder : BaseRequestBuilder + { + /// The complete property + public global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder Complete + { + get => new global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder(PathParameters, RequestAdapter); + } + /// The priority property + public global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder Priority + { + get => new global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ItemsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ItemsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}", rawUrl) + { + } + /// + /// Deletes the todo item with the specified ID. + /// + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Gets the todo item with the specified ID. + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoItemModel.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Deletes the todo item with the specified ID. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + return requestInfo; + } + /// + /// Gets the todo item with the specified ID. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/Priority/PriorityRequestBuilder.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/Priority/PriorityRequestBuilder.cs new file mode 100644 index 0000000000..52e95a1cb8 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/Item/Priority/PriorityRequestBuilder.cs @@ -0,0 +1,95 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Item.Priority +{ + /// + /// Builds and executes requests for operations under \api\items\{id}\priority + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class PriorityRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public PriorityRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/priority", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public PriorityRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/priority", rawUrl) + { + } + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// Represents the model for updating the priority of a Todo item. + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PatchAsync(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PatchAsync(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPatchRequestInformation(body, requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// A + /// Represents the model for updating the priority of a Todo item. + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPatchRequestInformation(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPatchRequestInformation(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PATCH, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/ItemsRequestBuilder.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/ItemsRequestBuilder.cs new file mode 100644 index 0000000000..489335512c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Api/Items/ItemsRequestBuilder.cs @@ -0,0 +1,156 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Api.Items.Find; +using TodoApp.Client.Api.Items.GetAfter; +using TodoApp.Client.Api.Items.Item; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items +{ + /// + /// Builds and executes requests for operations under \api\items + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsRequestBuilder : BaseRequestBuilder + { + /// The find property + public global::TodoApp.Client.Api.Items.Find.FindRequestBuilder Find + { + get => new global::TodoApp.Client.Api.Items.Find.FindRequestBuilder(PathParameters, RequestAdapter); + } + /// The getAfter property + public global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder GetAfter + { + get => new global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder(PathParameters, RequestAdapter); + } + /// Gets an item from the TodoApp.Client.api.items.item collection + /// The Todo item's ID. + /// A + public global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder this[Guid position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ItemsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ItemsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items", rawUrl) + { + } + /// + /// Gets all of the current user's todo items. + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// A + /// Represents the model for creating a new Todo item. + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::TodoApp.Client.Models.CreateTodoItemModel body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::TodoApp.Client.Models.CreateTodoItemModel body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.CreatedTodoItemModel.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Gets all of the current user's todo items. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// A + /// Represents the model for creating a new Todo item. + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::TodoApp.Client.Models.CreateTodoItemModel body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::TodoApp.Client.Models.CreateTodoItemModel body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.ItemsRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.ItemsRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/CreateTodoItemModel.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/CreateTodoItemModel.cs new file mode 100644 index 0000000000..997121bab3 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/CreateTodoItemModel.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents the model for creating a new Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CreateTodoItemModel : IParsable + { + /// Gets or sets the text of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.CreateTodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.CreateTodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "text", n => { Text = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("text", Text); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/CreatedTodoItemModel.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/CreatedTodoItemModel.cs new file mode 100644 index 0000000000..e3ebeb104f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/CreatedTodoItemModel.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents the model for a created Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CreatedTodoItemModel : IParsable + { + /// Gets or sets the ID of the created Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Id { get; set; } +#nullable restore +#else + public string Id { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.CreatedTodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.CreatedTodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "id", n => { Id = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/ProblemDetails.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/ProblemDetails.cs new file mode 100644 index 0000000000..49aa45adb4 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/ProblemDetails.cs @@ -0,0 +1,92 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProblemDetails : ApiException, IParsable + #pragma warning restore CS1591 + { + /// The detail property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Detail { get; set; } +#nullable restore +#else + public string Detail { get; set; } +#endif + /// The instance property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Instance { get; set; } +#nullable restore +#else + public string Instance { get; set; } +#endif + /// The primary error message. + public override string Message { get => base.Message; } + /// The status property + public int? Status { get; set; } + /// The title property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Title { get; set; } +#nullable restore +#else + public string Title { get; set; } +#endif + /// The type property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Type { get; set; } +#nullable restore +#else + public string Type { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.ProblemDetails CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.ProblemDetails(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "detail", n => { Detail = n.GetStringValue(); } }, + { "instance", n => { Instance = n.GetStringValue(); } }, + { "status", n => { Status = n.GetIntValue(); } }, + { "title", n => { Title = n.GetStringValue(); } }, + { "type", n => { Type = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("detail", Detail); + writer.WriteStringValue("instance", Instance); + writer.WriteIntValue("status", Status); + writer.WriteStringValue("title", Title); + writer.WriteStringValue("type", Type); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoItemModel.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoItemModel.cs new file mode 100644 index 0000000000..10a9a52b98 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoItemModel.cs @@ -0,0 +1,82 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents a Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoItemModel : IParsable + { + /// Gets or sets the date and time the item was completed. + public DateTimeOffset? CompletedAt { get; set; } + /// Gets or sets the date and time the item was created. + public DateTimeOffset? CreatedAt { get; set; } + /// Gets or sets the ID of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Id { get; set; } +#nullable restore +#else + public string Id { get; set; } +#endif + /// Gets or sets the date and time the Todo item was last updated. + public DateTimeOffset? LastUpdated { get; set; } + /// Gets or sets the optional priority of the Todo item. + public global::TodoApp.Client.Models.TodoPriority? Priority { get; set; } + /// Gets or sets the text of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.TodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.TodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "completedAt", n => { CompletedAt = n.GetDateTimeOffsetValue(); } }, + { "createdAt", n => { CreatedAt = n.GetDateTimeOffsetValue(); } }, + { "id", n => { Id = n.GetStringValue(); } }, + { "lastUpdated", n => { LastUpdated = n.GetDateTimeOffsetValue(); } }, + { "priority", n => { Priority = n.GetEnumValue(); } }, + { "text", n => { Text = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDateTimeOffsetValue("completedAt", CompletedAt); + writer.WriteDateTimeOffsetValue("createdAt", CreatedAt); + writer.WriteStringValue("id", Id); + writer.WriteDateTimeOffsetValue("lastUpdated", LastUpdated); + writer.WriteEnumValue("priority", Priority); + writer.WriteStringValue("text", Text); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoListViewModel.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoListViewModel.cs new file mode 100644 index 0000000000..d7fb2e91ac --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoListViewModel.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents a collection of Todo items. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoListViewModel : IParsable + { + /// Gets or sets the Todo item(s). +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public List? Items { get; set; } +#nullable restore +#else + public List Items { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.TodoListViewModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.TodoListViewModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "items", n => { Items = n.GetCollectionOfObjectValues(global::TodoApp.Client.Models.TodoItemModel.CreateFromDiscriminatorValue)?.AsList(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteCollectionOfObjectValues("items", Items); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoPriority.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoPriority.cs new file mode 100644 index 0000000000..5200deb280 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/TodoPriority.cs @@ -0,0 +1,23 @@ +// +using System.Runtime.Serialization; +using System; +namespace TodoApp.Client.Models +{ + /// The priority levels for a Todo item. + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public enum TodoPriority + { + [EnumMember(Value = "Normal")] + #pragma warning disable CS1591 + Normal, + #pragma warning restore CS1591 + [EnumMember(Value = "Low")] + #pragma warning disable CS1591 + Low, + #pragma warning restore CS1591 + [EnumMember(Value = "High")] + #pragma warning disable CS1591 + High, + #pragma warning restore CS1591 + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/UpdateTodoItemPriorityModel.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/UpdateTodoItemPriorityModel.cs new file mode 100644 index 0000000000..f2a9c6e583 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/Models/UpdateTodoItemPriorityModel.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents the model for updating the priority of a Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class UpdateTodoItemPriorityModel : IParsable + { + /// Gets or sets the new priority of the Todo item. + public global::TodoApp.Client.Models.TodoPriority? Priority { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.UpdateTodoItemPriorityModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.UpdateTodoItemPriorityModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "priority", n => { Priority = n.GetEnumValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteEnumValue("priority", Priority); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/TodoApiClient.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/TodoApiClient.cs new file mode 100644 index 0000000000..0d5631bb7d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/TodoApiClient.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +using TodoApp.Client.Api; +namespace TodoApp.Client +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoApiClient : BaseRequestBuilder + { + /// The api property + public global::TodoApp.Client.Api.ApiRequestBuilder Api + { + get => new global::TodoApp.Client.Api.ApiRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public TodoApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/kiota-lock.json b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/kiota-lock.json new file mode 100644 index 0000000000..497c46d4b3 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/TodoClient/kiota-lock.json @@ -0,0 +1,31 @@ +{ + "descriptionHash": "6220470D2DBDA8D33A3A26AE0D99FD08E8CA025558CE7AF3EFA771BEE7F540049DFB9E14E28367BD30CC488F5A918670E40CF226C0C825CC163EDBFFA1CCE766", + "descriptionLocation": "../snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt", + "lockFileVersion": "1.0.0", + "kiotaVersion": "1.29.0", + "clientClassName": "TodoApiClient", + "typeAccessModifier": "Public", + "clientNamespaceName": "TodoApp.Client", + "language": "CSharp", + "usesBackingStore": false, + "excludeBackwardCompatible": true, + "includeAdditionalData": false, + "disableSSLValidation": false, + "serializers": [ + "Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory", + "Microsoft.Kiota.Serialization.Text.TextSerializationWriterFactory", + "Microsoft.Kiota.Serialization.Form.FormSerializationWriterFactory", + "Microsoft.Kiota.Serialization.Multipart.MultipartSerializationWriterFactory" + ], + "deserializers": [ + "Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory", + "Microsoft.Kiota.Serialization.Text.TextParseNodeFactory", + "Microsoft.Kiota.Serialization.Form.FormParseNodeFactory" + ], + "structuredMimeTypes": [ + "application/json" + ], + "includePatterns": [], + "excludePatterns": [], + "disabledValidationRules": [] +} \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/VerifyTests.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/VerifyTests.cs index 650ea85e31..606400e63c 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/VerifyTests.cs +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/VerifyTests.cs @@ -58,6 +58,7 @@ await Verify(swagger) [InlineData(typeof(MinimalApp.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(MinimalAppWithNullableEnums.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(MvcWithNullable.Program), "/swagger/v1/swagger.json")] + [InlineData(typeof(TodoApp.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(TopLevelSwaggerDoc.Program), "/swagger/v1.json")] [InlineData(typeof(WebApi.Program), "/swagger/v1/swagger.json")] [InlineData(typeof(WebApi.Aot.Program), "/swagger/v1/swagger.json")] diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/generate-todo-client.ps1 b/test/Swashbuckle.AspNetCore.IntegrationTests/generate-todo-client.ps1 new file mode 100644 index 0000000000..2e5ff31862 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/generate-todo-client.ps1 @@ -0,0 +1,28 @@ +#! /usr/bin/env pwsh + +param( + [Parameter(Mandatory = $false)][string] $OpenApiUrl = "./snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt", + [Parameter(Mandatory = $false)][switch] $Regenerate +) + +$ErrorActionPreference = "Stop" +$ProgressPreference = "SilentlyContinue" + +$env:KIOTA_TUTORIAL_ENABLED = "false" + +$OutputPath = "./TodoClient" + +dotnet kiota generate ` + --additional-data false ` + --class-name TodoApiClient ` + --clean-output ` + --exclude-backward-compatible ` + --language csharp ` + --namespace-name TodoApp.Client ` + --openapi $OpenApiUrl ` + --output $OutputPath ` + --structured-mime-types "application/json" + +if ($LASTEXITCODE -ne 0) { + throw "Kiota generation failed with exit code ${LASTEXITCODE}" +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.2.0.json b/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.2.0.json new file mode 100644 index 0000000000..ebe10ed32d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.2.0.json @@ -0,0 +1,1607 @@ +{ + "title": "A JSON Schema for Swagger 2.0 API.", + "id": "http://swagger.io/v2/schema.json#", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "required": [ + "swagger", + "info", + "paths" + ], + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "swagger": { + "type": "string", + "enum": [ + "2.0" + ], + "description": "The Swagger version of this document." + }, + "info": { + "$ref": "#/definitions/info" + }, + "host": { + "type": "string", + "pattern": "^[^{}/ :\\\\]+(?::\\d+)?$", + "description": "The host (name or ip) of the API. Example: 'swagger.io'" + }, + "basePath": { + "type": "string", + "pattern": "^/", + "description": "The base path to the API. Example: '/api'." + }, + "schemes": { + "$ref": "#/definitions/schemesList" + }, + "consumes": { + "description": "A list of MIME types accepted by the API.", + "allOf": [ + { + "$ref": "#/definitions/mediaTypeList" + } + ] + }, + "produces": { + "description": "A list of MIME types the API can produce.", + "allOf": [ + { + "$ref": "#/definitions/mediaTypeList" + } + ] + }, + "paths": { + "$ref": "#/definitions/paths" + }, + "definitions": { + "$ref": "#/definitions/definitions" + }, + "parameters": { + "$ref": "#/definitions/parameterDefinitions" + }, + "responses": { + "$ref": "#/definitions/responseDefinitions" + }, + "security": { + "$ref": "#/definitions/security" + }, + "securityDefinitions": { + "$ref": "#/definitions/securityDefinitions" + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/tag" + }, + "uniqueItems": true + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + } + }, + "definitions": { + "info": { + "type": "object", + "description": "General information about the API.", + "required": [ + "version", + "title" + ], + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "title": { + "type": "string", + "description": "A unique and precise title of the API." + }, + "version": { + "type": "string", + "description": "A semantic version number of the API." + }, + "description": { + "type": "string", + "description": "A longer description of the API. Should be different from the title. GitHub Flavored Markdown is allowed." + }, + "termsOfService": { + "type": "string", + "description": "The terms of service for the API." + }, + "contact": { + "$ref": "#/definitions/contact" + }, + "license": { + "$ref": "#/definitions/license" + } + } + }, + "contact": { + "type": "object", + "description": "Contact information for the owners of the API.", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The identifying name of the contact person/organization." + }, + "url": { + "type": "string", + "description": "The URL pointing to the contact information.", + "format": "uri" + }, + "email": { + "type": "string", + "description": "The email address of the contact person/organization.", + "format": "email" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "license": { + "type": "object", + "required": [ + "name" + ], + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The name of the license type. It's encouraged to use an OSI compatible license." + }, + "url": { + "type": "string", + "description": "The URL pointing to the license.", + "format": "uri" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "paths": { + "type": "object", + "description": "Relative paths to the individual endpoints. They must be relative to the 'basePath'.", + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + }, + "^/": { + "$ref": "#/definitions/pathItem" + } + }, + "additionalProperties": false + }, + "definitions": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "description": "One or more JSON objects describing the schemas being consumed and produced by the API." + }, + "parameterDefinitions": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/parameter" + }, + "description": "One or more JSON representations for parameters" + }, + "responseDefinitions": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/response" + }, + "description": "One or more JSON representations for responses" + }, + "externalDocs": { + "type": "object", + "additionalProperties": false, + "description": "information about external documentation", + "required": [ + "url" + ], + "properties": { + "description": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "examples": { + "type": "object", + "additionalProperties": true + }, + "mimeType": { + "type": "string", + "description": "The MIME type of the HTTP message." + }, + "operation": { + "type": "object", + "required": [ + "responses" + ], + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "tags": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, + "summary": { + "type": "string", + "description": "A brief summary of the operation." + }, + "description": { + "type": "string", + "description": "A longer description of the operation, GitHub Flavored Markdown is allowed." + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "operationId": { + "type": "string", + "description": "A unique identifier of the operation." + }, + "produces": { + "description": "A list of MIME types the API can produce.", + "allOf": [ + { + "$ref": "#/definitions/mediaTypeList" + } + ] + }, + "consumes": { + "description": "A list of MIME types the API can consume.", + "allOf": [ + { + "$ref": "#/definitions/mediaTypeList" + } + ] + }, + "parameters": { + "$ref": "#/definitions/parametersList" + }, + "responses": { + "$ref": "#/definitions/responses" + }, + "schemes": { + "$ref": "#/definitions/schemesList" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "security": { + "$ref": "#/definitions/security" + } + } + }, + "pathItem": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "$ref": { + "type": "string" + }, + "get": { + "$ref": "#/definitions/operation" + }, + "put": { + "$ref": "#/definitions/operation" + }, + "post": { + "$ref": "#/definitions/operation" + }, + "delete": { + "$ref": "#/definitions/operation" + }, + "options": { + "$ref": "#/definitions/operation" + }, + "head": { + "$ref": "#/definitions/operation" + }, + "patch": { + "$ref": "#/definitions/operation" + }, + "parameters": { + "$ref": "#/definitions/parametersList" + } + } + }, + "responses": { + "type": "object", + "description": "Response objects names can either be any valid HTTP status code or 'default'.", + "minProperties": 1, + "additionalProperties": false, + "patternProperties": { + "^([0-9]{3})$|^(default)$": { + "$ref": "#/definitions/responseValue" + }, + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "not": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + } + }, + "responseValue": { + "oneOf": [ + { + "$ref": "#/definitions/response" + }, + { + "$ref": "#/definitions/jsonReference" + } + ] + }, + "response": { + "type": "object", + "required": [ + "description" + ], + "properties": { + "description": { + "type": "string" + }, + "schema": { + "oneOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "$ref": "#/definitions/fileSchema" + } + ] + }, + "headers": { + "$ref": "#/definitions/headers" + }, + "examples": { + "$ref": "#/definitions/examples" + } + }, + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "headers": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/header" + } + }, + "header": { + "type": "object", + "additionalProperties": false, + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "string", + "number", + "integer", + "boolean", + "array" + ] + }, + "format": { + "type": "string" + }, + "items": { + "$ref": "#/definitions/primitivesItems" + }, + "collectionFormat": { + "$ref": "#/definitions/collectionFormat" + }, + "default": { + "$ref": "#/definitions/default" + }, + "maximum": { + "$ref": "#/definitions/maximum" + }, + "exclusiveMaximum": { + "$ref": "#/definitions/exclusiveMaximum" + }, + "minimum": { + "$ref": "#/definitions/minimum" + }, + "exclusiveMinimum": { + "$ref": "#/definitions/exclusiveMinimum" + }, + "maxLength": { + "$ref": "#/definitions/maxLength" + }, + "minLength": { + "$ref": "#/definitions/minLength" + }, + "pattern": { + "$ref": "#/definitions/pattern" + }, + "maxItems": { + "$ref": "#/definitions/maxItems" + }, + "minItems": { + "$ref": "#/definitions/minItems" + }, + "uniqueItems": { + "$ref": "#/definitions/uniqueItems" + }, + "enum": { + "$ref": "#/definitions/enum" + }, + "multipleOf": { + "$ref": "#/definitions/multipleOf" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "vendorExtension": { + "description": "Any property starting with x- is valid.", + "additionalProperties": true, + "additionalItems": true + }, + "bodyParameter": { + "type": "object", + "required": [ + "name", + "in", + "schema" + ], + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "description": { + "type": "string", + "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." + }, + "name": { + "type": "string", + "description": "The name of the parameter." + }, + "in": { + "type": "string", + "description": "Determines the location of the parameter.", + "enum": [ + "body" + ] + }, + "required": { + "type": "boolean", + "description": "Determines whether or not this parameter is required or optional.", + "default": false + }, + "schema": { + "$ref": "#/definitions/schema" + } + }, + "additionalProperties": false + }, + "headerParameterSubSchema": { + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "required": { + "type": "boolean", + "description": "Determines whether or not this parameter is required or optional.", + "default": false + }, + "in": { + "type": "string", + "description": "Determines the location of the parameter.", + "enum": [ + "header" + ] + }, + "description": { + "type": "string", + "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." + }, + "name": { + "type": "string", + "description": "The name of the parameter." + }, + "type": { + "type": "string", + "enum": [ + "string", + "number", + "boolean", + "integer", + "array" + ] + }, + "format": { + "type": "string" + }, + "items": { + "$ref": "#/definitions/primitivesItems" + }, + "collectionFormat": { + "$ref": "#/definitions/collectionFormat" + }, + "default": { + "$ref": "#/definitions/default" + }, + "maximum": { + "$ref": "#/definitions/maximum" + }, + "exclusiveMaximum": { + "$ref": "#/definitions/exclusiveMaximum" + }, + "minimum": { + "$ref": "#/definitions/minimum" + }, + "exclusiveMinimum": { + "$ref": "#/definitions/exclusiveMinimum" + }, + "maxLength": { + "$ref": "#/definitions/maxLength" + }, + "minLength": { + "$ref": "#/definitions/minLength" + }, + "pattern": { + "$ref": "#/definitions/pattern" + }, + "maxItems": { + "$ref": "#/definitions/maxItems" + }, + "minItems": { + "$ref": "#/definitions/minItems" + }, + "uniqueItems": { + "$ref": "#/definitions/uniqueItems" + }, + "enum": { + "$ref": "#/definitions/enum" + }, + "multipleOf": { + "$ref": "#/definitions/multipleOf" + } + } + }, + "queryParameterSubSchema": { + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "required": { + "type": "boolean", + "description": "Determines whether or not this parameter is required or optional.", + "default": false + }, + "in": { + "type": "string", + "description": "Determines the location of the parameter.", + "enum": [ + "query" + ] + }, + "description": { + "type": "string", + "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." + }, + "name": { + "type": "string", + "description": "The name of the parameter." + }, + "allowEmptyValue": { + "type": "boolean", + "default": false, + "description": "allows sending a parameter by name only or with an empty value." + }, + "type": { + "type": "string", + "enum": [ + "string", + "number", + "boolean", + "integer", + "array" + ] + }, + "format": { + "type": "string" + }, + "items": { + "$ref": "#/definitions/primitivesItems" + }, + "collectionFormat": { + "$ref": "#/definitions/collectionFormatWithMulti" + }, + "default": { + "$ref": "#/definitions/default" + }, + "maximum": { + "$ref": "#/definitions/maximum" + }, + "exclusiveMaximum": { + "$ref": "#/definitions/exclusiveMaximum" + }, + "minimum": { + "$ref": "#/definitions/minimum" + }, + "exclusiveMinimum": { + "$ref": "#/definitions/exclusiveMinimum" + }, + "maxLength": { + "$ref": "#/definitions/maxLength" + }, + "minLength": { + "$ref": "#/definitions/minLength" + }, + "pattern": { + "$ref": "#/definitions/pattern" + }, + "maxItems": { + "$ref": "#/definitions/maxItems" + }, + "minItems": { + "$ref": "#/definitions/minItems" + }, + "uniqueItems": { + "$ref": "#/definitions/uniqueItems" + }, + "enum": { + "$ref": "#/definitions/enum" + }, + "multipleOf": { + "$ref": "#/definitions/multipleOf" + } + } + }, + "formDataParameterSubSchema": { + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "required": { + "type": "boolean", + "description": "Determines whether or not this parameter is required or optional.", + "default": false + }, + "in": { + "type": "string", + "description": "Determines the location of the parameter.", + "enum": [ + "formData" + ] + }, + "description": { + "type": "string", + "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." + }, + "name": { + "type": "string", + "description": "The name of the parameter." + }, + "allowEmptyValue": { + "type": "boolean", + "default": false, + "description": "allows sending a parameter by name only or with an empty value." + }, + "type": { + "type": "string", + "enum": [ + "string", + "number", + "boolean", + "integer", + "array", + "file" + ] + }, + "format": { + "type": "string" + }, + "items": { + "$ref": "#/definitions/primitivesItems" + }, + "collectionFormat": { + "$ref": "#/definitions/collectionFormatWithMulti" + }, + "default": { + "$ref": "#/definitions/default" + }, + "maximum": { + "$ref": "#/definitions/maximum" + }, + "exclusiveMaximum": { + "$ref": "#/definitions/exclusiveMaximum" + }, + "minimum": { + "$ref": "#/definitions/minimum" + }, + "exclusiveMinimum": { + "$ref": "#/definitions/exclusiveMinimum" + }, + "maxLength": { + "$ref": "#/definitions/maxLength" + }, + "minLength": { + "$ref": "#/definitions/minLength" + }, + "pattern": { + "$ref": "#/definitions/pattern" + }, + "maxItems": { + "$ref": "#/definitions/maxItems" + }, + "minItems": { + "$ref": "#/definitions/minItems" + }, + "uniqueItems": { + "$ref": "#/definitions/uniqueItems" + }, + "enum": { + "$ref": "#/definitions/enum" + }, + "multipleOf": { + "$ref": "#/definitions/multipleOf" + } + } + }, + "pathParameterSubSchema": { + "additionalProperties": false, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "required": [ + "required" + ], + "properties": { + "required": { + "type": "boolean", + "enum": [ + true + ], + "description": "Determines whether or not this parameter is required or optional." + }, + "in": { + "type": "string", + "description": "Determines the location of the parameter.", + "enum": [ + "path" + ] + }, + "description": { + "type": "string", + "description": "A brief description of the parameter. This could contain examples of use. GitHub Flavored Markdown is allowed." + }, + "name": { + "type": "string", + "description": "The name of the parameter." + }, + "type": { + "type": "string", + "enum": [ + "string", + "number", + "boolean", + "integer", + "array" + ] + }, + "format": { + "type": "string" + }, + "items": { + "$ref": "#/definitions/primitivesItems" + }, + "collectionFormat": { + "$ref": "#/definitions/collectionFormat" + }, + "default": { + "$ref": "#/definitions/default" + }, + "maximum": { + "$ref": "#/definitions/maximum" + }, + "exclusiveMaximum": { + "$ref": "#/definitions/exclusiveMaximum" + }, + "minimum": { + "$ref": "#/definitions/minimum" + }, + "exclusiveMinimum": { + "$ref": "#/definitions/exclusiveMinimum" + }, + "maxLength": { + "$ref": "#/definitions/maxLength" + }, + "minLength": { + "$ref": "#/definitions/minLength" + }, + "pattern": { + "$ref": "#/definitions/pattern" + }, + "maxItems": { + "$ref": "#/definitions/maxItems" + }, + "minItems": { + "$ref": "#/definitions/minItems" + }, + "uniqueItems": { + "$ref": "#/definitions/uniqueItems" + }, + "enum": { + "$ref": "#/definitions/enum" + }, + "multipleOf": { + "$ref": "#/definitions/multipleOf" + } + } + }, + "nonBodyParameter": { + "type": "object", + "required": [ + "name", + "in", + "type" + ], + "oneOf": [ + { + "$ref": "#/definitions/headerParameterSubSchema" + }, + { + "$ref": "#/definitions/formDataParameterSubSchema" + }, + { + "$ref": "#/definitions/queryParameterSubSchema" + }, + { + "$ref": "#/definitions/pathParameterSubSchema" + } + ] + }, + "parameter": { + "oneOf": [ + { + "$ref": "#/definitions/bodyParameter" + }, + { + "$ref": "#/definitions/nonBodyParameter" + } + ] + }, + "schema": { + "type": "object", + "description": "A deterministic version of a JSON Schema object.", + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "properties": { + "$ref": { + "type": "string" + }, + "format": { + "type": "string" + }, + "title": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/title" + }, + "description": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/description" + }, + "default": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/default" + }, + "multipleOf": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/multipleOf" + }, + "maximum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/maximum" + }, + "exclusiveMaximum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMaximum" + }, + "minimum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/minimum" + }, + "exclusiveMinimum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMinimum" + }, + "maxLength": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" + }, + "minLength": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" + }, + "pattern": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/pattern" + }, + "maxItems": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" + }, + "minItems": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" + }, + "uniqueItems": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/uniqueItems" + }, + "maxProperties": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" + }, + "minProperties": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" + }, + "required": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" + }, + "enum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/enum" + }, + "additionalProperties": { + "anyOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "type": "boolean" + } + ], + "default": {} + }, + "type": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/type" + }, + "items": { + "anyOf": [ + { + "$ref": "#/definitions/schema" + }, + { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + } + ], + "default": {} + }, + "allOf": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/schema" + } + }, + "properties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/schema" + }, + "default": {} + }, + "discriminator": { + "type": "string" + }, + "readOnly": { + "type": "boolean", + "default": false + }, + "xml": { + "$ref": "#/definitions/xml" + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "example": {} + }, + "additionalProperties": false + }, + "fileSchema": { + "type": "object", + "description": "A deterministic version of a JSON Schema object.", + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + }, + "required": [ + "type" + ], + "properties": { + "format": { + "type": "string" + }, + "title": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/title" + }, + "description": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/description" + }, + "default": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/default" + }, + "required": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" + }, + "type": { + "type": "string", + "enum": [ + "file" + ] + }, + "readOnly": { + "type": "boolean", + "default": false + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + }, + "example": {} + }, + "additionalProperties": false + }, + "primitivesItems": { + "type": "object", + "additionalProperties": false, + "properties": { + "type": { + "type": "string", + "enum": [ + "string", + "number", + "integer", + "boolean", + "array" + ] + }, + "format": { + "type": "string" + }, + "items": { + "$ref": "#/definitions/primitivesItems" + }, + "collectionFormat": { + "$ref": "#/definitions/collectionFormat" + }, + "default": { + "$ref": "#/definitions/default" + }, + "maximum": { + "$ref": "#/definitions/maximum" + }, + "exclusiveMaximum": { + "$ref": "#/definitions/exclusiveMaximum" + }, + "minimum": { + "$ref": "#/definitions/minimum" + }, + "exclusiveMinimum": { + "$ref": "#/definitions/exclusiveMinimum" + }, + "maxLength": { + "$ref": "#/definitions/maxLength" + }, + "minLength": { + "$ref": "#/definitions/minLength" + }, + "pattern": { + "$ref": "#/definitions/pattern" + }, + "maxItems": { + "$ref": "#/definitions/maxItems" + }, + "minItems": { + "$ref": "#/definitions/minItems" + }, + "uniqueItems": { + "$ref": "#/definitions/uniqueItems" + }, + "enum": { + "$ref": "#/definitions/enum" + }, + "multipleOf": { + "$ref": "#/definitions/multipleOf" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "security": { + "type": "array", + "items": { + "$ref": "#/definitions/securityRequirement" + }, + "uniqueItems": true + }, + "securityRequirement": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + } + }, + "xml": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "prefix": { + "type": "string" + }, + "attribute": { + "type": "boolean", + "default": false + }, + "wrapped": { + "type": "boolean", + "default": false + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "tag": { + "type": "object", + "additionalProperties": false, + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/externalDocs" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "securityDefinitions": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/basicAuthenticationSecurity" + }, + { + "$ref": "#/definitions/apiKeySecurity" + }, + { + "$ref": "#/definitions/oauth2ImplicitSecurity" + }, + { + "$ref": "#/definitions/oauth2PasswordSecurity" + }, + { + "$ref": "#/definitions/oauth2ApplicationSecurity" + }, + { + "$ref": "#/definitions/oauth2AccessCodeSecurity" + } + ] + } + }, + "basicAuthenticationSecurity": { + "type": "object", + "additionalProperties": false, + "required": [ + "type" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "basic" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "apiKeySecurity": { + "type": "object", + "additionalProperties": false, + "required": [ + "type", + "name", + "in" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "apiKey" + ] + }, + "name": { + "type": "string" + }, + "in": { + "type": "string", + "enum": [ + "header", + "query" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "oauth2ImplicitSecurity": { + "type": "object", + "additionalProperties": false, + "required": [ + "type", + "flow", + "authorizationUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "flow": { + "type": "string", + "enum": [ + "implicit" + ] + }, + "scopes": { + "$ref": "#/definitions/oauth2Scopes" + }, + "authorizationUrl": { + "type": "string", + "format": "uri" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "oauth2PasswordSecurity": { + "type": "object", + "additionalProperties": false, + "required": [ + "type", + "flow", + "tokenUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "flow": { + "type": "string", + "enum": [ + "password" + ] + }, + "scopes": { + "$ref": "#/definitions/oauth2Scopes" + }, + "tokenUrl": { + "type": "string", + "format": "uri" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "oauth2ApplicationSecurity": { + "type": "object", + "additionalProperties": false, + "required": [ + "type", + "flow", + "tokenUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "flow": { + "type": "string", + "enum": [ + "application" + ] + }, + "scopes": { + "$ref": "#/definitions/oauth2Scopes" + }, + "tokenUrl": { + "type": "string", + "format": "uri" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "oauth2AccessCodeSecurity": { + "type": "object", + "additionalProperties": false, + "required": [ + "type", + "flow", + "authorizationUrl", + "tokenUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "flow": { + "type": "string", + "enum": [ + "accessCode" + ] + }, + "scopes": { + "$ref": "#/definitions/oauth2Scopes" + }, + "authorizationUrl": { + "type": "string", + "format": "uri" + }, + "tokenUrl": { + "type": "string", + "format": "uri" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": { + "$ref": "#/definitions/vendorExtension" + } + } + }, + "oauth2Scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "mediaTypeList": { + "type": "array", + "items": { + "$ref": "#/definitions/mimeType" + }, + "uniqueItems": true + }, + "parametersList": { + "type": "array", + "description": "The parameters needed to send a valid API call.", + "additionalItems": false, + "items": { + "oneOf": [ + { + "$ref": "#/definitions/parameter" + }, + { + "$ref": "#/definitions/jsonReference" + } + ] + }, + "uniqueItems": true + }, + "schemesList": { + "type": "array", + "description": "The transfer protocol of the API.", + "items": { + "type": "string", + "enum": [ + "http", + "https", + "ws", + "wss" + ] + }, + "uniqueItems": true + }, + "collectionFormat": { + "type": "string", + "enum": [ + "csv", + "ssv", + "tsv", + "pipes" + ], + "default": "csv" + }, + "collectionFormatWithMulti": { + "type": "string", + "enum": [ + "csv", + "ssv", + "tsv", + "pipes", + "multi" + ], + "default": "csv" + }, + "title": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/title" + }, + "description": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/description" + }, + "default": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/default" + }, + "multipleOf": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/multipleOf" + }, + "maximum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/maximum" + }, + "exclusiveMaximum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMaximum" + }, + "minimum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/minimum" + }, + "exclusiveMinimum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/exclusiveMinimum" + }, + "maxLength": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" + }, + "minLength": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" + }, + "pattern": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/pattern" + }, + "maxItems": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveInteger" + }, + "minItems": { + "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0" + }, + "uniqueItems": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/uniqueItems" + }, + "enum": { + "$ref": "http://json-schema.org/draft-04/schema#/properties/enum" + }, + "jsonReference": { + "type": "object", + "required": [ + "$ref" + ], + "additionalProperties": false, + "properties": { + "$ref": { + "type": "string" + } + } + } + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.3.0.json b/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.3.0.json new file mode 100644 index 0000000000..a40570a367 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.3.0.json @@ -0,0 +1,1651 @@ +{ + "id": "https://spec.openapis.org/oas/3.0/schema/2024-10-18", + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "The description of OpenAPI v3.0.x Documents", + "type": "object", + "required": [ + "openapi", + "info", + "paths" + ], + "properties": { + "openapi": { + "type": "string", + "pattern": "^3\\.0\\.\\d(-.+)?$" + }, + "info": { + "$ref": "#/definitions/Info" + }, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/definitions/Server" + } + }, + "security": { + "type": "array", + "items": { + "$ref": "#/definitions/SecurityRequirement" + } + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/definitions/Tag" + }, + "uniqueItems": true + }, + "paths": { + "$ref": "#/definitions/Paths" + }, + "components": { + "$ref": "#/definitions/Components" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false, + "definitions": { + "Reference": { + "type": "object", + "required": [ + "$ref" + ], + "patternProperties": { + "^\\$ref$": { + "type": "string", + "format": "uri-reference" + } + } + }, + "Info": { + "type": "object", + "required": [ + "title", + "version" + ], + "properties": { + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "termsOfService": { + "type": "string", + "format": "uri-reference" + }, + "contact": { + "$ref": "#/definitions/Contact" + }, + "license": { + "$ref": "#/definitions/License" + }, + "version": { + "type": "string" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Contact": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + }, + "email": { + "type": "string", + "format": "email" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "License": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Server": { + "type": "object", + "required": [ + "url" + ], + "properties": { + "url": { + "type": "string" + }, + "description": { + "type": "string" + }, + "variables": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/ServerVariable" + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "ServerVariable": { + "type": "object", + "required": [ + "default" + ], + "properties": { + "enum": { + "type": "array", + "items": { + "type": "string" + } + }, + "default": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Components": { + "type": "object", + "properties": { + "schemas": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "responses": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Response" + } + ] + } + } + }, + "parameters": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Parameter" + } + ] + } + } + }, + "examples": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Example" + } + ] + } + } + }, + "requestBodies": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/RequestBody" + } + ] + } + } + }, + "headers": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Header" + } + ] + } + } + }, + "securitySchemes": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/SecurityScheme" + } + ] + } + } + }, + "links": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Link" + } + ] + } + } + }, + "callbacks": { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9\\.\\-_]+$": { + "oneOf": [ + { + "$ref": "#/definitions/Reference" + }, + { + "$ref": "#/definitions/Callback" + } + ] + } + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Schema": { + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "multipleOf": { + "type": "number", + "minimum": 0, + "exclusiveMinimum": true + }, + "maximum": { + "type": "number" + }, + "exclusiveMaximum": { + "type": "boolean", + "default": false + }, + "minimum": { + "type": "number" + }, + "exclusiveMinimum": { + "type": "boolean", + "default": false + }, + "maxLength": { + "type": "integer", + "minimum": 0 + }, + "minLength": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "pattern": { + "type": "string", + "format": "regex" + }, + "maxItems": { + "type": "integer", + "minimum": 0 + }, + "minItems": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "uniqueItems": { + "type": "boolean", + "default": false + }, + "maxProperties": { + "type": "integer", + "minimum": 0 + }, + "minProperties": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "required": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + }, + "enum": { + "type": "array", + "items": {}, + "minItems": 1, + "uniqueItems": false + }, + "type": { + "type": "string", + "enum": [ + "array", + "boolean", + "integer", + "number", + "object", + "string" + ] + }, + "not": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "allOf": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "oneOf": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "anyOf": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "properties": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + }, + { + "type": "boolean" + } + ], + "default": true + }, + "description": { + "type": "string" + }, + "format": { + "type": "string" + }, + "default": {}, + "nullable": { + "type": "boolean", + "default": false + }, + "discriminator": { + "$ref": "#/definitions/Discriminator" + }, + "readOnly": { + "type": "boolean", + "default": false + }, + "writeOnly": { + "type": "boolean", + "default": false + }, + "example": {}, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "xml": { + "$ref": "#/definitions/XML" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Discriminator": { + "type": "object", + "required": [ + "propertyName" + ], + "properties": { + "propertyName": { + "type": "string" + }, + "mapping": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "XML": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "namespace": { + "type": "string", + "format": "uri" + }, + "prefix": { + "type": "string" + }, + "attribute": { + "type": "boolean", + "default": false + }, + "wrapped": { + "type": "boolean", + "default": false + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Response": { + "type": "object", + "required": [ + "description" + ], + "properties": { + "description": { + "type": "string" + }, + "headers": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Header" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + } + }, + "links": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Link" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "MediaType": { + "type": "object", + "properties": { + "schema": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "example": {}, + "examples": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Example" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "encoding": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Encoding" + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false, + "allOf": [ + { + "$ref": "#/definitions/ExampleXORExamples" + } + ] + }, + "Example": { + "type": "object", + "properties": { + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "value": {}, + "externalValue": { + "type": "string", + "format": "uri-reference" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Header": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "required": { + "type": "boolean", + "default": false + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "allowEmptyValue": { + "type": "boolean", + "default": false + }, + "style": { + "type": "string", + "enum": [ + "simple" + ], + "default": "simple" + }, + "explode": { + "type": "boolean" + }, + "allowReserved": { + "type": "boolean", + "default": false + }, + "schema": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + }, + "minProperties": 1, + "maxProperties": 1 + }, + "example": {}, + "examples": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Example" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false, + "allOf": [ + { + "$ref": "#/definitions/ExampleXORExamples" + }, + { + "$ref": "#/definitions/SchemaXORContent" + } + ] + }, + "Paths": { + "type": "object", + "patternProperties": { + "^\\/": { + "$ref": "#/definitions/PathItem" + }, + "^x-": {} + }, + "additionalProperties": false + }, + "PathItem": { + "type": "object", + "properties": { + "$ref": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "get": { + "$ref": "#/definitions/Operation" + }, + "put": { + "$ref": "#/definitions/Operation" + }, + "post": { + "$ref": "#/definitions/Operation" + }, + "delete": { + "$ref": "#/definitions/Operation" + }, + "options": { + "$ref": "#/definitions/Operation" + }, + "head": { + "$ref": "#/definitions/Operation" + }, + "patch": { + "$ref": "#/definitions/Operation" + }, + "trace": { + "$ref": "#/definitions/Operation" + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/definitions/Server" + } + }, + "parameters": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Parameter" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "uniqueItems": true + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Operation": { + "type": "object", + "required": [ + "responses" + ], + "properties": { + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + }, + "operationId": { + "type": "string" + }, + "parameters": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/Parameter" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "uniqueItems": true + }, + "requestBody": { + "oneOf": [ + { + "$ref": "#/definitions/RequestBody" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "responses": { + "$ref": "#/definitions/Responses" + }, + "callbacks": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Callback" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "security": { + "type": "array", + "items": { + "$ref": "#/definitions/SecurityRequirement" + } + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/definitions/Server" + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Responses": { + "type": "object", + "properties": { + "default": { + "oneOf": [ + { + "$ref": "#/definitions/Response" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "patternProperties": { + "^[1-5](?:\\d{2}|XX)$": { + "oneOf": [ + { + "$ref": "#/definitions/Response" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "^x-": {} + }, + "minProperties": 1, + "additionalProperties": false + }, + "SecurityRequirement": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "Tag": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/definitions/ExternalDocumentation" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "ExternalDocumentation": { + "type": "object", + "required": [ + "url" + ], + "properties": { + "description": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "ExampleXORExamples": { + "description": "Example and examples are mutually exclusive", + "not": { + "required": [ + "example", + "examples" + ] + } + }, + "SchemaXORContent": { + "description": "Schema and content are mutually exclusive, at least one is required", + "not": { + "required": [ + "schema", + "content" + ] + }, + "oneOf": [ + { + "required": [ + "schema" + ] + }, + { + "required": [ + "content" + ], + "description": "Some properties are not allowed if content is present", + "allOf": [ + { + "not": { + "required": [ + "style" + ] + } + }, + { + "not": { + "required": [ + "explode" + ] + } + }, + { + "not": { + "required": [ + "allowReserved" + ] + } + }, + { + "not": { + "required": [ + "example" + ] + } + }, + { + "not": { + "required": [ + "examples" + ] + } + } + ] + } + ] + }, + "Parameter": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "in": { + "type": "string" + }, + "description": { + "type": "string" + }, + "required": { + "type": "boolean", + "default": false + }, + "deprecated": { + "type": "boolean", + "default": false + }, + "allowEmptyValue": { + "type": "boolean", + "default": false + }, + "style": { + "type": "string" + }, + "explode": { + "type": "boolean" + }, + "allowReserved": { + "type": "boolean", + "default": false + }, + "schema": { + "oneOf": [ + { + "$ref": "#/definitions/Schema" + }, + { + "$ref": "#/definitions/Reference" + } + ] + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + }, + "minProperties": 1, + "maxProperties": 1 + }, + "example": {}, + "examples": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Example" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false, + "required": [ + "name", + "in" + ], + "allOf": [ + { + "$ref": "#/definitions/ExampleXORExamples" + }, + { + "$ref": "#/definitions/SchemaXORContent" + } + ], + "oneOf": [ + { + "$ref": "#/definitions/PathParameter" + }, + { + "$ref": "#/definitions/QueryParameter" + }, + { + "$ref": "#/definitions/HeaderParameter" + }, + { + "$ref": "#/definitions/CookieParameter" + } + ] + }, + "PathParameter": { + "description": "Parameter in path", + "required": [ + "required" + ], + "properties": { + "in": { + "enum": [ + "path" + ] + }, + "style": { + "enum": [ + "matrix", + "label", + "simple" + ], + "default": "simple" + }, + "required": { + "enum": [ + true + ] + } + } + }, + "QueryParameter": { + "description": "Parameter in query", + "properties": { + "in": { + "enum": [ + "query" + ] + }, + "style": { + "enum": [ + "form", + "spaceDelimited", + "pipeDelimited", + "deepObject" + ], + "default": "form" + } + } + }, + "HeaderParameter": { + "description": "Parameter in header", + "properties": { + "in": { + "enum": [ + "header" + ] + }, + "style": { + "enum": [ + "simple" + ], + "default": "simple" + } + } + }, + "CookieParameter": { + "description": "Parameter in cookie", + "properties": { + "in": { + "enum": [ + "cookie" + ] + }, + "style": { + "enum": [ + "form" + ], + "default": "form" + } + } + }, + "RequestBody": { + "type": "object", + "required": [ + "content" + ], + "properties": { + "description": { + "type": "string" + }, + "content": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/MediaType" + } + }, + "required": { + "type": "boolean", + "default": false + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "SecurityScheme": { + "oneOf": [ + { + "$ref": "#/definitions/APIKeySecurityScheme" + }, + { + "$ref": "#/definitions/HTTPSecurityScheme" + }, + { + "$ref": "#/definitions/OAuth2SecurityScheme" + }, + { + "$ref": "#/definitions/OpenIdConnectSecurityScheme" + } + ] + }, + "APIKeySecurityScheme": { + "type": "object", + "required": [ + "type", + "name", + "in" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "apiKey" + ] + }, + "name": { + "type": "string" + }, + "in": { + "type": "string", + "enum": [ + "header", + "query", + "cookie" + ] + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "HTTPSecurityScheme": { + "type": "object", + "required": [ + "scheme", + "type" + ], + "properties": { + "scheme": { + "type": "string" + }, + "bearerFormat": { + "type": "string" + }, + "description": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "http" + ] + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false, + "oneOf": [ + { + "description": "Bearer", + "properties": { + "scheme": { + "type": "string", + "pattern": "^[Bb][Ee][Aa][Rr][Ee][Rr]$" + } + } + }, + { + "description": "Non Bearer", + "not": { + "required": [ + "bearerFormat" + ] + }, + "properties": { + "scheme": { + "not": { + "type": "string", + "pattern": "^[Bb][Ee][Aa][Rr][Ee][Rr]$" + } + } + } + } + ] + }, + "OAuth2SecurityScheme": { + "type": "object", + "required": [ + "type", + "flows" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "oauth2" + ] + }, + "flows": { + "$ref": "#/definitions/OAuthFlows" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "OpenIdConnectSecurityScheme": { + "type": "object", + "required": [ + "type", + "openIdConnectUrl" + ], + "properties": { + "type": { + "type": "string", + "enum": [ + "openIdConnect" + ] + }, + "openIdConnectUrl": { + "type": "string", + "format": "uri-reference" + }, + "description": { + "type": "string" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "OAuthFlows": { + "type": "object", + "properties": { + "implicit": { + "$ref": "#/definitions/ImplicitOAuthFlow" + }, + "password": { + "$ref": "#/definitions/PasswordOAuthFlow" + }, + "clientCredentials": { + "$ref": "#/definitions/ClientCredentialsFlow" + }, + "authorizationCode": { + "$ref": "#/definitions/AuthorizationCodeOAuthFlow" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "ImplicitOAuthFlow": { + "type": "object", + "required": [ + "authorizationUrl", + "scopes" + ], + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "PasswordOAuthFlow": { + "type": "object", + "required": [ + "tokenUrl", + "scopes" + ], + "properties": { + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "ClientCredentialsFlow": { + "type": "object", + "required": [ + "tokenUrl", + "scopes" + ], + "properties": { + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "AuthorizationCodeOAuthFlow": { + "type": "object", + "required": [ + "authorizationUrl", + "tokenUrl", + "scopes" + ], + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri-reference" + }, + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + }, + "Link": { + "type": "object", + "properties": { + "operationId": { + "type": "string" + }, + "operationRef": { + "type": "string", + "format": "uri-reference" + }, + "parameters": { + "type": "object", + "additionalProperties": {} + }, + "requestBody": {}, + "description": { + "type": "string" + }, + "server": { + "$ref": "#/definitions/Server" + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false, + "not": { + "description": "Operation Id and Operation Ref are mutually exclusive", + "required": [ + "operationId", + "operationRef" + ] + } + }, + "Callback": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/PathItem" + }, + "patternProperties": { + "^x-": {} + } + }, + "Encoding": { + "type": "object", + "properties": { + "contentType": { + "type": "string" + }, + "headers": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/definitions/Header" + }, + { + "$ref": "#/definitions/Reference" + } + ] + } + }, + "style": { + "type": "string", + "enum": [ + "form", + "spaceDelimited", + "pipeDelimited", + "deepObject" + ] + }, + "explode": { + "type": "boolean" + }, + "allowReserved": { + "type": "boolean", + "default": false + } + }, + "patternProperties": { + "^x-": {} + }, + "additionalProperties": false + } + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.3.1.json b/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.3.1.json new file mode 100644 index 0000000000..744f94a788 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/schemas/schema.3.1.json @@ -0,0 +1,1411 @@ +{ + "$id": "https://spec.openapis.org/oas/3.1/schema/2025-09-15", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "description": "The description of OpenAPI v3.1.x Documents without Schema Object validation", + "type": "object", + "properties": { + "openapi": { + "type": "string", + "pattern": "^3\\.1\\.\\d+(-.+)?$" + }, + "info": { + "$ref": "#/$defs/info" + }, + "jsonSchemaDialect": { + "type": "string", + "format": "uri-reference", + "default": "https://spec.openapis.org/oas/3.1/dialect/2024-11-10" + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/$defs/server" + }, + "default": [ + { + "url": "/" + } + ] + }, + "paths": { + "$ref": "#/$defs/paths" + }, + "webhooks": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/path-item" + } + }, + "components": { + "$ref": "#/$defs/components" + }, + "security": { + "type": "array", + "items": { + "$ref": "#/$defs/security-requirement" + } + }, + "tags": { + "type": "array", + "items": { + "$ref": "#/$defs/tag" + } + }, + "externalDocs": { + "$ref": "#/$defs/external-documentation" + } + }, + "required": [ + "openapi", + "info" + ], + "anyOf": [ + { + "required": [ + "paths" + ] + }, + { + "required": [ + "components" + ] + }, + { + "required": [ + "webhooks" + ] + } + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false, + "$defs": { + "info": { + "$comment": "https://spec.openapis.org/oas/v3.1#info-object", + "type": "object", + "properties": { + "title": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "termsOfService": { + "type": "string", + "format": "uri-reference" + }, + "contact": { + "$ref": "#/$defs/contact" + }, + "license": { + "$ref": "#/$defs/license" + }, + "version": { + "type": "string" + } + }, + "required": [ + "title", + "version" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "contact": { + "$comment": "https://spec.openapis.org/oas/v3.1#contact-object", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + }, + "email": { + "type": "string", + "format": "email" + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "license": { + "$comment": "https://spec.openapis.org/oas/v3.1#license-object", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "identifier": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + } + }, + "required": [ + "name" + ], + "dependentSchemas": { + "identifier": { + "not": { + "required": [ + "url" + ] + } + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "server": { + "$comment": "https://spec.openapis.org/oas/v3.1#server-object", + "type": "object", + "properties": { + "url": { + "type": "string" + }, + "description": { + "type": "string" + }, + "variables": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/server-variable" + } + } + }, + "required": [ + "url" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "server-variable": { + "$comment": "https://spec.openapis.org/oas/v3.1#server-variable-object", + "type": "object", + "properties": { + "enum": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1 + }, + "default": { + "type": "string" + }, + "description": { + "type": "string" + } + }, + "required": [ + "default" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "components": { + "$comment": "https://spec.openapis.org/oas/v3.1#components-object", + "type": "object", + "properties": { + "schemas": { + "type": "object", + "additionalProperties": { + "$dynamicRef": "#meta" + } + }, + "responses": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/response-or-reference" + } + }, + "parameters": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/parameter-or-reference" + } + }, + "examples": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/example-or-reference" + } + }, + "requestBodies": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/request-body-or-reference" + } + }, + "headers": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/header-or-reference" + } + }, + "securitySchemes": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/security-scheme-or-reference" + } + }, + "links": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/link-or-reference" + } + }, + "callbacks": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/callbacks-or-reference" + } + }, + "pathItems": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/path-item" + } + } + }, + "patternProperties": { + "^(?:schemas|responses|parameters|examples|requestBodies|headers|securitySchemes|links|callbacks|pathItems)$": { + "$comment": "Enumerating all of the property names in the regex above is necessary for unevaluatedProperties to work as expected", + "propertyNames": { + "pattern": "^[a-zA-Z0-9._-]+$" + } + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "paths": { + "$comment": "https://spec.openapis.org/oas/v3.1#paths-object", + "type": "object", + "patternProperties": { + "^/": { + "$ref": "#/$defs/path-item" + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "path-item": { + "$comment": "https://spec.openapis.org/oas/v3.1#path-item-object", + "type": "object", + "properties": { + "$ref": { + "type": "string", + "format": "uri-reference" + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/$defs/server" + } + }, + "parameters": { + "type": "array", + "items": { + "$ref": "#/$defs/parameter-or-reference" + } + }, + "get": { + "$ref": "#/$defs/operation" + }, + "put": { + "$ref": "#/$defs/operation" + }, + "post": { + "$ref": "#/$defs/operation" + }, + "delete": { + "$ref": "#/$defs/operation" + }, + "options": { + "$ref": "#/$defs/operation" + }, + "head": { + "$ref": "#/$defs/operation" + }, + "patch": { + "$ref": "#/$defs/operation" + }, + "trace": { + "$ref": "#/$defs/operation" + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "operation": { + "$comment": "https://spec.openapis.org/oas/v3.1#operation-object", + "type": "object", + "properties": { + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/$defs/external-documentation" + }, + "operationId": { + "type": "string" + }, + "parameters": { + "type": "array", + "items": { + "$ref": "#/$defs/parameter-or-reference" + } + }, + "requestBody": { + "$ref": "#/$defs/request-body-or-reference" + }, + "responses": { + "$ref": "#/$defs/responses" + }, + "callbacks": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/callbacks-or-reference" + } + }, + "deprecated": { + "default": false, + "type": "boolean" + }, + "security": { + "type": "array", + "items": { + "$ref": "#/$defs/security-requirement" + } + }, + "servers": { + "type": "array", + "items": { + "$ref": "#/$defs/server" + } + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "external-documentation": { + "$comment": "https://spec.openapis.org/oas/v3.1#external-documentation-object", + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri-reference" + } + }, + "required": [ + "url" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "parameter": { + "$comment": "https://spec.openapis.org/oas/v3.1#parameter-object", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "in": { + "enum": [ + "query", + "header", + "path", + "cookie" + ] + }, + "description": { + "type": "string" + }, + "required": { + "default": false, + "type": "boolean" + }, + "deprecated": { + "default": false, + "type": "boolean" + }, + "schema": { + "$dynamicRef": "#meta" + }, + "content": { + "$ref": "#/$defs/content", + "minProperties": 1, + "maxProperties": 1 + } + }, + "required": [ + "name", + "in" + ], + "oneOf": [ + { + "required": [ + "schema" + ] + }, + { + "required": [ + "content" + ] + } + ], + "if": { + "properties": { + "in": { + "const": "query" + } + } + }, + "then": { + "properties": { + "allowEmptyValue": { + "default": false, + "type": "boolean" + } + } + }, + "dependentSchemas": { + "schema": { + "properties": { + "style": { + "type": "string" + }, + "explode": { + "type": "boolean" + } + }, + "allOf": [ + { + "$ref": "#/$defs/examples" + }, + { + "$ref": "#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-path" + }, + { + "$ref": "#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-header" + }, + { + "$ref": "#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-query" + }, + { + "$ref": "#/$defs/parameter/dependentSchemas/schema/$defs/styles-for-cookie" + }, + { + "$ref": "#/$defs/styles-for-form" + } + ], + "$defs": { + "styles-for-path": { + "if": { + "properties": { + "in": { + "const": "path" + } + } + }, + "then": { + "properties": { + "style": { + "default": "simple", + "enum": [ + "matrix", + "label", + "simple" + ] + }, + "required": { + "const": true + } + }, + "required": [ + "required" + ] + } + }, + "styles-for-header": { + "if": { + "properties": { + "in": { + "const": "header" + } + } + }, + "then": { + "properties": { + "style": { + "default": "simple", + "const": "simple" + } + } + } + }, + "styles-for-query": { + "if": { + "properties": { + "in": { + "const": "query" + } + } + }, + "then": { + "properties": { + "style": { + "default": "form", + "enum": [ + "form", + "spaceDelimited", + "pipeDelimited", + "deepObject" + ] + }, + "allowReserved": { + "default": false, + "type": "boolean" + } + } + } + }, + "styles-for-cookie": { + "if": { + "properties": { + "in": { + "const": "cookie" + } + } + }, + "then": { + "properties": { + "style": { + "default": "form", + "const": "form" + } + } + } + } + } + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "parameter-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/parameter" + } + }, + "request-body": { + "$comment": "https://spec.openapis.org/oas/v3.1#request-body-object", + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "content": { + "$ref": "#/$defs/content" + }, + "required": { + "default": false, + "type": "boolean" + } + }, + "required": [ + "content" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "request-body-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/request-body" + } + }, + "content": { + "$comment": "https://spec.openapis.org/oas/v3.1#fixed-fields-10", + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/media-type" + }, + "propertyNames": { + "format": "media-range" + } + }, + "media-type": { + "$comment": "https://spec.openapis.org/oas/v3.1#media-type-object", + "type": "object", + "properties": { + "schema": { + "$dynamicRef": "#meta" + }, + "encoding": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/encoding" + } + } + }, + "allOf": [ + { + "$ref": "#/$defs/specification-extensions" + }, + { + "$ref": "#/$defs/examples" + } + ], + "unevaluatedProperties": false + }, + "encoding": { + "$comment": "https://spec.openapis.org/oas/v3.1#encoding-object", + "type": "object", + "properties": { + "contentType": { + "type": "string", + "format": "media-range" + }, + "headers": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/header-or-reference" + } + }, + "style": { + "enum": [ + "form", + "spaceDelimited", + "pipeDelimited", + "deepObject" + ] + }, + "explode": { + "type": "boolean" + }, + "allowReserved": { + "type": "boolean" + } + }, + "dependentSchemas": { + "style": { + "properties": { + "allowReserved": { + "default": false + } + } + }, + "explode": { + "properties": { + "style": { + "default": "form" + }, + "allowReserved": { + "default": false + } + } + }, + "allowReserved": { + "properties": { + "style": { + "default": "form" + } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs/specification-extensions" + }, + { + "$ref": "#/$defs/styles-for-form" + } + ], + "unevaluatedProperties": false + }, + "responses": { + "$comment": "https://spec.openapis.org/oas/v3.1#responses-object", + "type": "object", + "properties": { + "default": { + "$ref": "#/$defs/response-or-reference" + } + }, + "patternProperties": { + "^[1-5](?:[0-9]{2}|XX)$": { + "$ref": "#/$defs/response-or-reference" + } + }, + "minProperties": 1, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false, + "if": { + "$comment": "either default, or at least one response code property must exist", + "patternProperties": { + "^[1-5](?:[0-9]{2}|XX)$": false + } + }, + "then": { + "required": [ + "default" + ] + } + }, + "response": { + "$comment": "https://spec.openapis.org/oas/v3.1#response-object", + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "headers": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/header-or-reference" + } + }, + "content": { + "$ref": "#/$defs/content" + }, + "links": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/link-or-reference" + } + } + }, + "required": [ + "description" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "response-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/response" + } + }, + "callbacks": { + "$comment": "https://spec.openapis.org/oas/v3.1#callback-object", + "type": "object", + "$ref": "#/$defs/specification-extensions", + "additionalProperties": { + "$ref": "#/$defs/path-item" + } + }, + "callbacks-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/callbacks" + } + }, + "example": { + "$comment": "https://spec.openapis.org/oas/v3.1#example-object", + "type": "object", + "properties": { + "summary": { + "type": "string" + }, + "description": { + "type": "string" + }, + "value": true, + "externalValue": { + "type": "string", + "format": "uri-reference" + } + }, + "not": { + "required": [ + "value", + "externalValue" + ] + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "example-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/example" + } + }, + "link": { + "$comment": "https://spec.openapis.org/oas/v3.1#link-object", + "type": "object", + "properties": { + "operationRef": { + "type": "string", + "format": "uri-reference" + }, + "operationId": { + "type": "string" + }, + "parameters": { + "$ref": "#/$defs/map-of-strings" + }, + "requestBody": true, + "description": { + "type": "string" + }, + "server": { + "$ref": "#/$defs/server" + } + }, + "oneOf": [ + { + "required": [ + "operationRef" + ] + }, + { + "required": [ + "operationId" + ] + } + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "link-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/link" + } + }, + "header": { + "$comment": "https://spec.openapis.org/oas/v3.1#header-object", + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "required": { + "default": false, + "type": "boolean" + }, + "deprecated": { + "default": false, + "type": "boolean" + }, + "schema": { + "$dynamicRef": "#meta" + }, + "content": { + "$ref": "#/$defs/content", + "minProperties": 1, + "maxProperties": 1 + } + }, + "oneOf": [ + { + "required": [ + "schema" + ] + }, + { + "required": [ + "content" + ] + } + ], + "dependentSchemas": { + "schema": { + "properties": { + "style": { + "default": "simple", + "const": "simple" + }, + "explode": { + "default": false, + "type": "boolean" + } + }, + "$ref": "#/$defs/examples" + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "header-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/header" + } + }, + "tag": { + "$comment": "https://spec.openapis.org/oas/v3.1#tag-object", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "externalDocs": { + "$ref": "#/$defs/external-documentation" + } + }, + "required": [ + "name" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "reference": { + "$comment": "https://spec.openapis.org/oas/v3.1#reference-object", + "type": "object", + "properties": { + "$ref": { + "type": "string", + "format": "uri-reference" + }, + "summary": { + "type": "string" + }, + "description": { + "type": "string" + } + } + }, + "schema": { + "$comment": "https://spec.openapis.org/oas/v3.1#schema-object", + "$dynamicAnchor": "meta", + "type": [ + "object", + "boolean" + ] + }, + "security-scheme": { + "$comment": "https://spec.openapis.org/oas/v3.1#security-scheme-object", + "type": "object", + "properties": { + "type": { + "enum": [ + "apiKey", + "http", + "mutualTLS", + "oauth2", + "openIdConnect" + ] + }, + "description": { + "type": "string" + } + }, + "required": [ + "type" + ], + "allOf": [ + { + "$ref": "#/$defs/specification-extensions" + }, + { + "$ref": "#/$defs/security-scheme/$defs/type-apikey" + }, + { + "$ref": "#/$defs/security-scheme/$defs/type-http" + }, + { + "$ref": "#/$defs/security-scheme/$defs/type-http-bearer" + }, + { + "$ref": "#/$defs/security-scheme/$defs/type-oauth2" + }, + { + "$ref": "#/$defs/security-scheme/$defs/type-oidc" + } + ], + "unevaluatedProperties": false, + "$defs": { + "type-apikey": { + "if": { + "properties": { + "type": { + "const": "apiKey" + } + } + }, + "then": { + "properties": { + "name": { + "type": "string" + }, + "in": { + "enum": [ + "query", + "header", + "cookie" + ] + } + }, + "required": [ + "name", + "in" + ] + } + }, + "type-http": { + "if": { + "properties": { + "type": { + "const": "http" + } + } + }, + "then": { + "properties": { + "scheme": { + "type": "string" + } + }, + "required": [ + "scheme" + ] + } + }, + "type-http-bearer": { + "if": { + "properties": { + "type": { + "const": "http" + }, + "scheme": { + "type": "string", + "pattern": "^[Bb][Ee][Aa][Rr][Ee][Rr]$" + } + }, + "required": [ + "type", + "scheme" + ] + }, + "then": { + "properties": { + "bearerFormat": { + "type": "string" + } + } + } + }, + "type-oauth2": { + "if": { + "properties": { + "type": { + "const": "oauth2" + } + } + }, + "then": { + "properties": { + "flows": { + "$ref": "#/$defs/oauth-flows" + } + }, + "required": [ + "flows" + ] + } + }, + "type-oidc": { + "if": { + "properties": { + "type": { + "const": "openIdConnect" + } + } + }, + "then": { + "properties": { + "openIdConnectUrl": { + "type": "string", + "format": "uri-reference" + } + }, + "required": [ + "openIdConnectUrl" + ] + } + } + } + }, + "security-scheme-or-reference": { + "if": { + "type": "object", + "required": [ + "$ref" + ] + }, + "then": { + "$ref": "#/$defs/reference" + }, + "else": { + "$ref": "#/$defs/security-scheme" + } + }, + "oauth-flows": { + "type": "object", + "properties": { + "implicit": { + "$ref": "#/$defs/oauth-flows/$defs/implicit" + }, + "password": { + "$ref": "#/$defs/oauth-flows/$defs/password" + }, + "clientCredentials": { + "$ref": "#/$defs/oauth-flows/$defs/client-credentials" + }, + "authorizationCode": { + "$ref": "#/$defs/oauth-flows/$defs/authorization-code" + } + }, + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false, + "$defs": { + "implicit": { + "type": "object", + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "$ref": "#/$defs/map-of-strings" + } + }, + "required": [ + "authorizationUrl", + "scopes" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "password": { + "type": "object", + "properties": { + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "$ref": "#/$defs/map-of-strings" + } + }, + "required": [ + "tokenUrl", + "scopes" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "client-credentials": { + "type": "object", + "properties": { + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "$ref": "#/$defs/map-of-strings" + } + }, + "required": [ + "tokenUrl", + "scopes" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + }, + "authorization-code": { + "type": "object", + "properties": { + "authorizationUrl": { + "type": "string", + "format": "uri-reference" + }, + "tokenUrl": { + "type": "string", + "format": "uri-reference" + }, + "refreshUrl": { + "type": "string", + "format": "uri-reference" + }, + "scopes": { + "$ref": "#/$defs/map-of-strings" + } + }, + "required": [ + "authorizationUrl", + "tokenUrl", + "scopes" + ], + "$ref": "#/$defs/specification-extensions", + "unevaluatedProperties": false + } + } + }, + "security-requirement": { + "$comment": "https://spec.openapis.org/oas/v3.1#security-requirement-object", + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "specification-extensions": { + "$comment": "https://spec.openapis.org/oas/v3.1#specification-extensions", + "patternProperties": { + "^x-": {} + } + }, + "examples": { + "properties": { + "example": true, + "examples": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/example-or-reference" + } + } + }, + "not": { + "required": [ + "example", + "examples" + ] + } + }, + "map-of-strings": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "styles-for-form": { + "if": { + "properties": { + "style": { + "const": "form" + } + }, + "required": [ + "style" + ] + }, + "then": { + "properties": { + "explode": { + "default": true + } + } + }, + "else": { + "properties": { + "explode": { + "default": false + } + } + } + } + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/ApiRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/ApiRequestBuilder.verified.cs new file mode 100644 index 0000000000..3089b919fb --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/ApiRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +using TodoApp.Client.Api.Items; +namespace TodoApp.Client.Api +{ + /// + /// Builds and executes requests for operations under \api + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ApiRequestBuilder : BaseRequestBuilder + { + /// The items property + public global::TodoApp.Client.Api.Items.ItemsRequestBuilder Items + { + get => new global::TodoApp.Client.Api.Items.ItemsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Find/FindRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Find/FindRequestBuilder.verified.cs new file mode 100644 index 0000000000..1e6da55fa3 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Find/FindRequestBuilder.verified.cs @@ -0,0 +1,94 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Find +{ + /// + /// Builds and executes requests for operations under \api\items\find + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FindRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FindRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/find?IsCompleted={IsCompleted}&Text={Text}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FindRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/find?IsCompleted={IsCompleted}&Text={Text}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Find.FindRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Find.FindRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class FindRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + /// Gets or sets a value indicating whether to search completed Todo items. + public bool? IsCompleted { get; set; } + /// Gets or sets the text of the filter. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/GetAfter/GetAfterRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/GetAfter/GetAfterRequestBuilder.verified.cs new file mode 100644 index 0000000000..d420636015 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/GetAfter/GetAfterRequestBuilder.verified.cs @@ -0,0 +1,86 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.GetAfter +{ + /// + /// Builds and executes requests for operations under \api\items\getAfter + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class GetAfterRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public GetAfterRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/getAfter?value={value}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public GetAfterRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/getAfter?value={value}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class GetAfterRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + [QueryParameter("value")] + public DateTimeOffset? Value { get; set; } + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/Complete/CompleteRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/Complete/CompleteRequestBuilder.verified.cs new file mode 100644 index 0000000000..09e8901d32 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/Complete/CompleteRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Item.Complete +{ + /// + /// Builds and executes requests for operations under \api\items\{id}\complete + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CompleteRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CompleteRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/complete", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CompleteRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/complete", rawUrl) + { + } + /// + /// Marks the todo item with the specified ID as complete. + /// + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToPostRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Marks the todo item with the specified ID as complete. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/ItemsItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/ItemsItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..e3acec88bd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/ItemsItemRequestBuilder.verified.cs @@ -0,0 +1,142 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Api.Items.Item.Complete; +using TodoApp.Client.Api.Items.Item.Priority; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Item +{ + /// + /// Builds and executes requests for operations under \api\items\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsItemRequestBuilder : BaseRequestBuilder + { + /// The complete property + public global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder Complete + { + get => new global::TodoApp.Client.Api.Items.Item.Complete.CompleteRequestBuilder(PathParameters, RequestAdapter); + } + /// The priority property + public global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder Priority + { + get => new global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ItemsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ItemsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}", rawUrl) + { + } + /// + /// Deletes the todo item with the specified ID. + /// + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Gets the todo item with the specified ID. + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoItemModel.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Deletes the todo item with the specified ID. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + return requestInfo; + } + /// + /// Gets the todo item with the specified ID. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/Priority/PriorityRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/Priority/PriorityRequestBuilder.verified.cs new file mode 100644 index 0000000000..6df4f2ccf7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/Item/Priority/PriorityRequestBuilder.verified.cs @@ -0,0 +1,95 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items.Item.Priority +{ + /// + /// Builds and executes requests for operations under \api\items\{id}\priority + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class PriorityRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public PriorityRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/priority", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public PriorityRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/priority", rawUrl) + { + } + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// Represents the model for updating the priority of a Todo item. + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PatchAsync(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PatchAsync(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPatchRequestInformation(body, requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + { "404", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// A + /// Represents the model for updating the priority of a Todo item. + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPatchRequestInformation(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPatchRequestInformation(global::TodoApp.Client.Models.UpdateTodoItemPriorityModel body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PATCH, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.Item.Priority.PriorityRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/ItemsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/ItemsRequestBuilder.verified.cs new file mode 100644 index 0000000000..af6df99c5b --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Api/Items/ItemsRequestBuilder.verified.cs @@ -0,0 +1,156 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +using TodoApp.Client.Api.Items.Find; +using TodoApp.Client.Api.Items.GetAfter; +using TodoApp.Client.Api.Items.Item; +using TodoApp.Client.Models; +namespace TodoApp.Client.Api.Items +{ + /// + /// Builds and executes requests for operations under \api\items + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsRequestBuilder : BaseRequestBuilder + { + /// The find property + public global::TodoApp.Client.Api.Items.Find.FindRequestBuilder Find + { + get => new global::TodoApp.Client.Api.Items.Find.FindRequestBuilder(PathParameters, RequestAdapter); + } + /// The getAfter property + public global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder GetAfter + { + get => new global::TodoApp.Client.Api.Items.GetAfter.GetAfterRequestBuilder(PathParameters, RequestAdapter); + } + /// Gets an item from the TodoApp.Client.api.items.item collection + /// The Todo item's ID. + /// A + public global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder this[Guid position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::TodoApp.Client.Api.Items.Item.ItemsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ItemsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ItemsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items", rawUrl) + { + } + /// + /// Gets all of the current user's todo items. + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// A + /// Represents the model for creating a new Todo item. + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::TodoApp.Client.Models.CreateTodoItemModel body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::TodoApp.Client.Models.CreateTodoItemModel body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::TodoApp.Client.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::TodoApp.Client.Models.CreatedTodoItemModel.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Gets all of the current user's todo items. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// A + /// Represents the model for creating a new Todo item. + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::TodoApp.Client.Models.CreateTodoItemModel body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::TodoApp.Client.Models.CreateTodoItemModel body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::TodoApp.Client.Api.Items.ItemsRequestBuilder WithUrl(string rawUrl) + { + return new global::TodoApp.Client.Api.Items.ItemsRequestBuilder(rawUrl, RequestAdapter); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/CreateTodoItemModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/CreateTodoItemModel.verified.cs new file mode 100644 index 0000000000..facd4f1345 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/CreateTodoItemModel.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents the model for creating a new Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CreateTodoItemModel : IParsable + { + /// Gets or sets the text of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.CreateTodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.CreateTodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "text", n => { Text = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("text", Text); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/CreatedTodoItemModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/CreatedTodoItemModel.verified.cs new file mode 100644 index 0000000000..ab6ca282e9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/CreatedTodoItemModel.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents the model for a created Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CreatedTodoItemModel : IParsable + { + /// Gets or sets the ID of the created Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Id { get; set; } +#nullable restore +#else + public string Id { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.CreatedTodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.CreatedTodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "id", n => { Id = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/ProblemDetails.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/ProblemDetails.verified.cs new file mode 100644 index 0000000000..1773cc90ee --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/ProblemDetails.verified.cs @@ -0,0 +1,92 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProblemDetails : ApiException, IParsable + #pragma warning restore CS1591 + { + /// The detail property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Detail { get; set; } +#nullable restore +#else + public string Detail { get; set; } +#endif + /// The instance property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Instance { get; set; } +#nullable restore +#else + public string Instance { get; set; } +#endif + /// The primary error message. + public override string Message { get => base.Message; } + /// The status property + public int? Status { get; set; } + /// The title property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Title { get; set; } +#nullable restore +#else + public string Title { get; set; } +#endif + /// The type property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Type { get; set; } +#nullable restore +#else + public string Type { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.ProblemDetails CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.ProblemDetails(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "detail", n => { Detail = n.GetStringValue(); } }, + { "instance", n => { Instance = n.GetStringValue(); } }, + { "status", n => { Status = n.GetIntValue(); } }, + { "title", n => { Title = n.GetStringValue(); } }, + { "type", n => { Type = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("detail", Detail); + writer.WriteStringValue("instance", Instance); + writer.WriteIntValue("status", Status); + writer.WriteStringValue("title", Title); + writer.WriteStringValue("type", Type); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoItemModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoItemModel.verified.cs new file mode 100644 index 0000000000..f9e6233aca --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoItemModel.verified.cs @@ -0,0 +1,82 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents a Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoItemModel : IParsable + { + /// Gets or sets the date and time the item was completed. + public DateTimeOffset? CompletedAt { get; set; } + /// Gets or sets the date and time the item was created. + public DateTimeOffset? CreatedAt { get; set; } + /// Gets or sets the ID of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Id { get; set; } +#nullable restore +#else + public string Id { get; set; } +#endif + /// Gets or sets the date and time the Todo item was last updated. + public DateTimeOffset? LastUpdated { get; set; } + /// Gets or sets the optional priority of the Todo item. + public global::TodoApp.Client.Models.TodoPriority? Priority { get; set; } + /// Gets or sets the text of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.TodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.TodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "completedAt", n => { CompletedAt = n.GetDateTimeOffsetValue(); } }, + { "createdAt", n => { CreatedAt = n.GetDateTimeOffsetValue(); } }, + { "id", n => { Id = n.GetStringValue(); } }, + { "lastUpdated", n => { LastUpdated = n.GetDateTimeOffsetValue(); } }, + { "priority", n => { Priority = n.GetEnumValue(); } }, + { "text", n => { Text = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDateTimeOffsetValue("completedAt", CompletedAt); + writer.WriteDateTimeOffsetValue("createdAt", CreatedAt); + writer.WriteStringValue("id", Id); + writer.WriteDateTimeOffsetValue("lastUpdated", LastUpdated); + writer.WriteEnumValue("priority", Priority); + writer.WriteStringValue("text", Text); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoListViewModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoListViewModel.verified.cs new file mode 100644 index 0000000000..eb520f51c2 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoListViewModel.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents a collection of Todo items. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoListViewModel : IParsable + { + /// Gets or sets the Todo item(s). +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public List? Items { get; set; } +#nullable restore +#else + public List Items { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.TodoListViewModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.TodoListViewModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "items", n => { Items = n.GetCollectionOfObjectValues(global::TodoApp.Client.Models.TodoItemModel.CreateFromDiscriminatorValue)?.AsList(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteCollectionOfObjectValues("items", Items); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoPriority.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoPriority.verified.cs new file mode 100644 index 0000000000..3ff868a37c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/TodoPriority.verified.cs @@ -0,0 +1,23 @@ +// +using System.Runtime.Serialization; +using System; +namespace TodoApp.Client.Models +{ + /// The priority levels for a Todo item. + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public enum TodoPriority + { + [EnumMember(Value = "Normal")] + #pragma warning disable CS1591 + Normal, + #pragma warning restore CS1591 + [EnumMember(Value = "Low")] + #pragma warning disable CS1591 + Low, + #pragma warning restore CS1591 + [EnumMember(Value = "High")] + #pragma warning disable CS1591 + High, + #pragma warning restore CS1591 + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/UpdateTodoItemPriorityModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/UpdateTodoItemPriorityModel.verified.cs new file mode 100644 index 0000000000..7febaace2e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/Models/UpdateTodoItemPriorityModel.verified.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace TodoApp.Client.Models +{ + /// + /// Represents the model for updating the priority of a Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class UpdateTodoItemPriorityModel : IParsable + { + /// Gets or sets the new priority of the Todo item. + public global::TodoApp.Client.Models.TodoPriority? Priority { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::TodoApp.Client.Models.UpdateTodoItemPriorityModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::TodoApp.Client.Models.UpdateTodoItemPriorityModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "priority", n => { Priority = n.GetEnumValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteEnumValue("priority", Priority); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/TodoApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/TodoApiClient.verified.cs new file mode 100644 index 0000000000..a78b7241a4 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/CodeGenerationTests.VerifyKiotaTodoAppClient/TodoApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +using TodoApp.Client.Api; +namespace TodoApp.Client +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoApiClient : BaseRequestBuilder + { + /// The api property + public global::TodoApp.Client.Api.ApiRequestBuilder Api + { + get => new global::TodoApp.Client.Api.ApiRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public TodoApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..32c694c3e9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..e77961fa65 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_0452f380fe4cda4f/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/AnnotationsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/AnnotationsRequestBuilder.verified.cs new file mode 100644 index 0000000000..73d841b894 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/AnnotationsRequestBuilder.verified.cs @@ -0,0 +1,77 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations +{ + /// + /// Builds and executes requests for operations under \annotations + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AnnotationsRequestBuilder : BaseRequestBuilder + { + /// The AsParameters property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder AsParameters + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder(PathParameters, RequestAdapter); + } + /// The fruit property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.FruitRequestBuilder Fruit + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.FruitRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndEnum property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder IFromFileAndEnum + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder IFromFileAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromObjectAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder IFromObjectAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The multipleForms property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder MultipleForms + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder(PathParameters, RequestAdapter); + } + /// The singleForm property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder SingleForm + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AnnotationsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AnnotationsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/AsParameters/AsParametersRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/AsParameters/AsParametersRequestBuilder.verified.cs new file mode 100644 index 0000000000..c314460094 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/AsParameters/AsParametersRequestBuilder.verified.cs @@ -0,0 +1,117 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters +{ + /// + /// Builds and executes requests for operations under \annotations\AsParameters + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AsParametersRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AsParametersRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/AsParameters?paramEight={paramEight}¶mFour={paramFour}¶mSix={paramSix}¶mTen={paramTen}¶mTwelve={paramTwelve}¶mTwo={paramTwo}{¶mEleven*,paramFive*,paramNine*,paramOne*,paramSeven*,paramThree*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AsParametersRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/AsParameters?paramEight={paramEight}¶mFour={paramFour}¶mSix={paramSix}¶mTen={paramTen}¶mTwelve={paramTwelve}¶mTwo={paramTwo}{¶mEleven*,paramFive*,paramNine*,paramOne*,paramSeven*,paramThree*}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.AsParametersRecord.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class AsParametersRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + [QueryParameter("paramEight")] + public Time? ParamEight { get; set; } + [QueryParameter("paramEleven")] + public double? ParamEleven { get; set; } + [QueryParameter("paramFive")] + public Date? ParamFive { get; set; } + [QueryParameter("paramFour")] + public DateTimeOffset? ParamFour { get; set; } + [QueryParameter("paramNine")] + public int? ParamNine { get; set; } + /// Description + [QueryParameter("paramOne")] + public Guid? ParamOne { get; set; } + [QueryParameter("paramSeven")] + public Time? ParamSeven { get; set; } + [QueryParameter("paramSix")] + public Date? ParamSix { get; set; } + [QueryParameter("paramTen")] + public int? ParamTen { get; set; } + [QueryParameter("paramThree")] + public DateTimeOffset? ParamThree { get; set; } + [QueryParameter("paramTwelve")] + public double? ParamTwelve { get; set; } + [QueryParameter("paramTwo")] + public Guid? ParamTwo { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AsParametersRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/Fruit/FruitRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/Fruit/FruitRequestBuilder.verified.cs new file mode 100644 index 0000000000..1f743a2e89 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/Fruit/FruitRequestBuilder.verified.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit +{ + /// + /// Builds and executes requests for operations under \annotations\fruit + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FruitRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.annotations.fruit.item collection + /// The id of the fruit that will be created + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FruitRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FruitRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/Fruit/Item/FruitItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/Fruit/Item/FruitItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..2408b0a15d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/Fruit/Item/FruitItemRequestBuilder.verified.cs @@ -0,0 +1,97 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item +{ + /// + /// Builds and executes requests for operations under \annotations\fruit\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FruitItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FruitItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FruitItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit/{id}", rawUrl) + { + } + /// + /// Create a fruit + /// + /// A + /// Description for Schema + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Create a fruit + /// + /// A + /// Description for Schema + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FruitItemRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs new file mode 100644 index 0000000000..72889a4a75 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum +{ + /// + /// Builds and executes requests for operations under \annotations\IFromFileAndEnum + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndEnum", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndEnum", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..6cf1bf4636 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString +{ + /// + /// Builds and executes requests for operations under \annotations\IFromFileAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs new file mode 100644 index 0000000000..654ac6720d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs @@ -0,0 +1,67 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class IFromObjectAndStringPostRequestBody : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The tags property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Tags { get; set; } +#nullable restore +#else + public string Tags { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public IFromObjectAndStringPostRequestBody() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "tags", n => { Tags = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("tags", Tags); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..6fa13e87ac --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString +{ + /// + /// Builds and executes requests for operations under \annotations\IFromObjectAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromObjectAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromObjectAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/MultipleForms/MultipleFormsPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/MultipleForms/MultipleFormsPostRequestBody.verified.cs new file mode 100644 index 0000000000..1daf33186d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/MultipleForms/MultipleFormsPostRequestBody.verified.cs @@ -0,0 +1,115 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class MultipleFormsPostRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The city property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? City { get; set; } +#nullable restore +#else + public string City { get; set; } +#endif + /// Description for FirstName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// Description for LastName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// The state property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? State { get; set; } +#nullable restore +#else + public string State { get; set; } +#endif + /// Description for Street +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Street { get; set; } +#nullable restore +#else + public string Street { get; set; } +#endif + /// The zipCode property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? ZipCode { get; set; } +#nullable restore +#else + public string ZipCode { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public MultipleFormsPostRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "city", n => { City = n.GetStringValue(); } }, + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + { "state", n => { State = n.GetStringValue(); } }, + { "street", n => { Street = n.GetStringValue(); } }, + { "zipCode", n => { ZipCode = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("city", City); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + writer.WriteStringValue("state", State); + writer.WriteStringValue("street", Street); + writer.WriteStringValue("zipCode", ZipCode); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/MultipleForms/MultipleFormsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/MultipleForms/MultipleFormsRequestBuilder.verified.cs new file mode 100644 index 0000000000..78e5cdc7fc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/MultipleForms/MultipleFormsRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms +{ + /// + /// Builds and executes requests for operations under \annotations\multipleForms + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/multipleForms", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/multipleForms", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/SingleForm/SingleFormRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/SingleForm/SingleFormRequestBuilder.verified.cs new file mode 100644 index 0000000000..9f80518ba2 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Annotations/SingleForm/SingleFormRequestBuilder.verified.cs @@ -0,0 +1,91 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm +{ + /// + /// Builds and executes requests for operations under \annotations\singleForm + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SingleFormRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public SingleFormRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/singleForm", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public SingleFormRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/singleForm", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/x-www-form-urlencoded", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SingleFormRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..1d9f32b2bc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/KiotaOpenApiClient.verified.cs @@ -0,0 +1,61 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The annotations property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AnnotationsRequestBuilder Annotations + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AnnotationsRequestBuilder(PathParameters, RequestAdapter); + } + /// The TypeWithTryParse property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.TypeWithTryParseRequestBuilder TypeWithTryParse + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.TypeWithTryParseRequestBuilder(PathParameters, RequestAdapter); + } + /// The WithOpenApi property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.WithOpenApiRequestBuilder WithOpenApi + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.WithOpenApiRequestBuilder(PathParameters, RequestAdapter); + } + /// The XmlComments property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.XmlCommentsRequestBuilder XmlComments + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.XmlCommentsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/AsParametersRecord.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/AsParametersRecord.verified.cs new file mode 100644 index 0000000000..b703f26d0a --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/AsParametersRecord.verified.cs @@ -0,0 +1,94 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class AsParametersRecord : IParsable + #pragma warning restore CS1591 + { + /// The paramEight property + public Time? ParamEight { get; set; } + /// The paramEleven property + public double? ParamEleven { get; set; } + /// The paramFive property + public Date? ParamFive { get; set; } + /// The paramFour property + public DateTimeOffset? ParamFour { get; set; } + /// The paramNine property + public int? ParamNine { get; set; } + /// The paramOne property + public Guid? ParamOne { get; set; } + /// The paramSeven property + public Time? ParamSeven { get; set; } + /// The paramSix property + public Date? ParamSix { get; set; } + /// The paramTen property + public int? ParamTen { get; set; } + /// The paramThree property + public DateTimeOffset? ParamThree { get; set; } + /// The paramTwelve property + public double? ParamTwelve { get; set; } + /// The paramTwo property + public Guid? ParamTwo { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.AsParametersRecord CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.AsParametersRecord(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "paramEight", n => { ParamEight = n.GetTimeValue(); } }, + { "paramEleven", n => { ParamEleven = n.GetDoubleValue(); } }, + { "paramFive", n => { ParamFive = n.GetDateValue(); } }, + { "paramFour", n => { ParamFour = n.GetDateTimeOffsetValue(); } }, + { "paramNine", n => { ParamNine = n.GetIntValue(); } }, + { "paramOne", n => { ParamOne = n.GetGuidValue(); } }, + { "paramSeven", n => { ParamSeven = n.GetTimeValue(); } }, + { "paramSix", n => { ParamSix = n.GetDateValue(); } }, + { "paramTen", n => { ParamTen = n.GetIntValue(); } }, + { "paramThree", n => { ParamThree = n.GetDateTimeOffsetValue(); } }, + { "paramTwelve", n => { ParamTwelve = n.GetDoubleValue(); } }, + { "paramTwo", n => { ParamTwo = n.GetGuidValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteTimeValue("paramEight", ParamEight); + writer.WriteDoubleValue("paramEleven", ParamEleven); + writer.WriteDateValue("paramFive", ParamFive); + writer.WriteDateTimeOffsetValue("paramFour", ParamFour); + writer.WriteIntValue("paramNine", ParamNine); + writer.WriteGuidValue("paramOne", ParamOne); + writer.WriteTimeValue("paramSeven", ParamSeven); + writer.WriteDateValue("paramSix", ParamSix); + writer.WriteIntValue("paramTen", ParamTen); + writer.WriteDateTimeOffsetValue("paramThree", ParamThree); + writer.WriteDoubleValue("paramTwelve", ParamTwelve); + writer.WriteGuidValue("paramTwo", ParamTwo); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/CurrenciesRate.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/CurrenciesRate.verified.cs new file mode 100644 index 0000000000..b11e7225fd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/CurrenciesRate.verified.cs @@ -0,0 +1,69 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class CurrenciesRate : IParsable + #pragma warning restore CS1591 + { + /// Currency From +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CurrencyFrom { get; set; } +#nullable restore +#else + public string CurrencyFrom { get; set; } +#endif + /// The currencyTo property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CurrencyTo { get; set; } +#nullable restore +#else + public string CurrencyTo { get; set; } +#endif + /// The rate property + public double? Rate { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CurrenciesRate CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CurrenciesRate(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "currencyFrom", n => { CurrencyFrom = n.GetStringValue(); } }, + { "currencyTo", n => { CurrencyTo = n.GetStringValue(); } }, + { "rate", n => { Rate = n.GetDoubleValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("currencyFrom", CurrencyFrom); + writer.WriteStringValue("currencyTo", CurrencyTo); + writer.WriteDoubleValue("rate", Rate); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Fruit.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Fruit.verified.cs new file mode 100644 index 0000000000..8ce9761fec --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Fruit.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Description for Schema + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class Fruit : IParsable + { + /// The name property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Name { get; set; } +#nullable restore +#else + public string Name { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "name", n => { Name = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("name", Name); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/OrganizationCustomExchangeRatesDto.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/OrganizationCustomExchangeRatesDto.verified.cs new file mode 100644 index 0000000000..5cd77a470e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/OrganizationCustomExchangeRatesDto.verified.cs @@ -0,0 +1,58 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class OrganizationCustomExchangeRatesDto : IParsable + #pragma warning restore CS1591 + { + /// The currenciesRates property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public List? CurrenciesRates { get; set; } +#nullable restore +#else + public List CurrenciesRates { get; set; } +#endif + /// The isUpdated property + public bool? IsUpdated { get; private set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "currenciesRates", n => { CurrenciesRates = n.GetCollectionOfObjectValues(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CurrenciesRate.CreateFromDiscriminatorValue)?.AsList(); } }, + { "isUpdated", n => { IsUpdated = n.GetBoolValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteCollectionOfObjectValues("currenciesRates", CurrenciesRates); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Person.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Person.verified.cs new file mode 100644 index 0000000000..50466e2a4d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Person.verified.cs @@ -0,0 +1,65 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Person : IParsable + #pragma warning restore CS1591 + { + /// The firstName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// The lastName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Person CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Person(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/PersonAnnotated.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/PersonAnnotated.verified.cs new file mode 100644 index 0000000000..b21d6a6ae7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/PersonAnnotated.verified.cs @@ -0,0 +1,65 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class PersonAnnotated : IParsable + #pragma warning restore CS1591 + { + /// Description for FirstName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// Description for LastName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Product.verified.cs new file mode 100644 index 0000000000..77c098a9d5 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/Product.verified.cs @@ -0,0 +1,63 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents a product + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class Product : ApiException, IParsable + { + /// Describes the product +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// Uniquely identifies the product + public int? Id { get; set; } + /// The primary error message. + public override string Message { get => base.Message; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/WeatherForecast.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/WeatherForecast.verified.cs new file mode 100644 index 0000000000..8dbad82e4f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/Models/WeatherForecast.verified.cs @@ -0,0 +1,67 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class WeatherForecast : IParsable + #pragma warning restore CS1591 + { + /// The date property + public Date? Date { get; set; } + /// The summary property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Summary { get; set; } +#nullable restore +#else + public string Summary { get; set; } +#endif + /// The temperatureC property + public int? TemperatureC { get; set; } + /// The temperatureF property + public int? TemperatureF { get; private set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "date", n => { Date = n.GetDateValue(); } }, + { "summary", n => { Summary = n.GetStringValue(); } }, + { "temperatureC", n => { TemperatureC = n.GetIntValue(); } }, + { "temperatureF", n => { TemperatureF = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDateValue("date", Date); + writer.WriteStringValue("summary", Summary); + writer.WriteIntValue("temperatureC", TemperatureC); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/TypeWithTryParse/Item/WithTryParseItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/TypeWithTryParse/Item/WithTryParseItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..055941e1a7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/TypeWithTryParse/Item/WithTryParseItemRequestBuilder.verified.cs @@ -0,0 +1,85 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item +{ + /// + /// Builds and executes requests for operations under \TypeWithTryParse\{tryParse} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithTryParseItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WithTryParseItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse/{tryParse}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WithTryParseItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse/{tryParse}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithTryParseItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/TypeWithTryParse/TypeWithTryParseRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/TypeWithTryParse/TypeWithTryParseRequestBuilder.verified.cs new file mode 100644 index 0000000000..a7f8892ecd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/TypeWithTryParse/TypeWithTryParseRequestBuilder.verified.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse +{ + /// + /// Builds and executes requests for operations under \TypeWithTryParse + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TypeWithTryParseRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("tryParse", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public TypeWithTryParseRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public TypeWithTryParseRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromBody/IFromBodyRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromBody/IFromBodyRequestBuilder.verified.cs new file mode 100644 index 0000000000..9f5b657944 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromBody/IFromBodyRequestBuilder.verified.cs @@ -0,0 +1,91 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromBody + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromBodyRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromBodyRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromBody", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromBodyRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromBody", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromBodyRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFile/IFromFileRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFile/IFromFileRequestBuilder.verified.cs new file mode 100644 index 0000000000..61b5424207 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFile/IFromFileRequestBuilder.verified.cs @@ -0,0 +1,105 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFile + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFile?queryParameter={queryParameter}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFile?queryParameter={queryParameter}", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class IFromFileRequestBuilderPostQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("queryParameter")] + public string? QueryParameter { get; set; } +#nullable restore +#else + [QueryParameter("queryParameter")] + public string QueryParameter { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs new file mode 100644 index 0000000000..1500ddcbce --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFileAndEnum + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndEnum", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndEnum", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..106c2340f6 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFileAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileCollection/IFromFileCollectionRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileCollection/IFromFileCollectionRequestBuilder.verified.cs new file mode 100644 index 0000000000..4afacd0856 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromFileCollection/IFromFileCollectionRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFileCollection + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileCollectionRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileCollectionRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileCollection", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileCollectionRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileCollection", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileCollectionRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs new file mode 100644 index 0000000000..a3c1dcaffc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs @@ -0,0 +1,67 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class IFromObjectAndStringPostRequestBody : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Person, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The tags property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Tags { get; set; } +#nullable restore +#else + public string Tags { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public IFromObjectAndStringPostRequestBody() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "tags", n => { Tags = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("tags", Tags); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..59724371cd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromObjectAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromObjectAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromObjectAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/MultipleForms/MultipleFormsPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/MultipleForms/MultipleFormsPostRequestBody.verified.cs new file mode 100644 index 0000000000..0b0a90cc76 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/MultipleForms/MultipleFormsPostRequestBody.verified.cs @@ -0,0 +1,115 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class MultipleFormsPostRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The city property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? City { get; set; } +#nullable restore +#else + public string City { get; set; } +#endif + /// The firstName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// The lastName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// The state property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? State { get; set; } +#nullable restore +#else + public string State { get; set; } +#endif + /// The street property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Street { get; set; } +#nullable restore +#else + public string Street { get; set; } +#endif + /// The zipCode property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? ZipCode { get; set; } +#nullable restore +#else + public string ZipCode { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public MultipleFormsPostRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "city", n => { City = n.GetStringValue(); } }, + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + { "state", n => { State = n.GetStringValue(); } }, + { "street", n => { Street = n.GetStringValue(); } }, + { "zipCode", n => { ZipCode = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("city", City); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + writer.WriteStringValue("state", State); + writer.WriteStringValue("street", Street); + writer.WriteStringValue("zipCode", ZipCode); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/MultipleForms/MultipleFormsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/MultipleForms/MultipleFormsRequestBuilder.verified.cs new file mode 100644 index 0000000000..e6aca56210 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/MultipleForms/MultipleFormsRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\multipleForms + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/multipleForms", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/multipleForms", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/Weatherforecast/WeatherforecastRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/Weatherforecast/WeatherforecastRequestBuilder.verified.cs new file mode 100644 index 0000000000..94751af1af --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/Weatherforecast/WeatherforecastRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\weatherforecast + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherforecastRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WeatherforecastRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/weatherforecast", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WeatherforecastRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/weatherforecast", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherforecastRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/WithOpenApiRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/WithOpenApiRequestBuilder.verified.cs new file mode 100644 index 0000000000..ce7b199d2d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/WithOpenApi/WithOpenApiRequestBuilder.verified.cs @@ -0,0 +1,83 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi +{ + /// + /// Builds and executes requests for operations under \WithOpenApi + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithOpenApiRequestBuilder : BaseRequestBuilder + { + /// The IFromBody property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder IFromBody + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFile property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder IFromFile + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndEnum property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder IFromFileAndEnum + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder IFromFileAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileCollection property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder IFromFileCollection + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromObjectAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder IFromObjectAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The multipleForms property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder MultipleForms + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder(PathParameters, RequestAdapter); + } + /// The weatherforecast property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder Weatherforecast + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WithOpenApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WithOpenApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/Car/CarRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/Car/CarRequestBuilder.verified.cs new file mode 100644 index 0000000000..00c5cffc6e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/Car/CarRequestBuilder.verified.cs @@ -0,0 +1,135 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car +{ + /// + /// Builds and executes requests for operations under \XmlComments\Car + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.item collection + /// The product id + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.item collection + /// The product id + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car?Id={Id}{&Description*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car?Id={Id}{&Description*}", rawUrl) + { + } + /// + /// Returns a specific product using asParameters record + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product using asParameters record + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Returns a specific product using asParameters record + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarRequestBuilderGetQueryParameters + { + /// Describes the product +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// Uniquely identifies the product + public int? Id { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/Car/Item/CarItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/Car/Item/CarItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..92c6c82214 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/Car/Item/CarItemRequestBuilder.verified.cs @@ -0,0 +1,92 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item +{ + /// + /// Builds and executes requests for operations under \XmlComments\Car\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car/{id}", rawUrl) + { + } + /// + /// Returns a specific product + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/CarWithProduces/CarWithProducesRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/CarWithProduces/CarWithProducesRequestBuilder.verified.cs new file mode 100644 index 0000000000..377741915d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/CarWithProduces/CarWithProducesRequestBuilder.verified.cs @@ -0,0 +1,101 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces +{ + /// + /// Builds and executes requests for operations under \XmlComments\CarWithProduces + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarWithProducesRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProduces?id={id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarWithProducesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProduces?id={id}", rawUrl) + { + } + /// + /// Returns a specific product With Produces attribute + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product With Produces attribute + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Returns a specific product With Produces attribute + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesRequestBuilderGetQueryParameters + { + [QueryParameter("id")] + public int? Id { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/CarWithProducesDefaultResponseType/CarWithProducesDefaultResponseTypeRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/CarWithProducesDefaultResponseType/CarWithProducesDefaultResponseTypeRequestBuilder.verified.cs new file mode 100644 index 0000000000..468b0235ce --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/CarWithProducesDefaultResponseType/CarWithProducesDefaultResponseTypeRequestBuilder.verified.cs @@ -0,0 +1,106 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType +{ + /// + /// Builds and executes requests for operations under \XmlComments\CarWithProducesDefaultResponseType + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesDefaultResponseTypeRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarWithProducesDefaultResponseTypeRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProducesDefaultResponseType?id={id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarWithProducesDefaultResponseTypeRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProducesDefaultResponseType?id={id}", rawUrl) + { + } + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 4XX or 5XX status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "XXX", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesDefaultResponseTypeRequestBuilderGetQueryParameters + { + [QueryParameter("id")] + public int? Id { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesDefaultResponseTypeRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/XmlCommentsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/XmlCommentsRequestBuilder.verified.cs new file mode 100644 index 0000000000..4ea49e8371 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_18236050557cb287/XmlComments/XmlCommentsRequestBuilder.verified.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments +{ + /// + /// Builds and executes requests for operations under \XmlComments + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class XmlCommentsRequestBuilder : BaseRequestBuilder + { + /// The Car property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder Car + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder(PathParameters, RequestAdapter); + } + /// The CarWithProduces property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder CarWithProduces + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder(PathParameters, RequestAdapter); + } + /// The CarWithProducesDefaultResponseType property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder CarWithProducesDefaultResponseType + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public XmlCommentsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public XmlCommentsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_1b39b060fe3b17af/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_1b39b060fe3b17af/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..a85db07154 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_1b39b060fe3b17af/KiotaOpenApiClient.verified.cs @@ -0,0 +1,37 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..fe31ea3785 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/KiotaOpenApiClient.verified.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + if (string.IsNullOrEmpty(RequestAdapter.BaseUrl)) + { + RequestAdapter.BaseUrl = "http://localhost:57556"; + } + PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..e77961fa65 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_290d7bb6a62c35fc/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_2f2aebaf9596b3c5/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_2f2aebaf9596b3c5/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..6a4a90b043 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_2f2aebaf9596b3c5/NSwagOpenApiClient.verified.cs @@ -0,0 +1,1096 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// + /// Creates a resource + /// + /// The resource + /// Created + /// A server side error occurred. + public virtual System.Threading.Tasks.Task OrdersPOSTAsync(string tenantId, Order body) + { + return OrdersPOSTAsync(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Creates a resource + /// + /// The resource + /// Created + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task OrdersPOSTAsync(string tenantId, Order body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/orders" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/orders"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 201) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Delete by Ids + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual System.Threading.Tasks.Task OrdersDELETEAsync(string tenantId, System.Collections.Generic.IEnumerable body) + { + return OrdersDELETEAsync(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Delete by Ids + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task OrdersDELETEAsync(string tenantId, System.Collections.Generic.IEnumerable body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/orders" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/orders"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Failed", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Delete by Id + /// + /// deleting Id + /// Deleted + /// A server side error occurred. + public virtual System.Threading.Tasks.Task DeleteByIdAsync(string tenantId, Order body) + { + return DeleteByIdAsync(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Delete by Id + /// + /// deleting Id + /// Deleted + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task DeleteByIdAsync(string tenantId, Order body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/orders/DeleteById" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/orders/DeleteById"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Failed", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Delete by Id List + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ListAsync(string tenantId, System.Collections.Generic.IEnumerable body) + { + return ListAsync(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Delete by Id List + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ListAsync(string tenantId, System.Collections.Generic.IEnumerable body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/orders/Delete/List" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/orders/Delete/List"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Failed", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Creates a resource + /// + /// The resource + /// Created + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsPOSTAsync(string tenantId, Product body) + { + return ProductsPOSTAsync(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Creates a resource + /// + /// The resource + /// Created + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsPOSTAsync(string tenantId, Product body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/products" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 201) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Delete by Ids + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsDELETEAsync(string tenantId, System.Collections.Generic.IEnumerable body) + { + return ProductsDELETEAsync(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Delete by Ids + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsDELETEAsync(string tenantId, System.Collections.Generic.IEnumerable body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/products" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Failed", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Delete by Id + /// + /// deleting Id + /// Deleted + /// A server side error occurred. + public virtual System.Threading.Tasks.Task DeleteById2Async(string tenantId, Product body) + { + return DeleteById2Async(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Delete by Id + /// + /// deleting Id + /// Deleted + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task DeleteById2Async(string tenantId, Product body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/products/DeleteById" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/products/DeleteById"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Failed", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Delete by Id List + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual System.Threading.Tasks.Task List2Async(string tenantId, System.Collections.Generic.IEnumerable body) + { + return List2Async(tenantId, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Delete by Id List + /// + /// deleting Ids + /// Deleted + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task List2Async(string tenantId, System.Collections.Generic.IEnumerable body, System.Threading.CancellationToken cancellationToken) + { + if (tenantId == null) + throw new System.ArgumentNullException("tenantId"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "{tenantId}/products/Delete/List" + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tenantId, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/products/Delete/List"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Failed", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Order + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("subtotal", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double Subtotal { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_39927dbb50aae831/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_39927dbb50aae831/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..7c5581de11 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_39927dbb50aae831/NSwagOpenApiClient.verified.cs @@ -0,0 +1,350 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = "http://localhost:51071"; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAsync() + { + return ProductsAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3bdc6e31f7698656/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3bdc6e31f7698656/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..1363660a45 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3bdc6e31f7698656/NSwagOpenApiClient.verified.cs @@ -0,0 +1,347 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAsync() + { + return ProductsAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/Products" + urlBuilder_.Append("api/Products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("foo", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.Generic.ICollection> Foo { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/ApiRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/ApiRequestBuilder.verified.cs new file mode 100644 index 0000000000..2de5a7a4af --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/ApiRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api +{ + /// + /// Builds and executes requests for operations under \api + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ApiRequestBuilder : BaseRequestBuilder + { + /// The items property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.ItemsRequestBuilder Items + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.ItemsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Find/FindRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Find/FindRequestBuilder.verified.cs new file mode 100644 index 0000000000..08de162a9c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Find/FindRequestBuilder.verified.cs @@ -0,0 +1,102 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Find +{ + /// + /// Builds and executes requests for operations under \api\items\find + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FindRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FindRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/find?IsCompleted={IsCompleted}&Text={Text}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FindRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/find?IsCompleted={IsCompleted}&Text={Text}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Find.FindRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Find.FindRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class FindRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + /// Gets or sets a value indicating whether to search completed Todo items. + public bool? IsCompleted { get; set; } + /// Gets or sets the text of the filter. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FindRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/GetAfter/GetAfterRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/GetAfter/GetAfterRequestBuilder.verified.cs new file mode 100644 index 0000000000..9b6c9cf1a7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/GetAfter/GetAfterRequestBuilder.verified.cs @@ -0,0 +1,94 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.GetAfter +{ + /// + /// Builds and executes requests for operations under \api\items\getAfter + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class GetAfterRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public GetAfterRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/getAfter?value={value}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public GetAfterRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/getAfter?value={value}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.GetAfter.GetAfterRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.GetAfter.GetAfterRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class GetAfterRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + [QueryParameter("value")] + public DateTimeOffset? Value { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class GetAfterRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/Complete/CompleteRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/Complete/CompleteRequestBuilder.verified.cs new file mode 100644 index 0000000000..57899a582d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/Complete/CompleteRequestBuilder.verified.cs @@ -0,0 +1,98 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Complete +{ + /// + /// Builds and executes requests for operations under \api\items\{id}\complete + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CompleteRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CompleteRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/complete", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CompleteRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/complete", rawUrl) + { + } + /// + /// Marks the todo item with the specified ID as complete. + /// + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToPostRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails.CreateFromDiscriminatorValue }, + { "404", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Marks the todo item with the specified ID as complete. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Complete.CompleteRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Complete.CompleteRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CompleteRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/ItemsItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/ItemsItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..f9a9422849 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/ItemsItemRequestBuilder.verified.cs @@ -0,0 +1,158 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Complete; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Priority; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item +{ + /// + /// Builds and executes requests for operations under \api\items\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsItemRequestBuilder : BaseRequestBuilder + { + /// The complete property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Complete.CompleteRequestBuilder Complete + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Complete.CompleteRequestBuilder(PathParameters, RequestAdapter); + } + /// The priority property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Priority.PriorityRequestBuilder Priority + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Priority.PriorityRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ItemsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ItemsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}", rawUrl) + { + } + /// + /// Deletes the todo item with the specified ID. + /// + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "404", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Gets the todo item with the specified ID. + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "404", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoItemModel.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Deletes the todo item with the specified ID. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + return requestInfo; + } + /// + /// Gets the todo item with the specified ID. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.ItemsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.ItemsItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsItemRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/Priority/PriorityRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/Priority/PriorityRequestBuilder.verified.cs new file mode 100644 index 0000000000..86cfb7244a --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/Item/Priority/PriorityRequestBuilder.verified.cs @@ -0,0 +1,103 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Priority +{ + /// + /// Builds and executes requests for operations under \api\items\{id}\priority + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class PriorityRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public PriorityRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/priority", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public PriorityRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items/{id}/priority", rawUrl) + { + } + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// Represents the model for updating the priority of a Todo item. + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code + /// When receiving a 404 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PatchAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.UpdateTodoItemPriorityModel body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PatchAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.UpdateTodoItemPriorityModel body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPatchRequestInformation(body, requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails.CreateFromDiscriminatorValue }, + { "404", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// A + /// Represents the model for updating the priority of a Todo item. + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPatchRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.UpdateTodoItemPriorityModel body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPatchRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.UpdateTodoItemPriorityModel body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PATCH, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/problem+json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Priority.PriorityRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.Priority.PriorityRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class PriorityRequestBuilderPatchRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/ItemsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/ItemsRequestBuilder.verified.cs new file mode 100644 index 0000000000..32015ee7db --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Api/Items/ItemsRequestBuilder.verified.cs @@ -0,0 +1,185 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Find; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.GetAfter; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items +{ + /// + /// Builds and executes requests for operations under \api\items + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsRequestBuilder : BaseRequestBuilder + { + /// The find property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Find.FindRequestBuilder Find + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Find.FindRequestBuilder(PathParameters, RequestAdapter); + } + /// The getAfter property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.GetAfter.GetAfterRequestBuilder GetAfter + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.GetAfter.GetAfterRequestBuilder(PathParameters, RequestAdapter); + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.api.items.item collection + /// The Todo item's ID. + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.ItemsItemRequestBuilder this[Guid position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.ItemsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.api.items.item collection + /// The Todo item's ID. + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.ItemsItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.Item.ItemsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ItemsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ItemsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/items", rawUrl) + { + } + /// + /// Gets all of the current user's todo items. + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoListViewModel.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// A + /// Represents the model for creating a new Todo item. + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 400 status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreateTodoItemModel body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreateTodoItemModel body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + var errorMapping = new Dictionary> + { + { "400", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreatedTodoItemModel.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Gets all of the current user's todo items. + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// A + /// Represents the model for creating a new Todo item. + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreateTodoItemModel body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreateTodoItemModel body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.ItemsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Items.ItemsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ItemsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..f1c91cb638 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The api property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder Api + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/CreateTodoItemModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/CreateTodoItemModel.verified.cs new file mode 100644 index 0000000000..c06131f459 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/CreateTodoItemModel.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents the model for creating a new Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CreateTodoItemModel : IParsable + { + /// Gets or sets the text of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreateTodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreateTodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "text", n => { Text = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("text", Text); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/CreatedTodoItemModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/CreatedTodoItemModel.verified.cs new file mode 100644 index 0000000000..f3bd86efe7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/CreatedTodoItemModel.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents the model for a created Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CreatedTodoItemModel : IParsable + { + /// Gets or sets the ID of the created Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Id { get; set; } +#nullable restore +#else + public string Id { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreatedTodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreatedTodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "id", n => { Id = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/ProblemDetails.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/ProblemDetails.verified.cs new file mode 100644 index 0000000000..b2ca46048c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/ProblemDetails.verified.cs @@ -0,0 +1,102 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProblemDetails : ApiException, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The detail property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Detail { get; set; } +#nullable restore +#else + public string Detail { get; set; } +#endif + /// The instance property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Instance { get; set; } +#nullable restore +#else + public string Instance { get; set; } +#endif + /// The primary error message. + public override string Message { get => base.Message; } + /// The status property + public int? Status { get; set; } + /// The title property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Title { get; set; } +#nullable restore +#else + public string Title { get; set; } +#endif + /// The type property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Type { get; set; } +#nullable restore +#else + public string Type { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public ProblemDetails() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.ProblemDetails(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "detail", n => { Detail = n.GetStringValue(); } }, + { "instance", n => { Instance = n.GetStringValue(); } }, + { "status", n => { Status = n.GetIntValue(); } }, + { "title", n => { Title = n.GetStringValue(); } }, + { "type", n => { Type = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("detail", Detail); + writer.WriteStringValue("instance", Instance); + writer.WriteIntValue("status", Status); + writer.WriteStringValue("title", Title); + writer.WriteStringValue("type", Type); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoItemModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoItemModel.verified.cs new file mode 100644 index 0000000000..9ecbe5a36e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoItemModel.verified.cs @@ -0,0 +1,82 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents a Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoItemModel : IParsable + { + /// Gets or sets the date and time the item was completed. + public DateTimeOffset? CompletedAt { get; set; } + /// Gets or sets the date and time the item was created. + public DateTimeOffset? CreatedAt { get; set; } + /// Gets or sets the ID of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Id { get; set; } +#nullable restore +#else + public string Id { get; set; } +#endif + /// Gets or sets the date and time the Todo item was last updated. + public DateTimeOffset? LastUpdated { get; set; } + /// Gets or sets the optional priority of the Todo item. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoPriority? Priority { get; set; } + /// Gets or sets the text of the Todo item. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoItemModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoItemModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "completedAt", n => { CompletedAt = n.GetDateTimeOffsetValue(); } }, + { "createdAt", n => { CreatedAt = n.GetDateTimeOffsetValue(); } }, + { "id", n => { Id = n.GetStringValue(); } }, + { "lastUpdated", n => { LastUpdated = n.GetDateTimeOffsetValue(); } }, + { "priority", n => { Priority = n.GetEnumValue(); } }, + { "text", n => { Text = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDateTimeOffsetValue("completedAt", CompletedAt); + writer.WriteDateTimeOffsetValue("createdAt", CreatedAt); + writer.WriteStringValue("id", Id); + writer.WriteDateTimeOffsetValue("lastUpdated", LastUpdated); + writer.WriteEnumValue("priority", Priority); + writer.WriteStringValue("text", Text); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoListViewModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoListViewModel.verified.cs new file mode 100644 index 0000000000..36f26f3a29 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoListViewModel.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents a collection of Todo items. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodoListViewModel : IParsable + { + /// Gets or sets the Todo item(s). +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public List? Items { get; set; } +#nullable restore +#else + public List Items { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoListViewModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoListViewModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "items", n => { Items = n.GetCollectionOfObjectValues(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoItemModel.CreateFromDiscriminatorValue)?.AsList(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteCollectionOfObjectValues("items", Items); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoPriority.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoPriority.verified.cs new file mode 100644 index 0000000000..edd12d14fe --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/TodoPriority.verified.cs @@ -0,0 +1,23 @@ +// +using System.Runtime.Serialization; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// The priority levels for a Todo item. + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public enum TodoPriority + { + [EnumMember(Value = "Normal")] + #pragma warning disable CS1591 + Normal, + #pragma warning restore CS1591 + [EnumMember(Value = "Low")] + #pragma warning disable CS1591 + Low, + #pragma warning restore CS1591 + [EnumMember(Value = "High")] + #pragma warning disable CS1591 + High, + #pragma warning restore CS1591 + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/UpdateTodoItemPriorityModel.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/UpdateTodoItemPriorityModel.verified.cs new file mode 100644 index 0000000000..c89cca25c2 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_3cdd085efa40fddd/Models/UpdateTodoItemPriorityModel.verified.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents the model for updating the priority of a Todo item. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class UpdateTodoItemPriorityModel : IParsable + { + /// Gets or sets the new priority of the Todo item. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TodoPriority? Priority { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.UpdateTodoItemPriorityModel CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.UpdateTodoItemPriorityModel(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "priority", n => { Priority = n.GetEnumValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteEnumValue("priority", Priority); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..32c694c3e9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/Item/ProductsItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/Item/ProductsItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..2cbb808790 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/Item/ProductsItemRequestBuilder.verified.cs @@ -0,0 +1,213 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item +{ + /// + /// Builds and executes requests for operations under \products\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/{id}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PatchAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PatchAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPatchRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PutAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PutAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPutRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/octet-stream"); + return requestInfo; + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPatchRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPatchRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PATCH, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/octet-stream"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPutRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPutRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PUT, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/octet-stream"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderPatchRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderPutRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/Item/ProductsPatchRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/Item/ProductsPatchRequestBody.verified.cs new file mode 100644 index 0000000000..aa13c65c65 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/Item/ProductsPatchRequestBody.verified.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProductsPatchRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// + /// Instantiates a new and sets the default values. + /// + public ProductsPatchRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..b68de75cb8 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_484a86c0761779e7/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,157 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.products.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.products.item collection + /// Unique identifier of the item + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Api/ApiRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Api/ApiRequestBuilder.verified.cs new file mode 100644 index 0000000000..a14dd539ca --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Api/ApiRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api +{ + /// + /// Builds and executes requests for operations under \api + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ApiRequestBuilder : BaseRequestBuilder + { + /// The Products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Api/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Api/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..5210c94755 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Api/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Products +{ + /// + /// Builds and executes requests for operations under \api\Products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/Products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/Products", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..f1c91cb638 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The api property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder Api + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Models/Product.verified.cs new file mode 100644 index 0000000000..172a72b305 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_4dd7802f98d99c89/Models/Product.verified.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The foo property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public UntypedNode? Foo { get; set; } +#nullable restore +#else + public UntypedNode Foo { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "foo", n => { Foo = n.GetObjectValue(UntypedNode.CreateFromDiscriminatorValue); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteObjectValue("foo", Foo); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..32c694c3e9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..e77961fa65 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_565c8d3b8ad0210d/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/Delete/DeleteRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/Delete/DeleteRequestBuilder.verified.cs new file mode 100644 index 0000000000..c89eca1a89 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/Delete/DeleteRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.List; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete +{ + /// + /// Builds and executes requests for operations under \{tenantId}\orders\Delete + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DeleteRequestBuilder : BaseRequestBuilder + { + /// The List property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.List.ListRequestBuilder List + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.List.ListRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public DeleteRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders/Delete", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public DeleteRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders/Delete", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/Delete/List/ListRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/Delete/List/ListRequestBuilder.verified.cs new file mode 100644 index 0000000000..3b404f70c9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/Delete/List/ListRequestBuilder.verified.cs @@ -0,0 +1,97 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.List +{ + /// + /// Builds and executes requests for operations under \{tenantId}\orders\Delete\List + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ListRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ListRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders/Delete/List", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ListRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders/Delete/List", rawUrl) + { + } + /// + /// Delete by Id List + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(List body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(List body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToDeleteRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Delete by Id List + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(List body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(List body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.List.ListRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.List.ListRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ListRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/DeleteById/DeleteByIdRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/DeleteById/DeleteByIdRequestBuilder.verified.cs new file mode 100644 index 0000000000..c1f48f28e7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/DeleteById/DeleteByIdRequestBuilder.verified.cs @@ -0,0 +1,97 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.DeleteById +{ + /// + /// Builds and executes requests for operations under \{tenantId}\orders\DeleteById + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DeleteByIdRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public DeleteByIdRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders/DeleteById", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public DeleteByIdRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders/DeleteById", rawUrl) + { + } + /// + /// Delete by Id + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToDeleteRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Delete by Id + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.DeleteById.DeleteByIdRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.DeleteById.DeleteByIdRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DeleteByIdRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/OrdersRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/OrdersRequestBuilder.verified.cs new file mode 100644 index 0000000000..95389db696 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Orders/OrdersRequestBuilder.verified.cs @@ -0,0 +1,159 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.DeleteById; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders +{ + /// + /// Builds and executes requests for operations under \{tenantId}\orders + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class OrdersRequestBuilder : BaseRequestBuilder + { + /// The DeleteById property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.DeleteById.DeleteByIdRequestBuilder DeleteById + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.DeleteById.DeleteByIdRequestBuilder(PathParameters, RequestAdapter); + } + /// The DeletePath property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.DeleteRequestBuilder DeletePath + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.Delete.DeleteRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public OrdersRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public OrdersRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/orders", rawUrl) + { + } + /// + /// Delete by Ids + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(List body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(List body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToDeleteRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Creates a resource + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Delete by Ids + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(List body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(List body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Creates a resource + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.OrdersRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.OrdersRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class OrdersRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class OrdersRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/Delete/DeleteRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/Delete/DeleteRequestBuilder.verified.cs new file mode 100644 index 0000000000..7f6b5112c4 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/Delete/DeleteRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.List; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete +{ + /// + /// Builds and executes requests for operations under \{tenantId}\products\Delete + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DeleteRequestBuilder : BaseRequestBuilder + { + /// The List property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.List.ListRequestBuilder List + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.List.ListRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public DeleteRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products/Delete", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public DeleteRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products/Delete", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/Delete/List/ListRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/Delete/List/ListRequestBuilder.verified.cs new file mode 100644 index 0000000000..b4b80f7286 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/Delete/List/ListRequestBuilder.verified.cs @@ -0,0 +1,97 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.List +{ + /// + /// Builds and executes requests for operations under \{tenantId}\products\Delete\List + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ListRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ListRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products/Delete/List", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ListRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products/Delete/List", rawUrl) + { + } + /// + /// Delete by Id List + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(List body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(List body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToDeleteRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Delete by Id List + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(List body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(List body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.List.ListRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.List.ListRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ListRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/DeleteById/DeleteByIdRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/DeleteById/DeleteByIdRequestBuilder.verified.cs new file mode 100644 index 0000000000..956efdade1 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/DeleteById/DeleteByIdRequestBuilder.verified.cs @@ -0,0 +1,97 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.DeleteById +{ + /// + /// Builds and executes requests for operations under \{tenantId}\products\DeleteById + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DeleteByIdRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public DeleteByIdRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products/DeleteById", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public DeleteByIdRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products/DeleteById", rawUrl) + { + } + /// + /// Delete by Id + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToDeleteRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Delete by Id + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.DeleteById.DeleteByIdRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.DeleteById.DeleteByIdRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DeleteByIdRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..fe7f74c702 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,159 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.DeleteById; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products +{ + /// + /// Builds and executes requests for operations under \{tenantId}\products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// The DeleteById property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.DeleteById.DeleteByIdRequestBuilder DeleteById + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.DeleteById.DeleteByIdRequestBuilder(PathParameters, RequestAdapter); + } + /// The DeletePath property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.DeleteRequestBuilder DeletePath + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.Delete.DeleteRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}/products", rawUrl) + { + } + /// + /// Delete by Ids + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(List body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(List body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToDeleteRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Creates a resource + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Delete by Ids + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(List body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(List body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Creates a resource + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/WithTenantItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/WithTenantItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..c66623e61f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Item/WithTenantItemRequestBuilder.verified.cs @@ -0,0 +1,47 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item +{ + /// + /// Builds and executes requests for operations under \{tenantId} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithTenantItemRequestBuilder : BaseRequestBuilder + { + /// The orders property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.OrdersRequestBuilder Orders + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Orders.OrdersRequestBuilder(PathParameters, RequestAdapter); + } + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WithTenantItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WithTenantItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/{tenantId}", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..aea852567b --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/KiotaOpenApiClient.verified.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.WithTenantItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("tenantId", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Item.WithTenantItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Models/Order.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Models/Order.verified.cs new file mode 100644 index 0000000000..b159b1421c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Models/Order.verified.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Order : IParsable + #pragma warning restore CS1591 + { + /// The id property + public int? Id { get; set; } + /// The subtotal property + public double? Subtotal { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Order(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "id", n => { Id = n.GetIntValue(); } }, + { "subtotal", n => { Subtotal = n.GetDoubleValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteIntValue("id", Id); + writer.WriteDoubleValue("subtotal", Subtotal); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_5c64fb6b50e962ed/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..52c5f219ab --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/KiotaOpenApiClient.verified.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + if (string.IsNullOrEmpty(RequestAdapter.BaseUrl)) + { + RequestAdapter.BaseUrl = "http://localhost:51071"; + } + PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..e77961fa65 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6010233cf877b681/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..8aac6f0d16 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WeatherForecast; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The WeatherForecast property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WeatherForecast.WeatherForecastRequestBuilder WeatherForecast + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WeatherForecast.WeatherForecastRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/Models/WeatherForecast.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/Models/WeatherForecast.verified.cs new file mode 100644 index 0000000000..48fc15286c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/Models/WeatherForecast.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class WeatherForecast : IParsable + #pragma warning restore CS1591 + { + /// The date property + public DateTimeOffset? Date { get; set; } + /// The summary property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Summary { get; set; } +#nullable restore +#else + public string Summary { get; set; } +#endif + /// The temperatureC property + public int? TemperatureC { get; set; } + /// The temperatureF property + public int? TemperatureF { get; private set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "date", n => { Date = n.GetDateTimeOffsetValue(); } }, + { "summary", n => { Summary = n.GetStringValue(); } }, + { "temperatureC", n => { TemperatureC = n.GetIntValue(); } }, + { "temperatureF", n => { TemperatureF = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDateTimeOffsetValue("date", Date); + writer.WriteStringValue("summary", Summary); + writer.WriteIntValue("temperatureC", TemperatureC); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/WeatherForecast/WeatherForecastRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/WeatherForecast/WeatherForecastRequestBuilder.verified.cs new file mode 100644 index 0000000000..433c7dfddd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6f5bddaf4a3479f0/WeatherForecast/WeatherForecastRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WeatherForecast +{ + /// + /// Builds and executes requests for operations under \WeatherForecast + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherForecastRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WeatherForecastRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WeatherForecast", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WeatherForecastRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WeatherForecast", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WeatherForecast.WeatherForecastRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WeatherForecast.WeatherForecastRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherForecastRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..4c2aae0b7f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The todos property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.TodosRequestBuilder Todos + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.TodosRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Models/Todo.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Models/Todo.verified.cs new file mode 100644 index 0000000000..58ca8f6360 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Models/Todo.verified.cs @@ -0,0 +1,68 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Todo : IParsable + #pragma warning restore CS1591 + { + /// The dueBy property + public Date? DueBy { get; set; } + /// The id property + public int? Id { get; set; } + /// The isComplete property + public bool? IsComplete { get; set; } + /// The title property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Title { get; set; } +#nullable restore +#else + public string Title { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Todo CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Todo(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "dueBy", n => { DueBy = n.GetDateValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + { "isComplete", n => { IsComplete = n.GetBoolValue(); } }, + { "title", n => { Title = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDateValue("dueBy", DueBy); + writer.WriteIntValue("id", Id); + writer.WriteBoolValue("isComplete", IsComplete); + writer.WriteStringValue("title", Title); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Todos/Item/TodosItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Todos/Item/TodosItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..06b25cedc9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Todos/Item/TodosItemRequestBuilder.verified.cs @@ -0,0 +1,84 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item +{ + /// + /// Builds and executes requests for operations under \todos\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodosItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public TodosItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/todos/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public TodosItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/todos/{id}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item.TodosItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item.TodosItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodosItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Todos/TodosRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Todos/TodosRequestBuilder.verified.cs new file mode 100644 index 0000000000..f68a92feb8 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_6fe5d13a9d93e91a/Todos/TodosRequestBuilder.verified.cs @@ -0,0 +1,113 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos +{ + /// + /// Builds and executes requests for operations under \todos + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodosRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.todos.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item.TodosItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item.TodosItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.todos.item collection + /// Unique identifier of the item + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item.TodosItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.Item.TodosItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public TodosRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/todos", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public TodosRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/todos", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Todo> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Todo.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.TodosRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Todos.TodosRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TodosRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..e035d3baf7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/KiotaOpenApiClient.verified.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + if (string.IsNullOrEmpty(RequestAdapter.BaseUrl)) + { + RequestAdapter.BaseUrl = "/resource-server"; + } + PathParameters.TryAdd("baseurl", RequestAdapter.BaseUrl); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Models/Product.verified.cs new file mode 100644 index 0000000000..c2d9b9ae70 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Models/Product.verified.cs @@ -0,0 +1,62 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The id property + public int? Id { get; private set; } + /// The serialNo property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? SerialNo { get; set; } +#nullable restore +#else + public string SerialNo { get; set; } +#endif + /// The status property + public int? Status { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "id", n => { Id = n.GetIntValue(); } }, + { "serialNo", n => { SerialNo = n.GetStringValue(); } }, + { "status", n => { Status = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("serialNo", SerialNo); + writer.WriteIntValue("status", Status); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Products/Item/ProductsItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Products/Item/ProductsItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..0606ff62b0 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Products/Item/ProductsItemRequestBuilder.verified.cs @@ -0,0 +1,124 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item +{ + /// + /// Builds and executes requests for operations under \products\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/{id}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json, text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..d6264fa087 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_768e677c94277084/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,156 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.products.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.products.item collection + /// Unique identifier of the item + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78402e8ccf6874be/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78402e8ccf6874be/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..25719b19df --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78402e8ccf6874be/NSwagOpenApiClient.verified.cs @@ -0,0 +1,356 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> WeatherForecastAsync() + { + return WeatherForecastAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> WeatherForecastAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WeatherForecast" + urlBuilder_.Append("WeatherForecast"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class WeatherForecast + { + + [Newtonsoft.Json.JsonProperty("date", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset Date { get; set; } + + [Newtonsoft.Json.JsonProperty("temperatureC", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int TemperatureC { get; set; } + + [Newtonsoft.Json.JsonProperty("temperatureF", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int TemperatureF { get; set; } + + [Newtonsoft.Json.JsonProperty("summary", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Summary { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/ApiRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/ApiRequestBuilder.verified.cs new file mode 100644 index 0000000000..b9cfc5cc8e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/ApiRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api +{ + /// + /// Builds and executes requests for operations under \api + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ApiRequestBuilder : BaseRequestBuilder + { + /// The users property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersRequestBuilder Users + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/Users/UsersPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/Users/UsersPostRequestBody.verified.cs new file mode 100644 index 0000000000..a730fce457 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/Users/UsersPostRequestBody.verified.cs @@ -0,0 +1,75 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class UsersPostRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The email property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Email { get; set; } +#nullable restore +#else + public string Email { get; set; } +#endif + /// The password property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Password { get; set; } +#nullable restore +#else + public string Password { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public UsersPostRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "email", n => { Email = n.GetStringValue(); } }, + { "password", n => { Password = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("email", Email); + writer.WriteStringValue("password", Password); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/Users/UsersRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/Users/UsersRequestBuilder.verified.cs new file mode 100644 index 0000000000..7787eb6786 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/Api/Users/UsersRequestBuilder.verified.cs @@ -0,0 +1,88 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users +{ + /// + /// Builds and executes requests for operations under \api\users + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class UsersRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public UsersRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/users", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public UsersRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/users", rawUrl) + { + } + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + await RequestAdapter.SendNoContentAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.Users.UsersRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class UsersRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..f1c91cb638 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_78fcf947cfcdf156/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The api property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder Api + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_887704eaa79e8ac0/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_887704eaa79e8ac0/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..a4ff686c47 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_887704eaa79e8ac0/NSwagOpenApiClient.verified.cs @@ -0,0 +1,49 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + + + + + + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..c672df5e27 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The Products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..7e8b4a875f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9267f2f0046c723d/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,102 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \Products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Products?api-version={api%2Dversion}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Products?api-version={api%2Dversion}", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProductsRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("api%2Dversion")] + public string? ApiVersion { get; set; } +#nullable restore +#else + [QueryParameter("api%2Dversion")] + public string ApiVersion { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9b761e4794fc013c/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9b761e4794fc013c/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..1ad2c9ba51 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9b761e4794fc013c/NSwagOpenApiClient.verified.cs @@ -0,0 +1,832 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task AnimalsAsync(Animal body) + { + return AnimalsAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task AnimalsAsync(Animal body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "Animals" + urlBuilder_.Append("Animals"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task SecondLevelAsync(SubSubType body) + { + return SecondLevelAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task SecondLevelAsync(SubSubType body, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "SecondLevel" + urlBuilder_.Append("SecondLevel"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task SystemTextJsonAnimalsAsync(SystemTextJsonAnimal body) + { + return SystemTextJsonAnimalsAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task SystemTextJsonAnimalsAsync(SystemTextJsonAnimal body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "SystemTextJsonAnimals" + urlBuilder_.Append("SystemTextJsonAnimals"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task SystemTextJsonDefaultDiscriminatorAnimalsAsync(SystemTextJsonDefaultDiscriminatorAnimal body) + { + return SystemTextJsonDefaultDiscriminatorAnimalsAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task SystemTextJsonDefaultDiscriminatorAnimalsAsync(SystemTextJsonDefaultDiscriminatorAnimal body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "SystemTextJsonDefaultDiscriminatorAnimals" + urlBuilder_.Append("SystemTextJsonDefaultDiscriminatorAnimals"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [Newtonsoft.Json.JsonConverter(typeof(JsonInheritanceConverter), "animalType")] + [JsonInheritanceAttribute("Cat", typeof(Cat))] + [JsonInheritanceAttribute("Dog", typeof(Dog))] + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Animal + { + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum AnimalType + { + + [System.Runtime.Serialization.EnumMember(Value = @"Cat")] + Cat = 0, + + [System.Runtime.Serialization.EnumMember(Value = @"Dog")] + Dog = 1, + + } + + [Newtonsoft.Json.JsonConverter(typeof(JsonInheritanceConverter), "discriminator")] + [JsonInheritanceAttribute("SubSubType", typeof(SubSubType))] + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class BaseType + { + + [Newtonsoft.Json.JsonProperty("property", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Property { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Cat : Animal + { + + [Newtonsoft.Json.JsonProperty("catSpecificProperty", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string CatSpecificProperty { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Dog : Animal + { + + [Newtonsoft.Json.JsonProperty("dogSpecificProperty", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string DogSpecificProperty { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SubSubType : BaseType + { + + [Newtonsoft.Json.JsonProperty("property2", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Property2 { get; set; } + + } + + [Newtonsoft.Json.JsonConverter(typeof(JsonInheritanceConverter), "animalType")] + [JsonInheritanceAttribute("Cat", typeof(SystemTextJsonCat))] + [JsonInheritanceAttribute("Dog", typeof(SystemTextJsonDog))] + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SystemTextJsonAnimal + { + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SystemTextJsonCat : SystemTextJsonAnimal + { + + [Newtonsoft.Json.JsonProperty("catSpecificProperty", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string CatSpecificProperty { get; set; } + + } + + [Newtonsoft.Json.JsonConverter(typeof(JsonInheritanceConverter), "$type")] + [JsonInheritanceAttribute("Cat", typeof(SystemTextJsonDefaultDiscriminatorCat))] + [JsonInheritanceAttribute("Dog", typeof(SystemTextJsonDefaultDiscriminatorDog))] + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SystemTextJsonDefaultDiscriminatorAnimal + { + + [Newtonsoft.Json.JsonProperty("animalType", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string AnimalType { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SystemTextJsonDefaultDiscriminatorCat : SystemTextJsonDefaultDiscriminatorAnimal + { + + [Newtonsoft.Json.JsonProperty("catSpecificProperty", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string CatSpecificProperty { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SystemTextJsonDefaultDiscriminatorDog : SystemTextJsonDefaultDiscriminatorAnimal + { + + [Newtonsoft.Json.JsonProperty("dogSpecificProperty", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string DogSpecificProperty { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class SystemTextJsonDog : SystemTextJsonAnimal + { + + [Newtonsoft.Json.JsonProperty("dogSpecificProperty", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string DogSpecificProperty { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + [System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple = true)] + internal class JsonInheritanceAttribute : System.Attribute + { + public JsonInheritanceAttribute(string key, System.Type type) + { + Key = key; + Type = type; + } + + public string Key { get; } + + public System.Type Type { get; } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public class JsonInheritanceConverter : Newtonsoft.Json.JsonConverter + { + internal static readonly string DefaultDiscriminatorName = "discriminator"; + + private readonly string _discriminatorName; + + [System.ThreadStatic] + private static bool _isReading; + + [System.ThreadStatic] + private static bool _isWriting; + + public JsonInheritanceConverter() + { + _discriminatorName = DefaultDiscriminatorName; + } + + public JsonInheritanceConverter(string discriminatorName) + { + _discriminatorName = discriminatorName; + } + + public string DiscriminatorName { get { return _discriminatorName; } } + + public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) + { + try + { + _isWriting = true; + + var jObject = Newtonsoft.Json.Linq.JObject.FromObject(value, serializer); + jObject.AddFirst(new Newtonsoft.Json.Linq.JProperty(_discriminatorName, GetSubtypeDiscriminator(value.GetType()))); + writer.WriteToken(jObject.CreateReader()); + } + finally + { + _isWriting = false; + } + } + + public override bool CanWrite + { + get + { + if (_isWriting) + { + _isWriting = false; + return false; + } + return true; + } + } + + public override bool CanRead + { + get + { + if (_isReading) + { + _isReading = false; + return false; + } + return true; + } + } + + public override bool CanConvert(System.Type objectType) + { + return true; + } + + public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) + { + var jObject = serializer.Deserialize(reader); + if (jObject == null) + return null; + + var discriminatorValue = jObject.GetValue(_discriminatorName); + var discriminator = discriminatorValue != null ? Newtonsoft.Json.Linq.Extensions.Value(discriminatorValue) : null; + var subtype = GetObjectSubtype(objectType, discriminator); + + var objectContract = serializer.ContractResolver.ResolveContract(subtype) as Newtonsoft.Json.Serialization.JsonObjectContract; + if (objectContract == null || System.Linq.Enumerable.All(objectContract.Properties, p => p.PropertyName != _discriminatorName)) + { + jObject.Remove(_discriminatorName); + } + + try + { + _isReading = true; + return serializer.Deserialize(jObject.CreateReader(), subtype); + } + finally + { + _isReading = false; + } + } + + private System.Type GetObjectSubtype(System.Type objectType, string discriminator) + { + foreach (var attribute in System.Reflection.CustomAttributeExtensions.GetCustomAttributes(System.Reflection.IntrospectionExtensions.GetTypeInfo(objectType), true)) + { + if (attribute.Key == discriminator) + return attribute.Type; + } + + return objectType; + } + + private string GetSubtypeDiscriminator(System.Type objectType) + { + foreach (var attribute in System.Reflection.CustomAttributeExtensions.GetCustomAttributes(System.Reflection.IntrospectionExtensions.GetTypeInfo(objectType), true)) + { + if (attribute.Type == objectType) + return attribute.Key; + } + + return objectType.Name; + } + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9ff8910c4c525cf0/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9ff8910c4c525cf0/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..49b8b9ccc3 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_9ff8910c4c525cf0/NSwagOpenApiClient.verified.cs @@ -0,0 +1,356 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAsync(string api_version) + { + return ProductsAsync(api_version, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAsync(string api_version, System.Threading.CancellationToken cancellationToken) + { + if (api_version == null) + throw new System.ArgumentNullException("api_version"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "Products" + urlBuilder_.Append("Products"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("api-version")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(api_version, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a183add29706ff70/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a183add29706ff70/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..25296f73c5 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a183add29706ff70/NSwagOpenApiClient.verified.cs @@ -0,0 +1,350 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAsync() + { + return ProductsAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a1ab8f6c5e8ef470/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a1ab8f6c5e8ef470/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..5cecb9b037 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a1ab8f6c5e8ef470/NSwagOpenApiClient.verified.cs @@ -0,0 +1,618 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsPOSTAsync(string api_version, Product body) + { + return ProductsPOSTAsync(api_version, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsPOSTAsync(string api_version, Product body, System.Threading.CancellationToken cancellationToken) + { + if (api_version == null) + throw new System.ArgumentNullException("api_version"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "Products" + urlBuilder_.Append("Products"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("api-version")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(api_version, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAllAsync(string api_version) + { + return ProductsAllAsync(api_version, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAllAsync(string api_version, System.Threading.CancellationToken cancellationToken) + { + if (api_version == null) + throw new System.ArgumentNullException("api_version"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "Products" + urlBuilder_.Append("Products"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("api-version")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(api_version, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsPUTAsync(int id, string api_version, Product body) + { + return ProductsPUTAsync(id, api_version, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsPUTAsync(int id, string api_version, Product body, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + if (api_version == null) + throw new System.ArgumentNullException("api_version"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("PUT"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "Products/{id}" + urlBuilder_.Append("Products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("api-version")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(api_version, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsDELETEAsync(int id, string api_version) + { + return ProductsDELETEAsync(id, api_version, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsDELETEAsync(int id, string api_version, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + if (api_version == null) + throw new System.ArgumentNullException("api_version"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "Products/{id}" + urlBuilder_.Append("Products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("api-version")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(api_version, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a4dcbaf37de46e5e/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a4dcbaf37de46e5e/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..25a5554d9c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_a4dcbaf37de46e5e/NSwagOpenApiClient.verified.cs @@ -0,0 +1,1224 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// + /// Get all Todo items + /// + /// + /// Gets all of the current user's todo items. + /// + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ListTodosAsync() + { + return ListTodosAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Get all Todo items + /// + /// + /// Gets all of the current user's todo items. + /// + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ListTodosAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items" + urlBuilder_.Append("api/items"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Create a new Todo item + /// + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// Created + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CreateTodoAsync(CreateTodoItemModel body) + { + return CreateTodoAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Create a new Todo item + /// + /// + /// Creates a new todo item for the current user and returns its ID. + /// + /// Created + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CreateTodoAsync(CreateTodoItemModel body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items" + urlBuilder_.Append("api/items"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 201) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 400) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("Bad Request", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Get a specific Todo item + /// + /// + /// Gets the todo item with the specified ID. + /// + /// The Todo item's ID. + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task GetTodoAsync(System.Guid id) + { + return GetTodoAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Get a specific Todo item + /// + /// + /// Gets the todo item with the specified ID. + /// + /// The Todo item's ID. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task GetTodoAsync(System.Guid id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items/{id}" + urlBuilder_.Append("api/items/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 404) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("Not Found", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Delete a Todo item + /// + /// + /// Deletes the todo item with the specified ID. + /// + /// The Todo item's ID. + /// No Content + /// A server side error occurred. + public virtual System.Threading.Tasks.Task DeleteTodoAsync(System.Guid id) + { + return DeleteTodoAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Delete a Todo item + /// + /// + /// Deletes the todo item with the specified ID. + /// + /// The Todo item's ID. + /// No Content + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task DeleteTodoAsync(System.Guid id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items/{id}" + urlBuilder_.Append("api/items/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 204) + { + return; + } + else + if (status_ == 404) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("Not Found", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Mark a Todo item as completed + /// + /// + /// Marks the todo item with the specified ID as complete. + /// + /// The Todo item's ID. + /// No Content + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CompleteTodoAsync(System.Guid id) + { + return CompleteTodoAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Mark a Todo item as completed + /// + /// + /// Marks the todo item with the specified ID as complete. + /// + /// The Todo item's ID. + /// No Content + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CompleteTodoAsync(System.Guid id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items/{id}/complete" + urlBuilder_.Append("api/items/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/complete"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 204) + { + return; + } + else + if (status_ == 400) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("Bad Request", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 404) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("Not Found", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Updates the priority of a Todo item + /// + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// The Todo item's ID. + /// No Content + /// A server side error occurred. + public virtual System.Threading.Tasks.Task UpdateTodoPriorityAsync(System.Guid id, UpdateTodoItemPriorityModel body) + { + return UpdateTodoPriorityAsync(id, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Updates the priority of a Todo item + /// + /// + /// Updates the priority of the todo item with the specified ID to the specified priority. + /// + /// The Todo item's ID. + /// No Content + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task UpdateTodoPriorityAsync(System.Guid id, UpdateTodoItemPriorityModel body, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("PATCH"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items/{id}/priority" + urlBuilder_.Append("api/items/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Append("/priority"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 204) + { + return; + } + else + if (status_ == 400) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("Bad Request", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + if (status_ == 404) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("Not Found", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Gets or sets the text of the filter. + /// Gets or sets a value indicating whether to search completed Todo items. + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task FindTodoAsync(string text, bool isCompleted) + { + return FindTodoAsync(text, isCompleted, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Gets or sets the text of the filter. + /// Gets or sets a value indicating whether to search completed Todo items. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task FindTodoAsync(string text, bool isCompleted, System.Threading.CancellationToken cancellationToken) + { + if (text == null) + throw new System.ArgumentNullException("text"); + + if (isCompleted == null) + throw new System.ArgumentNullException("isCompleted"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items/find" + urlBuilder_.Append("api/items/find"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("Text")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(text, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Append(System.Uri.EscapeDataString("IsCompleted")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(isCompleted, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task GetAfterDateAsync(System.DateTimeOffset value) + { + return GetAfterDateAsync(value, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task GetAfterDateAsync(System.DateTimeOffset value, System.Threading.CancellationToken cancellationToken) + { + if (value == null) + throw new System.ArgumentNullException("value"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/items/getAfter" + urlBuilder_.Append("api/items/getAfter"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("value")).Append('=').Append(System.Uri.EscapeDataString(value.ToString("s", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + /// + /// Represents the model for creating a new Todo item. + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class CreateTodoItemModel + { + + /// + /// Gets or sets the text of the Todo item. + /// + [Newtonsoft.Json.JsonProperty("text", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Text { get; set; } + + } + + /// + /// Represents the model for a created Todo item. + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class CreatedTodoItemModel + { + + /// + /// Gets or sets the ID of the created Todo item. + /// + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Id { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ProblemDetails + { + + [Newtonsoft.Json.JsonProperty("type", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Type { get; set; } + + [Newtonsoft.Json.JsonProperty("title", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Title { get; set; } + + [Newtonsoft.Json.JsonProperty("status", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int? Status { get; set; } + + [Newtonsoft.Json.JsonProperty("detail", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Detail { get; set; } + + [Newtonsoft.Json.JsonProperty("instance", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Instance { get; set; } + + private System.Collections.Generic.IDictionary _additionalProperties; + + [Newtonsoft.Json.JsonExtensionData] + public System.Collections.Generic.IDictionary AdditionalProperties + { + get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary()); } + set { _additionalProperties = value; } + } + + } + + /// + /// Represents a Todo item. + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class TodoItemModel + { + + /// + /// Gets or sets the ID of the Todo item. + /// + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Id { get; set; } + + /// + /// Gets or sets the text of the Todo item. + /// + [Newtonsoft.Json.JsonProperty("text", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Text { get; set; } + + /// + /// Gets or sets the date and time the item was created. + /// + [Newtonsoft.Json.JsonProperty("createdAt", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset CreatedAt { get; set; } + + /// + /// Gets or sets the date and time the item was completed. + /// + [Newtonsoft.Json.JsonProperty("completedAt", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset? CompletedAt { get; set; } + + /// + /// Gets or sets the date and time the Todo item was last updated. + /// + [Newtonsoft.Json.JsonProperty("lastUpdated", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset LastUpdated { get; set; } + + /// + /// Gets or sets the optional priority of the Todo item. + /// + [Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + public TodoPriority Priority { get; set; } + + } + + /// + /// Represents a collection of Todo items. + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class TodoListViewModel + { + + /// + /// Gets or sets the Todo item(s). + /// + [Newtonsoft.Json.JsonProperty("items", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Collections.Generic.ICollection Items { get; set; } + + } + + /// + /// The priority levels for a Todo item. + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum TodoPriority + { + + [System.Runtime.Serialization.EnumMember(Value = @"Normal")] + Normal = 0, + + [System.Runtime.Serialization.EnumMember(Value = @"Low")] + Low = 1, + + [System.Runtime.Serialization.EnumMember(Value = @"High")] + High = 2, + + } + + /// + /// Represents the model for updating the priority of a Todo item. + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class UpdateTodoItemPriorityModel + { + + /// + /// Gets or sets the new priority of the Todo item. + /// + [Newtonsoft.Json.JsonProperty("priority", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] + public TodoPriority Priority { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_b071608681806e68/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_b071608681806e68/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..6a3e890499 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_b071608681806e68/NSwagOpenApiClient.verified.cs @@ -0,0 +1,759 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsPOSTAsync(Product body) + { + return ProductsPOSTAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsPOSTAsync(Product body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAllAsync() + { + return ProductsAllAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAllAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsGETAsync(int id) + { + return ProductsGETAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsGETAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products/{id}" + urlBuilder_.Append("products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsPUTAsync(int id, Product body) + { + return ProductsPUTAsync(id, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsPUTAsync(int id, Product body, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("PUT"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products/{id}" + urlBuilder_.Append("products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsPATCHAsync(int id, System.Collections.Generic.IDictionary body) + { + return ProductsPATCHAsync(id, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsPATCHAsync(int id, System.Collections.Generic.IDictionary body, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("PATCH"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products/{id}" + urlBuilder_.Append("products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsDELETEAsync(int id) + { + return ProductsDELETEAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsDELETEAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products/{id}" + urlBuilder_.Append("products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int? Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/AnnotationsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/AnnotationsRequestBuilder.verified.cs new file mode 100644 index 0000000000..73d841b894 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/AnnotationsRequestBuilder.verified.cs @@ -0,0 +1,77 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations +{ + /// + /// Builds and executes requests for operations under \annotations + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AnnotationsRequestBuilder : BaseRequestBuilder + { + /// The AsParameters property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder AsParameters + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder(PathParameters, RequestAdapter); + } + /// The fruit property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.FruitRequestBuilder Fruit + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.FruitRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndEnum property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder IFromFileAndEnum + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder IFromFileAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromObjectAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder IFromObjectAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The multipleForms property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder MultipleForms + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder(PathParameters, RequestAdapter); + } + /// The singleForm property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder SingleForm + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AnnotationsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AnnotationsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/AsParameters/AsParametersRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/AsParameters/AsParametersRequestBuilder.verified.cs new file mode 100644 index 0000000000..c314460094 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/AsParameters/AsParametersRequestBuilder.verified.cs @@ -0,0 +1,117 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters +{ + /// + /// Builds and executes requests for operations under \annotations\AsParameters + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AsParametersRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AsParametersRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/AsParameters?paramEight={paramEight}¶mFour={paramFour}¶mSix={paramSix}¶mTen={paramTen}¶mTwelve={paramTwelve}¶mTwo={paramTwo}{¶mEleven*,paramFive*,paramNine*,paramOne*,paramSeven*,paramThree*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AsParametersRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/AsParameters?paramEight={paramEight}¶mFour={paramFour}¶mSix={paramSix}¶mTen={paramTen}¶mTwelve={paramTwelve}¶mTwo={paramTwo}{¶mEleven*,paramFive*,paramNine*,paramOne*,paramSeven*,paramThree*}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.AsParametersRecord.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AsParameters.AsParametersRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class AsParametersRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + [QueryParameter("paramEight")] + public Time? ParamEight { get; set; } + [QueryParameter("paramEleven")] + public double? ParamEleven { get; set; } + [QueryParameter("paramFive")] + public Date? ParamFive { get; set; } + [QueryParameter("paramFour")] + public DateTimeOffset? ParamFour { get; set; } + [QueryParameter("paramNine")] + public int? ParamNine { get; set; } + /// Description + [QueryParameter("paramOne")] + public Guid? ParamOne { get; set; } + [QueryParameter("paramSeven")] + public Time? ParamSeven { get; set; } + [QueryParameter("paramSix")] + public Date? ParamSix { get; set; } + [QueryParameter("paramTen")] + public int? ParamTen { get; set; } + [QueryParameter("paramThree")] + public DateTimeOffset? ParamThree { get; set; } + [QueryParameter("paramTwelve")] + public double? ParamTwelve { get; set; } + [QueryParameter("paramTwo")] + public Guid? ParamTwo { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AsParametersRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/Fruit/FruitRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/Fruit/FruitRequestBuilder.verified.cs new file mode 100644 index 0000000000..1f743a2e89 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/Fruit/FruitRequestBuilder.verified.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit +{ + /// + /// Builds and executes requests for operations under \annotations\fruit + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FruitRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.annotations.fruit.item collection + /// The id of the fruit that will be created + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FruitRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FruitRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/Fruit/Item/FruitItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/Fruit/Item/FruitItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..2408b0a15d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/Fruit/Item/FruitItemRequestBuilder.verified.cs @@ -0,0 +1,97 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item +{ + /// + /// Builds and executes requests for operations under \annotations\fruit\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FruitItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FruitItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FruitItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/fruit/{id}", rawUrl) + { + } + /// + /// Create a fruit + /// + /// A + /// Description for Schema + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Create a fruit + /// + /// A + /// Description for Schema + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.Fruit.Item.FruitItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FruitItemRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs new file mode 100644 index 0000000000..72889a4a75 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum +{ + /// + /// Builds and executes requests for operations under \annotations\IFromFileAndEnum + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndEnum", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndEnum", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..6cf1bf4636 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString +{ + /// + /// Builds and executes requests for operations under \annotations\IFromFileAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromFileAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromFileAndString.IFromFileAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs new file mode 100644 index 0000000000..654ac6720d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs @@ -0,0 +1,67 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class IFromObjectAndStringPostRequestBody : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The tags property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Tags { get; set; } +#nullable restore +#else + public string Tags { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public IFromObjectAndStringPostRequestBody() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "tags", n => { Tags = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("tags", Tags); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..6fa13e87ac --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString +{ + /// + /// Builds and executes requests for operations under \annotations\IFromObjectAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromObjectAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/IFromObjectAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.IFromObjectAndString.IFromObjectAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/MultipleForms/MultipleFormsPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/MultipleForms/MultipleFormsPostRequestBody.verified.cs new file mode 100644 index 0000000000..1daf33186d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/MultipleForms/MultipleFormsPostRequestBody.verified.cs @@ -0,0 +1,115 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class MultipleFormsPostRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The city property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? City { get; set; } +#nullable restore +#else + public string City { get; set; } +#endif + /// Description for FirstName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// Description for LastName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// The state property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? State { get; set; } +#nullable restore +#else + public string State { get; set; } +#endif + /// Description for Street +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Street { get; set; } +#nullable restore +#else + public string Street { get; set; } +#endif + /// The zipCode property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? ZipCode { get; set; } +#nullable restore +#else + public string ZipCode { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public MultipleFormsPostRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "city", n => { City = n.GetStringValue(); } }, + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + { "state", n => { State = n.GetStringValue(); } }, + { "street", n => { Street = n.GetStringValue(); } }, + { "zipCode", n => { ZipCode = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("city", City); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + writer.WriteStringValue("state", State); + writer.WriteStringValue("street", Street); + writer.WriteStringValue("zipCode", ZipCode); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/MultipleForms/MultipleFormsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/MultipleForms/MultipleFormsRequestBuilder.verified.cs new file mode 100644 index 0000000000..78e5cdc7fc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/MultipleForms/MultipleFormsRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms +{ + /// + /// Builds and executes requests for operations under \annotations\multipleForms + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/multipleForms", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/multipleForms", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.MultipleForms.MultipleFormsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/SingleForm/SingleFormRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/SingleForm/SingleFormRequestBuilder.verified.cs new file mode 100644 index 0000000000..9f80518ba2 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Annotations/SingleForm/SingleFormRequestBuilder.verified.cs @@ -0,0 +1,91 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm +{ + /// + /// Builds and executes requests for operations under \annotations\singleForm + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SingleFormRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public SingleFormRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/singleForm", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public SingleFormRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/annotations/singleForm", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/x-www-form-urlencoded", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.SingleForm.SingleFormRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SingleFormRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..1d9f32b2bc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/KiotaOpenApiClient.verified.cs @@ -0,0 +1,61 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The annotations property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AnnotationsRequestBuilder Annotations + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Annotations.AnnotationsRequestBuilder(PathParameters, RequestAdapter); + } + /// The TypeWithTryParse property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.TypeWithTryParseRequestBuilder TypeWithTryParse + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.TypeWithTryParseRequestBuilder(PathParameters, RequestAdapter); + } + /// The WithOpenApi property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.WithOpenApiRequestBuilder WithOpenApi + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.WithOpenApiRequestBuilder(PathParameters, RequestAdapter); + } + /// The XmlComments property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.XmlCommentsRequestBuilder XmlComments + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.XmlCommentsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/AsParametersRecord.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/AsParametersRecord.verified.cs new file mode 100644 index 0000000000..b703f26d0a --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/AsParametersRecord.verified.cs @@ -0,0 +1,94 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class AsParametersRecord : IParsable + #pragma warning restore CS1591 + { + /// The paramEight property + public Time? ParamEight { get; set; } + /// The paramEleven property + public double? ParamEleven { get; set; } + /// The paramFive property + public Date? ParamFive { get; set; } + /// The paramFour property + public DateTimeOffset? ParamFour { get; set; } + /// The paramNine property + public int? ParamNine { get; set; } + /// The paramOne property + public Guid? ParamOne { get; set; } + /// The paramSeven property + public Time? ParamSeven { get; set; } + /// The paramSix property + public Date? ParamSix { get; set; } + /// The paramTen property + public int? ParamTen { get; set; } + /// The paramThree property + public DateTimeOffset? ParamThree { get; set; } + /// The paramTwelve property + public double? ParamTwelve { get; set; } + /// The paramTwo property + public Guid? ParamTwo { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.AsParametersRecord CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.AsParametersRecord(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "paramEight", n => { ParamEight = n.GetTimeValue(); } }, + { "paramEleven", n => { ParamEleven = n.GetDoubleValue(); } }, + { "paramFive", n => { ParamFive = n.GetDateValue(); } }, + { "paramFour", n => { ParamFour = n.GetDateTimeOffsetValue(); } }, + { "paramNine", n => { ParamNine = n.GetIntValue(); } }, + { "paramOne", n => { ParamOne = n.GetGuidValue(); } }, + { "paramSeven", n => { ParamSeven = n.GetTimeValue(); } }, + { "paramSix", n => { ParamSix = n.GetDateValue(); } }, + { "paramTen", n => { ParamTen = n.GetIntValue(); } }, + { "paramThree", n => { ParamThree = n.GetDateTimeOffsetValue(); } }, + { "paramTwelve", n => { ParamTwelve = n.GetDoubleValue(); } }, + { "paramTwo", n => { ParamTwo = n.GetGuidValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteTimeValue("paramEight", ParamEight); + writer.WriteDoubleValue("paramEleven", ParamEleven); + writer.WriteDateValue("paramFive", ParamFive); + writer.WriteDateTimeOffsetValue("paramFour", ParamFour); + writer.WriteIntValue("paramNine", ParamNine); + writer.WriteGuidValue("paramOne", ParamOne); + writer.WriteTimeValue("paramSeven", ParamSeven); + writer.WriteDateValue("paramSix", ParamSix); + writer.WriteIntValue("paramTen", ParamTen); + writer.WriteDateTimeOffsetValue("paramThree", ParamThree); + writer.WriteDoubleValue("paramTwelve", ParamTwelve); + writer.WriteGuidValue("paramTwo", ParamTwo); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/CurrenciesRate.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/CurrenciesRate.verified.cs new file mode 100644 index 0000000000..b11e7225fd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/CurrenciesRate.verified.cs @@ -0,0 +1,69 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class CurrenciesRate : IParsable + #pragma warning restore CS1591 + { + /// Currency From +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CurrencyFrom { get; set; } +#nullable restore +#else + public string CurrencyFrom { get; set; } +#endif + /// The currencyTo property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CurrencyTo { get; set; } +#nullable restore +#else + public string CurrencyTo { get; set; } +#endif + /// The rate property + public double? Rate { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CurrenciesRate CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CurrenciesRate(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "currencyFrom", n => { CurrencyFrom = n.GetStringValue(); } }, + { "currencyTo", n => { CurrencyTo = n.GetStringValue(); } }, + { "rate", n => { Rate = n.GetDoubleValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("currencyFrom", CurrencyFrom); + writer.WriteStringValue("currencyTo", CurrencyTo); + writer.WriteDoubleValue("rate", Rate); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Fruit.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Fruit.verified.cs new file mode 100644 index 0000000000..8ce9761fec --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Fruit.verified.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Description for Schema + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class Fruit : IParsable + { + /// The name property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Name { get; set; } +#nullable restore +#else + public string Name { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Fruit(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "name", n => { Name = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("name", Name); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/OrganizationCustomExchangeRatesDto.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/OrganizationCustomExchangeRatesDto.verified.cs new file mode 100644 index 0000000000..5cd77a470e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/OrganizationCustomExchangeRatesDto.verified.cs @@ -0,0 +1,58 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class OrganizationCustomExchangeRatesDto : IParsable + #pragma warning restore CS1591 + { + /// The currenciesRates property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public List? CurrenciesRates { get; set; } +#nullable restore +#else + public List CurrenciesRates { get; set; } +#endif + /// The isUpdated property + public bool? IsUpdated { get; private set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "currenciesRates", n => { CurrenciesRates = n.GetCollectionOfObjectValues(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CurrenciesRate.CreateFromDiscriminatorValue)?.AsList(); } }, + { "isUpdated", n => { IsUpdated = n.GetBoolValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteCollectionOfObjectValues("currenciesRates", CurrenciesRates); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Person.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Person.verified.cs new file mode 100644 index 0000000000..50466e2a4d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Person.verified.cs @@ -0,0 +1,65 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Person : IParsable + #pragma warning restore CS1591 + { + /// The firstName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// The lastName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Person CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Person(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/PersonAnnotated.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/PersonAnnotated.verified.cs new file mode 100644 index 0000000000..b21d6a6ae7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/PersonAnnotated.verified.cs @@ -0,0 +1,65 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class PersonAnnotated : IParsable + #pragma warning restore CS1591 + { + /// Description for FirstName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// Description for LastName +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PersonAnnotated(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Product.verified.cs new file mode 100644 index 0000000000..77c098a9d5 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/Product.verified.cs @@ -0,0 +1,63 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents a product + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class Product : ApiException, IParsable + { + /// Describes the product +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// Uniquely identifies the product + public int? Id { get; set; } + /// The primary error message. + public override string Message { get => base.Message; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/WeatherForecast.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/WeatherForecast.verified.cs new file mode 100644 index 0000000000..8dbad82e4f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/Models/WeatherForecast.verified.cs @@ -0,0 +1,67 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class WeatherForecast : IParsable + #pragma warning restore CS1591 + { + /// The date property + public Date? Date { get; set; } + /// The summary property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Summary { get; set; } +#nullable restore +#else + public string Summary { get; set; } +#endif + /// The temperatureC property + public int? TemperatureC { get; set; } + /// The temperatureF property + public int? TemperatureF { get; private set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "date", n => { Date = n.GetDateValue(); } }, + { "summary", n => { Summary = n.GetStringValue(); } }, + { "temperatureC", n => { TemperatureC = n.GetIntValue(); } }, + { "temperatureF", n => { TemperatureF = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDateValue("date", Date); + writer.WriteStringValue("summary", Summary); + writer.WriteIntValue("temperatureC", TemperatureC); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/TypeWithTryParse/Item/WithTryParseItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/TypeWithTryParse/Item/WithTryParseItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..055941e1a7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/TypeWithTryParse/Item/WithTryParseItemRequestBuilder.verified.cs @@ -0,0 +1,85 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item +{ + /// + /// Builds and executes requests for operations under \TypeWithTryParse\{tryParse} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithTryParseItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WithTryParseItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse/{tryParse}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WithTryParseItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse/{tryParse}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithTryParseItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/TypeWithTryParse/TypeWithTryParseRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/TypeWithTryParse/TypeWithTryParseRequestBuilder.verified.cs new file mode 100644 index 0000000000..a7f8892ecd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/TypeWithTryParse/TypeWithTryParseRequestBuilder.verified.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse +{ + /// + /// Builds and executes requests for operations under \TypeWithTryParse + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class TypeWithTryParseRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("tryParse", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.TypeWithTryParse.Item.WithTryParseItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public TypeWithTryParseRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public TypeWithTryParseRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/TypeWithTryParse", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromBody/IFromBodyRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromBody/IFromBodyRequestBuilder.verified.cs new file mode 100644 index 0000000000..9f5b657944 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromBody/IFromBodyRequestBuilder.verified.cs @@ -0,0 +1,91 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromBody + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromBodyRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromBodyRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromBody", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromBodyRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromBody", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.OrganizationCustomExchangeRatesDto body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromBodyRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFile/IFromFileRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFile/IFromFileRequestBuilder.verified.cs new file mode 100644 index 0000000000..61b5424207 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFile/IFromFileRequestBuilder.verified.cs @@ -0,0 +1,105 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFile + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFile?queryParameter={queryParameter}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFile?queryParameter={queryParameter}", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class IFromFileRequestBuilderPostQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("queryParameter")] + public string? QueryParameter { get; set; } +#nullable restore +#else + [QueryParameter("queryParameter")] + public string QueryParameter { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs new file mode 100644 index 0000000000..1500ddcbce --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileAndEnum/IFromFileAndEnumRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFileAndEnum + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndEnum", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndEnumRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndEnum", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndEnumRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..106c2340f6 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileAndString/IFromFileAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFileAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileCollection/IFromFileCollectionRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileCollection/IFromFileCollectionRequestBuilder.verified.cs new file mode 100644 index 0000000000..4afacd0856 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromFileCollection/IFromFileCollectionRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromFileCollection + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileCollectionRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromFileCollectionRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileCollection", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromFileCollectionRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromFileCollection", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromFileCollectionRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs new file mode 100644 index 0000000000..a3c1dcaffc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromObjectAndString/IFromObjectAndStringPostRequestBody.verified.cs @@ -0,0 +1,67 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class IFromObjectAndStringPostRequestBody : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Person, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The tags property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Tags { get; set; } +#nullable restore +#else + public string Tags { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public IFromObjectAndStringPostRequestBody() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "tags", n => { Tags = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("tags", Tags); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs new file mode 100644 index 0000000000..59724371cd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/IFromObjectAndString/IFromObjectAndStringRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\IFromObjectAndString + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromObjectAndString", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public IFromObjectAndStringRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/IFromObjectAndString", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class IFromObjectAndStringRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/MultipleForms/MultipleFormsPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/MultipleForms/MultipleFormsPostRequestBody.verified.cs new file mode 100644 index 0000000000..0b0a90cc76 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/MultipleForms/MultipleFormsPostRequestBody.verified.cs @@ -0,0 +1,115 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class MultipleFormsPostRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The city property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? City { get; set; } +#nullable restore +#else + public string City { get; set; } +#endif + /// The firstName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? FirstName { get; set; } +#nullable restore +#else + public string FirstName { get; set; } +#endif + /// The lastName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? LastName { get; set; } +#nullable restore +#else + public string LastName { get; set; } +#endif + /// The state property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? State { get; set; } +#nullable restore +#else + public string State { get; set; } +#endif + /// The street property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Street { get; set; } +#nullable restore +#else + public string Street { get; set; } +#endif + /// The zipCode property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? ZipCode { get; set; } +#nullable restore +#else + public string ZipCode { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public MultipleFormsPostRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "city", n => { City = n.GetStringValue(); } }, + { "firstName", n => { FirstName = n.GetStringValue(); } }, + { "lastName", n => { LastName = n.GetStringValue(); } }, + { "state", n => { State = n.GetStringValue(); } }, + { "street", n => { Street = n.GetStringValue(); } }, + { "zipCode", n => { ZipCode = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("city", City); + writer.WriteStringValue("firstName", FirstName); + writer.WriteStringValue("lastName", LastName); + writer.WriteStringValue("state", State); + writer.WriteStringValue("street", Street); + writer.WriteStringValue("zipCode", ZipCode); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/MultipleForms/MultipleFormsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/MultipleForms/MultipleFormsRequestBuilder.verified.cs new file mode 100644 index 0000000000..e6aca56210 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/MultipleForms/MultipleFormsRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\multipleForms + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/multipleForms", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public MultipleFormsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/multipleForms", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleFormsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/Weatherforecast/WeatherforecastRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/Weatherforecast/WeatherforecastRequestBuilder.verified.cs new file mode 100644 index 0000000000..94751af1af --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/Weatherforecast/WeatherforecastRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast +{ + /// + /// Builds and executes requests for operations under \WithOpenApi\weatherforecast + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherforecastRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WeatherforecastRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/weatherforecast", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WeatherforecastRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi/weatherforecast", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.WeatherForecast.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherforecastRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/WithOpenApiRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/WithOpenApiRequestBuilder.verified.cs new file mode 100644 index 0000000000..ce7b199d2d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/WithOpenApi/WithOpenApiRequestBuilder.verified.cs @@ -0,0 +1,83 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi +{ + /// + /// Builds and executes requests for operations under \WithOpenApi + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithOpenApiRequestBuilder : BaseRequestBuilder + { + /// The IFromBody property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder IFromBody + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromBody.IFromBodyRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFile property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder IFromFile + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFile.IFromFileRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndEnum property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder IFromFileAndEnum + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndEnum.IFromFileAndEnumRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder IFromFileAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileAndString.IFromFileAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromFileCollection property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder IFromFileCollection + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromFileCollection.IFromFileCollectionRequestBuilder(PathParameters, RequestAdapter); + } + /// The IFromObjectAndString property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder IFromObjectAndString + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.IFromObjectAndString.IFromObjectAndStringRequestBuilder(PathParameters, RequestAdapter); + } + /// The multipleForms property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder MultipleForms + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.MultipleForms.MultipleFormsRequestBuilder(PathParameters, RequestAdapter); + } + /// The weatherforecast property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder Weatherforecast + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.WithOpenApi.Weatherforecast.WeatherforecastRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WithOpenApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WithOpenApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/WithOpenApi", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/Car/CarRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/Car/CarRequestBuilder.verified.cs new file mode 100644 index 0000000000..00c5cffc6e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/Car/CarRequestBuilder.verified.cs @@ -0,0 +1,135 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car +{ + /// + /// Builds and executes requests for operations under \XmlComments\Car + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.item collection + /// The product id + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.item collection + /// The product id + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car?Id={Id}{&Description*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car?Id={Id}{&Description*}", rawUrl) + { + } + /// + /// Returns a specific product using asParameters record + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product using asParameters record + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Returns a specific product using asParameters record + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarRequestBuilderGetQueryParameters + { + /// Describes the product +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// Uniquely identifies the product + public int? Id { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/Car/Item/CarItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/Car/Item/CarItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..92c6c82214 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/Car/Item/CarItemRequestBuilder.verified.cs @@ -0,0 +1,92 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item +{ + /// + /// Builds and executes requests for operations under \XmlComments\Car\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/Car/{id}", rawUrl) + { + } + /// + /// Returns a specific product + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.Item.CarItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/CarWithProduces/CarWithProducesRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/CarWithProduces/CarWithProducesRequestBuilder.verified.cs new file mode 100644 index 0000000000..377741915d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/CarWithProduces/CarWithProducesRequestBuilder.verified.cs @@ -0,0 +1,101 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces +{ + /// + /// Builds and executes requests for operations under \XmlComments\CarWithProduces + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarWithProducesRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProduces?id={id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarWithProducesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProduces?id={id}", rawUrl) + { + } + /// + /// Returns a specific product With Produces attribute + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product With Produces attribute + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Returns a specific product With Produces attribute + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesRequestBuilderGetQueryParameters + { + [QueryParameter("id")] + public int? Id { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/CarWithProducesDefaultResponseType/CarWithProducesDefaultResponseTypeRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/CarWithProducesDefaultResponseType/CarWithProducesDefaultResponseTypeRequestBuilder.verified.cs new file mode 100644 index 0000000000..468b0235ce --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/CarWithProducesDefaultResponseType/CarWithProducesDefaultResponseTypeRequestBuilder.verified.cs @@ -0,0 +1,106 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType +{ + /// + /// Builds and executes requests for operations under \XmlComments\CarWithProducesDefaultResponseType + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesDefaultResponseTypeRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CarWithProducesDefaultResponseTypeRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProducesDefaultResponseType?id={id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CarWithProducesDefaultResponseTypeRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments/CarWithProducesDefaultResponseType?id={id}", rawUrl) + { + } + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + /// When receiving a 4XX or 5XX status code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var errorMapping = new Dictionary> + { + { "XXX", global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue }, + }; + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesDefaultResponseTypeRequestBuilderGetQueryParameters + { + [QueryParameter("id")] + public int? Id { get; set; } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CarWithProducesDefaultResponseTypeRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/XmlCommentsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/XmlCommentsRequestBuilder.verified.cs new file mode 100644 index 0000000000..4ea49e8371 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ba95e19a2268ba0d/XmlComments/XmlCommentsRequestBuilder.verified.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments +{ + /// + /// Builds and executes requests for operations under \XmlComments + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class XmlCommentsRequestBuilder : BaseRequestBuilder + { + /// The Car property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder Car + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.Car.CarRequestBuilder(PathParameters, RequestAdapter); + } + /// The CarWithProduces property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder CarWithProduces + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProduces.CarWithProducesRequestBuilder(PathParameters, RequestAdapter); + } + /// The CarWithProducesDefaultResponseType property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder CarWithProducesDefaultResponseType + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.XmlComments.CarWithProducesDefaultResponseType.CarWithProducesDefaultResponseTypeRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public XmlCommentsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public XmlCommentsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/XmlComments", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_bd8e5ffa55d2e869/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_bd8e5ffa55d2e869/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..5036e7874a --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_bd8e5ffa55d2e869/NSwagOpenApiClient.verified.cs @@ -0,0 +1,368 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// User created + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CreateUserAsync(Body body) + { + return CreateUserAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// User created + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CreateUserAsync(Body body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/users" + urlBuilder_.Append("api/users"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 201) + { + return; + } + else + if (status_ == 400) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Invalid request", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Body + { + + [Newtonsoft.Json.JsonProperty("email", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Email { get; set; } + + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Always)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Password { get; set; } + + private System.Collections.Generic.IDictionary _additionalProperties; + + [Newtonsoft.Json.JsonExtensionData] + public System.Collections.Generic.IDictionary AdditionalProperties + { + get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary()); } + set { _additionalProperties = value; } + } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Addresses/AddressesRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Addresses/AddressesRequestBuilder.verified.cs new file mode 100644 index 0000000000..7fba6168de --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Addresses/AddressesRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.Validate; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses +{ + /// + /// Builds and executes requests for operations under \addresses + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AddressesRequestBuilder : BaseRequestBuilder + { + /// The validate property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.Validate.ValidateRequestBuilder Validate + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.Validate.ValidateRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AddressesRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/addresses", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AddressesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/addresses", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Addresses/Validate/ValidateRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Addresses/Validate/ValidateRequestBuilder.verified.cs new file mode 100644 index 0000000000..437c3fa9f0 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Addresses/Validate/ValidateRequestBuilder.verified.cs @@ -0,0 +1,110 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.Validate +{ + /// + /// Builds and executes requests for operations under \addresses\validate + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ValidateRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ValidateRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/addresses/validate?country={country}{&city*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ValidateRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/addresses/validate?country={country}{&city*}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.Validate.ValidateRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.Validate.ValidateRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ValidateRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { + /// Name of city +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("city")] + public string? City { get; set; } +#nullable restore +#else + [QueryParameter("city")] + public string City { get; set; } +#endif + /// 3-letter ISO country code +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("country")] + public string? Country { get; set; } +#nullable restore +#else + [QueryParameter("country")] + public string Country { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ValidateRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Carts/CartsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Carts/CartsRequestBuilder.verified.cs new file mode 100644 index 0000000000..99b9fd258f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Carts/CartsRequestBuilder.verified.cs @@ -0,0 +1,117 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts +{ + /// + /// Builds and executes requests for operations under \carts + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CartsRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.carts.item collection + /// The cart identifier + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item.CartsItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item.CartsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.carts.item collection + /// The cart identifier + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item.CartsItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item.CartsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CartsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/carts", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CartsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/carts", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json, text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.CartsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.CartsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CartsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Carts/Item/CartsItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Carts/Item/CartsItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..36c4f27c74 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Carts/Item/CartsItemRequestBuilder.verified.cs @@ -0,0 +1,134 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item +{ + /// + /// Builds and executes requests for operations under \carts\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CartsItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CartsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/carts/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CartsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/carts/{id}", rawUrl) + { + } + /// + /// Requires admin privileges + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// External docs for CartsByIdGet + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Requires admin privileges + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json, text/plain;q=0.9"); + return requestInfo; + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json, text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item.CartsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.Item.CartsItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CartsItemRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CartsItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Country/CountryRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Country/CountryRequestBuilder.verified.cs new file mode 100644 index 0000000000..2f0b117fb6 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Country/CountryRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.Validate; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country +{ + /// + /// Builds and executes requests for operations under \country + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CountryRequestBuilder : BaseRequestBuilder + { + /// The validate property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.Validate.ValidateRequestBuilder Validate + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.Validate.ValidateRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CountryRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/country", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CountryRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/country", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Country/Validate/ValidateRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Country/Validate/ValidateRequestBuilder.verified.cs new file mode 100644 index 0000000000..70e1a9bb4f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Country/Validate/ValidateRequestBuilder.verified.cs @@ -0,0 +1,99 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.Validate +{ + /// + /// Builds and executes requests for operations under \country\validate + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ValidateRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ValidateRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/country/validate{?country*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ValidateRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/country/validate{?country*}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.Validate.ValidateRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.Validate.ValidateRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ValidateRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("country")] + public string? Country { get; set; } +#nullable restore +#else + [QueryParameter("country")] + public string Country { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ValidateRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Dragons/DragonsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Dragons/DragonsRequestBuilder.verified.cs new file mode 100644 index 0000000000..8e9b74fdc9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Dragons/DragonsRequestBuilder.verified.cs @@ -0,0 +1,89 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Dragons +{ + /// + /// Builds and executes requests for operations under \dragons + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DragonsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public DragonsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/dragons", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public DragonsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/dragons", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(UntypedNode body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(UntypedNode body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(UntypedNode body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(UntypedNode body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Dragons.DragonsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Dragons.DragonsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class DragonsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/FilesRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/FilesRequestBuilder.verified.cs new file mode 100644 index 0000000000..5486f6a6ca --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/FilesRequestBuilder.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FormWithFile; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Multiple; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.SingleNamespace; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files +{ + /// + /// Builds and executes requests for operations under \files + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FilesRequestBuilder : BaseRequestBuilder + { + /// The formWithFile property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FormWithFile.FormWithFileRequestBuilder FormWithFile + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FormWithFile.FormWithFileRequestBuilder(PathParameters, RequestAdapter); + } + /// The multiple property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Multiple.MultipleRequestBuilder Multiple + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Multiple.MultipleRequestBuilder(PathParameters, RequestAdapter); + } + /// The single property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.SingleNamespace.SingleRequestBuilder Single + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.SingleNamespace.SingleRequestBuilder(PathParameters, RequestAdapter); + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.files.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("name", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FilesRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FilesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/FormWithFile/FormWithFileRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/FormWithFile/FormWithFileRequestBuilder.verified.cs new file mode 100644 index 0000000000..cc95ee02ec --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/FormWithFile/FormWithFileRequestBuilder.verified.cs @@ -0,0 +1,89 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FormWithFile +{ + /// + /// Builds and executes requests for operations under \files\form-with-file + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FormWithFileRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public FormWithFileRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/form-with-file", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public FormWithFileRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/form-with-file", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FormWithFile.FormWithFileRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FormWithFile.FormWithFileRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class FormWithFileRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/Item/WithNameItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/Item/WithNameItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..8a077807be --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/Item/WithNameItemRequestBuilder.verified.cs @@ -0,0 +1,203 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item +{ + /// + /// Builds and executes requests for operations under \files\{name} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithNameItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WithNameItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/{name}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WithNameItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/{name}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsWithNameGetResponseAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsWithNameGetResponseAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder.WithNameGetResponse.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + [Obsolete("This method is obsolete. Use GetAsWithNameGetResponseAsync instead.")] +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder.WithNameResponse.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Composed type wrapper for classes + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithNameGetResponse : IComposedTypeWrapper, IParsable + { + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public byte[]? Binary { get; set; } +#nullable restore +#else + public byte[] Binary { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder.WithNameGetResponse CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("")?.GetStringValue(); + var result = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder.WithNameGetResponse(); + if(parseNode.GetByteArrayValue() is byte[] binaryValue) + { + result.Binary = binaryValue; + } + return result; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary>(); + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + if(Binary != null) + { + writer.WriteByteArrayValue(null, Binary); + } + } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithNameItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + /// + /// Composed type wrapper for classes + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithNameResponse : IComposedTypeWrapper, IParsable + { + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public byte[]? Binary { get; set; } +#nullable restore +#else + public byte[] Binary { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder.WithNameResponse CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("")?.GetStringValue(); + var result = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Item.WithNameItemRequestBuilder.WithNameResponse(); + if(parseNode.GetByteArrayValue() is byte[] binaryValue) + { + result.Binary = binaryValue; + } + return result; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary>(); + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + if(Binary != null) + { + writer.WriteByteArrayValue(null, Binary); + } + } + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/Multiple/MultipleRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/Multiple/MultipleRequestBuilder.verified.cs new file mode 100644 index 0000000000..ee1756e790 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/Multiple/MultipleRequestBuilder.verified.cs @@ -0,0 +1,89 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Multiple +{ + /// + /// Builds and executes requests for operations under \files\multiple + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public MultipleRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/multiple", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public MultipleRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/multiple", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Multiple.MultipleRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.Multiple.MultipleRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class MultipleRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/SingleNamespace/SingleRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/SingleNamespace/SingleRequestBuilder.verified.cs new file mode 100644 index 0000000000..26eaec4466 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Files/SingleNamespace/SingleRequestBuilder.verified.cs @@ -0,0 +1,89 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.SingleNamespace +{ + /// + /// Builds and executes requests for operations under \files\single + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SingleRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public SingleRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/single", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public SingleRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/files/single", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.SingleNamespace.SingleRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.SingleNamespace.SingleRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SingleRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Issue3013/Get/GetRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Issue3013/Get/GetRequestBuilder.verified.cs new file mode 100644 index 0000000000..74911b8dc9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Issue3013/Get/GetRequestBuilder.verified.cs @@ -0,0 +1,86 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Get +{ + /// + /// Builds and executes requests for operations under \Issue3013\Get + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class GetRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public GetRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Issue3013/Get", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public GetRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Issue3013/Get", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestResponse.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json, text/plain;q=0.9"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Get.GetRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Get.GetRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class GetRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Issue3013/Issue3013RequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Issue3013/Issue3013RequestBuilder.verified.cs new file mode 100644 index 0000000000..ba52057f89 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Issue3013/Issue3013RequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Get; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013 +{ + /// + /// Builds and executes requests for operations under \Issue3013 + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class Issue3013RequestBuilder : BaseRequestBuilder + { + /// The GetPath property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Get.GetRequestBuilder GetPath + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Get.GetRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public Issue3013RequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Issue3013", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public Issue3013RequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Issue3013", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..a964f8c532 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/KiotaOpenApiClient.verified.cs @@ -0,0 +1,145 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Dragons; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Kittens; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Orders; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Promotions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithEnumParameter; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithIgnoreProperties; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The addresses property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.AddressesRequestBuilder Addresses + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Addresses.AddressesRequestBuilder(PathParameters, RequestAdapter); + } + /// The carts property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.CartsRequestBuilder Carts + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Carts.CartsRequestBuilder(PathParameters, RequestAdapter); + } + /// The country property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.CountryRequestBuilder Country + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Country.CountryRequestBuilder(PathParameters, RequestAdapter); + } + /// The dragons property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Dragons.DragonsRequestBuilder Dragons + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Dragons.DragonsRequestBuilder(PathParameters, RequestAdapter); + } + /// The files property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FilesRequestBuilder Files + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Files.FilesRequestBuilder(PathParameters, RequestAdapter); + } + /// The Issue3013 property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Issue3013RequestBuilder Issue3013 + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Issue3013.Issue3013RequestBuilder(PathParameters, RequestAdapter); + } + /// The kittens property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Kittens.KittensRequestBuilder Kittens + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Kittens.KittensRequestBuilder(PathParameters, RequestAdapter); + } + /// The orders property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Orders.OrdersRequestBuilder Orders + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Orders.OrdersRequestBuilder(PathParameters, RequestAdapter); + } + /// The payments property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.PaymentsRequestBuilder Payments + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.PaymentsRequestBuilder(PathParameters, RequestAdapter); + } + /// The products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// The promotions property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Promotions.PromotionsRequestBuilder Promotions + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Promotions.PromotionsRequestBuilder(PathParameters, RequestAdapter); + } + /// The registrations property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsRequestBuilder Registrations + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsRequestBuilder(PathParameters, RequestAdapter); + } + /// The registrationsWithEnumParameter property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithEnumParameter.RegistrationsWithEnumParameterRequestBuilder RegistrationsWithEnumParameter + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithEnumParameter.RegistrationsWithEnumParameterRequestBuilder(PathParameters, RequestAdapter); + } + /// The registrationsWithIgnoreProperties property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithIgnoreProperties.RegistrationsWithIgnorePropertiesRequestBuilder RegistrationsWithIgnoreProperties + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithIgnoreProperties.RegistrationsWithIgnorePropertiesRequestBuilder(PathParameters, RequestAdapter); + } + /// The shapes property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder Shapes + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder(PathParameters, RequestAdapter); + } + /// The stores property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.StoresRequestBuilder Stores + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.StoresRequestBuilder(PathParameters, RequestAdapter); + } + /// The unicorns property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsRequestBuilder Unicorns + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsRequestBuilder(PathParameters, RequestAdapter); + } + /// The zipCodes property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.ZipCodesRequestBuilder ZipCodes + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.ZipCodesRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Kittens/KittensRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Kittens/KittensRequestBuilder.verified.cs new file mode 100644 index 0000000000..9b3fabfde3 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Kittens/KittensRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Kittens +{ + /// + /// Builds and executes requests for operations under \kittens + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KittensRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public KittensRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/kittens", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public KittensRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/kittens", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(UntypedNode body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(UntypedNode body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(UntypedNode body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(UntypedNode body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Kittens.KittensRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Kittens.KittensRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KittensRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Cart.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Cart.verified.cs new file mode 100644 index 0000000000..ba75b1190f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Cart.verified.cs @@ -0,0 +1,52 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Cart : IParsable + #pragma warning restore CS1591 + { + /// The cart type + public int? CartType { get; set; } + /// The cart identifier + public int? Id { get; private set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cart(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "cartType", n => { CartType = n.GetIntValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteIntValue("cartType", CartType); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Circle.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Circle.verified.cs new file mode 100644 index 0000000000..332eb18ee6 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Circle.verified.cs @@ -0,0 +1,60 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Circle : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Shape, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The radius property + public int? Radius { get; set; } + /// + /// Instantiates a new and sets the default values. + /// + public Circle() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Circle CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Circle(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "radius", n => { Radius = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteIntValue("radius", Radius); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/CreditCard.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/CreditCard.verified.cs new file mode 100644 index 0000000000..acf3fa2026 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/CreditCard.verified.cs @@ -0,0 +1,63 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class CreditCard : IParsable + #pragma warning restore CS1591 + { + /// The cardNumber property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CardNumber { get; set; } +#nullable restore +#else + public string CardNumber { get; set; } +#endif + /// The expMonth property + public int? ExpMonth { get; set; } + /// The expYear property + public int? ExpYear { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreditCard CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreditCard(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "cardNumber", n => { CardNumber = n.GetStringValue(); } }, + { "expMonth", n => { ExpMonth = n.GetIntValue(); } }, + { "expYear", n => { ExpYear = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("cardNumber", CardNumber); + writer.WriteIntValue("expMonth", ExpMonth); + writer.WriteIntValue("expYear", ExpYear); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/DiscountType.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/DiscountType.verified.cs new file mode 100644 index 0000000000..f847b26979 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/DiscountType.verified.cs @@ -0,0 +1,20 @@ +// +using System.Runtime.Serialization; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public enum DiscountType + #pragma warning restore CS1591 + { + [EnumMember(Value = "Percentage")] + #pragma warning disable CS1591 + Percentage, + #pragma warning restore CS1591 + [EnumMember(Value = "Amount")] + #pragma warning disable CS1591 + Amount, + #pragma warning restore CS1591 + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/PaymentRequest.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/PaymentRequest.verified.cs new file mode 100644 index 0000000000..483114978d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/PaymentRequest.verified.cs @@ -0,0 +1,65 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class PaymentRequest : IParsable + #pragma warning restore CS1591 + { + /// The creditCard property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreditCard? CreditCard { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreditCard CreditCard { get; set; } +#endif + /// The transaction property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Transaction? Transaction { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Transaction Transaction { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PaymentRequest CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PaymentRequest(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "creditCard", n => { CreditCard = n.GetObjectValue(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.CreditCard.CreateFromDiscriminatorValue); } }, + { "transaction", n => { Transaction = n.GetObjectValue(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Transaction.CreateFromDiscriminatorValue); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteObjectValue("creditCard", CreditCard); + writer.WriteObjectValue("transaction", Transaction); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Product.verified.cs new file mode 100644 index 0000000000..547ecaf118 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Product.verified.cs @@ -0,0 +1,72 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + /// + /// Represents a product + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class Product : IParsable + { + /// Describes the product +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// Uniquely identifies the product + public int? Id { get; set; } + /// The price property + public double? Price { get; set; } + /// The status property + public int? Status { get; set; } + /// The status2 property + public int? Status2 { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + { "price", n => { Price = n.GetDoubleValue(); } }, + { "status", n => { Status = n.GetIntValue(); } }, + { "status2", n => { Status2 = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + writer.WriteDoubleValue("price", Price); + writer.WriteIntValue("status", Status); + writer.WriteIntValue("status2", Status2); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Promotion.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Promotion.verified.cs new file mode 100644 index 0000000000..0cb92a9dea --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Promotion.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Promotion : IParsable + #pragma warning restore CS1591 + { + /// The discountType property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.DiscountType? DiscountType { get; set; } + /// The promoCode property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? PromoCode { get; set; } +#nullable restore +#else + public string PromoCode { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Promotion CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Promotion(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "discountType", n => { DiscountType = n.GetEnumValue(); } }, + { "promo-code", n => { PromoCode = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteEnumValue("discountType", DiscountType); + writer.WriteStringValue("promo-code", PromoCode); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Rectangle.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Rectangle.verified.cs new file mode 100644 index 0000000000..2f5c0e54b4 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Rectangle.verified.cs @@ -0,0 +1,64 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Rectangle : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Shape, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The height property + public int? Height { get; set; } + /// The width property + public int? Width { get; set; } + /// + /// Instantiates a new and sets the default values. + /// + public Rectangle() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Rectangle CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Rectangle(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "height", n => { Height = n.GetIntValue(); } }, + { "width", n => { Width = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteIntValue("height", Height); + writer.WriteIntValue("width", Width); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Shape.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Shape.verified.cs new file mode 100644 index 0000000000..92e3954fdd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Shape.verified.cs @@ -0,0 +1,71 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Shape : IParsable + #pragma warning restore CS1591 + { + /// The name property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Name { get; set; } +#nullable restore +#else + public string Name { get; set; } +#endif + /// The TypeName property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? TypeName { get; set; } +#nullable restore +#else + public string TypeName { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Shape CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("TypeName")?.GetStringValue(); + return mappingValue switch + { + "Circle" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Circle(), + "Rectangle" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Rectangle(), + _ => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Shape(), + }; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "name", n => { Name = n.GetStringValue(); } }, + { "TypeName", n => { TypeName = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("name", Name); + writer.WriteStringValue("TypeName", TypeName); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Store.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Store.verified.cs new file mode 100644 index 0000000000..cfa383ede7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Store.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Store : IParsable + #pragma warning restore CS1591 + { + /// The id property + public int? Id { get; set; } + /// The location property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Location { get; set; } +#nullable restore +#else + public string Location { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Store CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Store(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "id", n => { Id = n.GetIntValue(); } }, + { "location", n => { Location = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteIntValue("id", Id); + writer.WriteStringValue("location", Location); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/TestResponse.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/TestResponse.verified.cs new file mode 100644 index 0000000000..c7b2007674 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/TestResponse.verified.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class TestResponse : IParsable + #pragma warning restore CS1591 + { + /// The foo property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestStruct? Foo { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestStruct Foo { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestResponse CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestResponse(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "foo", n => { Foo = n.GetObjectValue(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestStruct.CreateFromDiscriminatorValue); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteObjectValue("foo", Foo); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/TestStruct.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/TestStruct.verified.cs new file mode 100644 index 0000000000..0a7e06dc2c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/TestStruct.verified.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class TestStruct : IParsable + #pragma warning restore CS1591 + { + /// The a property + public int? A { get; set; } + /// The b property + public int? B { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestStruct CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.TestStruct(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "a", n => { A = n.GetIntValue(); } }, + { "b", n => { B = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteIntValue("a", A); + writer.WriteIntValue("b", B); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Transaction.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Transaction.verified.cs new file mode 100644 index 0000000000..6a797549af --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Models/Transaction.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Transaction : IParsable + #pragma warning restore CS1591 + { + /// The amount property + public double? Amount { get; set; } + /// The note property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Note { get; set; } +#nullable restore +#else + public string Note { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Transaction CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Transaction(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "amount", n => { Amount = n.GetDoubleValue(); } }, + { "note", n => { Note = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteDoubleValue("amount", Amount); + writer.WriteStringValue("note", Note); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Orders/OrdersRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Orders/OrdersRequestBuilder.verified.cs new file mode 100644 index 0000000000..c07712c3b0 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Orders/OrdersRequestBuilder.verified.cs @@ -0,0 +1,95 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Orders +{ + /// + /// Builds and executes requests for operations under \orders + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class OrdersRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public OrdersRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/orders", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public OrdersRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/orders", rawUrl) + { + } + /// + /// Creates an order + /// + /// Binary request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(Stream body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(Stream body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + await RequestAdapter.SendNoContentAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Creates an order + /// + /// A + /// Binary request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(Stream body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(Stream body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/xml"); + requestInfo.SetStreamContent(body, "application/xml"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Orders.OrdersRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Orders.OrdersRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class OrdersRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Authorize/AuthorizeRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Authorize/AuthorizeRequestBuilder.verified.cs new file mode 100644 index 0000000000..5e14cd4209 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Authorize/AuthorizeRequestBuilder.verified.cs @@ -0,0 +1,91 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Authorize +{ + /// + /// Builds and executes requests for operations under \payments\authorize + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AuthorizeRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AuthorizeRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments/authorize", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AuthorizeRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments/authorize", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PaymentRequest body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PaymentRequest body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PaymentRequest body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.PaymentRequest body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Authorize.AuthorizeRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Authorize.AuthorizeRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AuthorizeRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Item/Cancel/CancelRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Item/Cancel/CancelRequestBuilder.verified.cs new file mode 100644 index 0000000000..4e55c1dffb --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Item/Cancel/CancelRequestBuilder.verified.cs @@ -0,0 +1,84 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.Cancel +{ + /// + /// Builds and executes requests for operations under \payments\{paymentId}\cancel + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CancelRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public CancelRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments/{paymentId}/cancel", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public CancelRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments/{paymentId}/cancel", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PutAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PutAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToPutRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPutRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPutRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.PUT, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.Cancel.CancelRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.Cancel.CancelRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class CancelRequestBuilderPutRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Item/WithPaymentItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Item/WithPaymentItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..9771fe9316 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/Item/WithPaymentItemRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.Cancel; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item +{ + /// + /// Builds and executes requests for operations under \payments\{paymentId} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WithPaymentItemRequestBuilder : BaseRequestBuilder + { + /// The cancel property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.Cancel.CancelRequestBuilder Cancel + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.Cancel.CancelRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WithPaymentItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments/{paymentId}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WithPaymentItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments/{paymentId}", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/PaymentsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/PaymentsRequestBuilder.verified.cs new file mode 100644 index 0000000000..6b6d77cb4b --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Payments/PaymentsRequestBuilder.verified.cs @@ -0,0 +1,54 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Authorize; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments +{ + /// + /// Builds and executes requests for operations under \payments + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class PaymentsRequestBuilder : BaseRequestBuilder + { + /// The authorize property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Authorize.AuthorizeRequestBuilder Authorize + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Authorize.AuthorizeRequestBuilder(PathParameters, RequestAdapter); + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.payments.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.WithPaymentItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("paymentId", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Payments.Item.WithPaymentItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public PaymentsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public PaymentsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/payments", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/All/AllRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/All/AllRequestBuilder.verified.cs new file mode 100644 index 0000000000..c31d2364aa --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/All/AllRequestBuilder.verified.cs @@ -0,0 +1,93 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.All +{ + /// + /// Builds and executes requests for operations under \products\all + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AllRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AllRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/all", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AllRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/all", rawUrl) + { + } + /// + /// ```{ "Id":1, "Description":"", "Status": 0, "Status2": 1} ``` + /// + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// + /// ```{ "Id":1, "Description":"", "Status": 0, "Status2": 1} ``` + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.All.AllRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.All.AllRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AllRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/Item/ProductsItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/Item/ProductsItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..03162fda40 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/Item/ProductsItemRequestBuilder.verified.cs @@ -0,0 +1,234 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item +{ + /// + /// Builds and executes requests for operations under \products\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/{id}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products/{id}", rawUrl) + { + } + /// + /// Deletes a specific product + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Returns a specific product + /// + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Only provided properties will be updated, other remain unchanged.Identifier must be non-default valueBody must be specified + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PatchAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PatchAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPatchRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Updates all properties of a specific product + /// + /// A + /// Represents a product + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PutAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PutAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPutRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Deletes a specific product + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a specific product + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Only provided properties will be updated, other remain unchanged.Identifier must be non-default valueBody must be specified + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPatchRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPatchRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PATCH, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Updates all properties of a specific product + /// + /// A + /// Represents a product + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPutRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPutRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PUT, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderPatchRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderPutRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/Item/ProductsPatchRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/Item/ProductsPatchRequestBody.verified.cs new file mode 100644 index 0000000000..aa13c65c65 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/Item/ProductsPatchRequestBody.verified.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProductsPatchRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// + /// Instantiates a new and sets the default values. + /// + public ProductsPatchRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsPatchRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..af6b4fb2b5 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,192 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.All; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// The all property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.All.AllRequestBuilder All + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.All.AllRequestBuilder(PathParameters, RequestAdapter); + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.products.item collection + /// The product id + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.products.item collection + /// The product id + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products{?kw*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/products{?kw*}", rawUrl) + { + } + /// + /// Searches the collection of products by description key words + /// + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// + /// ## Heading 1 POST /products { "id": "123", "description": "Some product" } + /// + /// A + /// Represents a product + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Searches the collection of products by description key words + /// + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// ## Heading 1 POST /products { "id": "123", "description": "Some product" } + /// + /// A + /// Represents a product + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Searches the collection of products by description key words + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetQueryParameters + { + /// A list of search terms +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("kw")] + public string? Kw { get; set; } +#nullable restore +#else + [QueryParameter("kw")] + public string Kw { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Promotions/PromotionsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Promotions/PromotionsRequestBuilder.verified.cs new file mode 100644 index 0000000000..c36d7d2e82 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Promotions/PromotionsRequestBuilder.verified.cs @@ -0,0 +1,87 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Promotions +{ + /// + /// Builds and executes requests for operations under \promotions + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class PromotionsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public PromotionsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/promotions", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public PromotionsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/promotions", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Promotion> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Promotion.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Promotions.PromotionsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Promotions.PromotionsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class PromotionsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Registrations/RegistrationsPostRequestBody.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Registrations/RegistrationsPostRequestBody.verified.cs new file mode 100644 index 0000000000..820571787f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Registrations/RegistrationsPostRequestBody.verified.cs @@ -0,0 +1,95 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class RegistrationsPostRequestBody : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// Description for file +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public byte[]? FormFile { get; set; } +#nullable restore +#else + public byte[] FormFile { get; set; } +#endif + /// Summary for Name +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Name { get; set; } +#nullable restore +#else + public string Name { get; set; } +#endif + /// Summary for PhoneNumbers +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public List? PhoneNumbers { get; set; } +#nullable restore +#else + public List PhoneNumbers { get; set; } +#endif + /// Description for Text +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Text { get; set; } +#nullable restore +#else + public string Text { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public RegistrationsPostRequestBody() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsPostRequestBody(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "formFile", n => { FormFile = n.GetByteArrayValue(); } }, + { "name", n => { Name = n.GetStringValue(); } }, + { "phoneNumbers", n => { PhoneNumbers = n.GetCollectionOfPrimitiveValues()?.AsList(); } }, + { "text", n => { Text = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteByteArrayValue("formFile", FormFile); + writer.WriteStringValue("name", Name); + writer.WriteCollectionOfPrimitiveValues("phoneNumbers", PhoneNumbers); + writer.WriteStringValue("text", Text); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Registrations/RegistrationsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Registrations/RegistrationsRequestBuilder.verified.cs new file mode 100644 index 0000000000..913425d3b7 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Registrations/RegistrationsRequestBuilder.verified.cs @@ -0,0 +1,95 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations +{ + /// + /// Builds and executes requests for operations under \registrations + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RegistrationsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public RegistrationsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/registrations", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public RegistrationsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/registrations", rawUrl) + { + } + /// + /// Form parameters with description + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Form parameters with description + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/x-www-form-urlencoded", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Registrations.RegistrationsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RegistrationsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/RegistrationsWithEnumParameter/RegistrationsWithEnumParameterRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/RegistrationsWithEnumParameter/RegistrationsWithEnumParameterRequestBuilder.verified.cs new file mode 100644 index 0000000000..3ea9bb3193 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/RegistrationsWithEnumParameter/RegistrationsWithEnumParameterRequestBuilder.verified.cs @@ -0,0 +1,95 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithEnumParameter +{ + /// + /// Builds and executes requests for operations under \registrationsWithEnumParameter + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RegistrationsWithEnumParameterRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public RegistrationsWithEnumParameterRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/registrationsWithEnumParameter", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public RegistrationsWithEnumParameterRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/registrationsWithEnumParameter", rawUrl) + { + } + /// + /// Form parameters with description + /// + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// + /// Form parameters with description + /// + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithEnumParameter.RegistrationsWithEnumParameterRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithEnumParameter.RegistrationsWithEnumParameterRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RegistrationsWithEnumParameterRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/RegistrationsWithIgnoreProperties/RegistrationsWithIgnorePropertiesRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/RegistrationsWithIgnoreProperties/RegistrationsWithIgnorePropertiesRequestBuilder.verified.cs new file mode 100644 index 0000000000..33dda59d28 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/RegistrationsWithIgnoreProperties/RegistrationsWithIgnorePropertiesRequestBuilder.verified.cs @@ -0,0 +1,89 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithIgnoreProperties +{ + /// + /// Builds and executes requests for operations under \registrationsWithIgnoreProperties + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RegistrationsWithIgnorePropertiesRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public RegistrationsWithIgnorePropertiesRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/registrationsWithIgnoreProperties", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public RegistrationsWithIgnorePropertiesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/registrationsWithIgnoreProperties", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(MultipartBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(MultipartBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(MultipartBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(MultipartBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "multipart/form-data", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithIgnoreProperties.RegistrationsWithIgnorePropertiesRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.RegistrationsWithIgnoreProperties.RegistrationsWithIgnorePropertiesRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RegistrationsWithIgnorePropertiesRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Shapes/ShapesRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Shapes/ShapesRequestBuilder.verified.cs new file mode 100644 index 0000000000..bdabf09ab1 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Shapes/ShapesRequestBuilder.verified.cs @@ -0,0 +1,166 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes +{ + /// + /// Builds and executes requests for operations under \shapes + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ShapesRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ShapesRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/shapes", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ShapesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/shapes", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder.ShapesPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder.ShapesPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder.ShapesPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder.ShapesPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Composed type wrapper for classes , + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ShapesPostRequestBody : IComposedTypeWrapper, IParsable + { + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Circle? Circle { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Circle Circle { get; set; } +#endif + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Rectangle? Rectangle { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Rectangle Rectangle { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder.ShapesPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("TypeName")?.GetStringValue(); + var result = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Shapes.ShapesRequestBuilder.ShapesPostRequestBody(); + if("Circle".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.Circle = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Circle(); + } + else if("Rectangle".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.Rectangle = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Rectangle(); + } + return result; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + if(Circle != null) + { + return Circle.GetFieldDeserializers(); + } + else if(Rectangle != null) + { + return Rectangle.GetFieldDeserializers(); + } + return new Dictionary>(); + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + if(Circle != null) + { + writer.WriteObjectValue(null, Circle); + } + else if(Rectangle != null) + { + writer.WriteObjectValue(null, Rectangle); + } + } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ShapesRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Stores/Item/StoresItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Stores/Item/StoresItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..a4e3266e05 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Stores/Item/StoresItemRequestBuilder.verified.cs @@ -0,0 +1,179 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item +{ + /// + /// Builds and executes requests for operations under \stores\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class StoresItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public StoresItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/stores/{id}{?id*,location*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public StoresItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/stores/{id}{?id*,location*}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Store.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PutAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PutAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToPutRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPutRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPutRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.PUT, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item.StoresItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item.StoresItemRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class StoresItemRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class StoresItemRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class StoresItemRequestBuilderPutQueryParameters + #pragma warning restore CS1591 + { + [QueryParameter("id")] + public int? Id { get; set; } +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("location")] + public string? Location { get; set; } +#nullable restore +#else + [QueryParameter("location")] + public string Location { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class StoresItemRequestBuilderPutRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Stores/StoresRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Stores/StoresRequestBuilder.verified.cs new file mode 100644 index 0000000000..bcdaee7f5d --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Stores/StoresRequestBuilder.verified.cs @@ -0,0 +1,184 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores +{ + /// + /// Builds and executes requests for operations under \stores + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class StoresRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.stores.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item.StoresItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item.StoresItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.stores.item collection + /// Unique identifier of the item + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item.StoresItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.Item.StoresItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public StoresRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/stores{?id*,location*,locations*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public StoresRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/stores{?id*,location*,locations*}", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Store> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Store.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToPostRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.StoresRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Stores.StoresRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class StoresRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("locations")] + public string[]? Locations { get; set; } +#nullable restore +#else + [QueryParameter("locations")] + public string[] Locations { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class StoresRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class StoresRequestBuilderPostQueryParameters + #pragma warning restore CS1591 + { + [QueryParameter("id")] + public int? Id { get; set; } +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("location")] + public string? Location { get; set; } +#nullable restore +#else + [QueryParameter("location")] + public string Location { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class StoresRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsGetResponse.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsGetResponse.verified.cs new file mode 100644 index 0000000000..9e2f71a79b --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsGetResponse.verified.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class UnicornsGetResponse : IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// + /// Instantiates a new and sets the default values. + /// + public UnicornsGetResponse() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsGetResponse CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsGetResponse(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsRequestBuilder.verified.cs new file mode 100644 index 0000000000..77a44243cc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsRequestBuilder.verified.cs @@ -0,0 +1,101 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns +{ + /// + /// Builds and executes requests for operations under \unicorns + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class UnicornsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public UnicornsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/unicorns", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public UnicornsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/unicorns", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsUnicornsGetResponseAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsUnicornsGetResponseAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsGetResponse.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. + [Obsolete("This method is obsolete. Use GetAsUnicornsGetResponseAsync instead.")] +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsResponse.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class UnicornsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsResponse.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsResponse.verified.cs new file mode 100644 index 0000000000..164e95fe5e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/Unicorns/UnicornsResponse.verified.cs @@ -0,0 +1,28 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns +{ + [Obsolete("This class is obsolete. Use UnicornsGetResponse instead.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class UnicornsResponse : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsGetResponse, IParsable + #pragma warning restore CS1591 + { + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsResponse CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Unicorns.UnicornsResponse(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/ZipCodes/Validate/ValidateRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/ZipCodes/Validate/ValidateRequestBuilder.verified.cs new file mode 100644 index 0000000000..12d1ad9639 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/ZipCodes/Validate/ValidateRequestBuilder.verified.cs @@ -0,0 +1,108 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.Validate +{ + /// + /// Builds and executes requests for operations under \zip-codes\validate + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ValidateRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ValidateRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/zip-codes/validate?search={search}{&zipCodes*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ValidateRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/zip-codes/validate?search={search}{&zipCodes*}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.Validate.ValidateRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.Validate.ValidateRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ValidateRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("search")] + public string? Search { get; set; } +#nullable restore +#else + [QueryParameter("search")] + public string Search { get; set; } +#endif +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("zipCodes")] + public string[]? ZipCodes { get; set; } +#nullable restore +#else + [QueryParameter("zipCodes")] + public string[] ZipCodes { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ValidateRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/ZipCodes/ZipCodesRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/ZipCodes/ZipCodesRequestBuilder.verified.cs new file mode 100644 index 0000000000..0f128af863 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_c5d548b51ce098ba/ZipCodes/ZipCodesRequestBuilder.verified.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.Validate; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes +{ + /// + /// Builds and executes requests for operations under \zip-codes + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ZipCodesRequestBuilder : BaseRequestBuilder + { + /// The validate property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.Validate.ValidateRequestBuilder Validate + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.ZipCodes.Validate.ValidateRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ZipCodesRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/zip-codes", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ZipCodesRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/zip-codes", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_cd7f23bce481d107/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_cd7f23bce481d107/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..c38e859de8 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_cd7f23bce481d107/NSwagOpenApiClient.verified.cs @@ -0,0 +1,350 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = "http://localhost:57556/"; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAsync() + { + return ProductsAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d30b8d492860d9c9/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d30b8d492860d9c9/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..bcf2b1b61e --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d30b8d492860d9c9/NSwagOpenApiClient.verified.cs @@ -0,0 +1,436 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task EnumAsync(LogLevel? logLevel) + { + return EnumAsync(logLevel, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task EnumAsync(LogLevel? logLevel, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/Enum" + urlBuilder_.Append("api/Enum"); + urlBuilder_.Append('?'); + if (logLevel != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("logLevel")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(logLevel, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task RequiredEnumAsync(LogLevel logLevel) + { + return RequiredEnumAsync(logLevel, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task RequiredEnumAsync(LogLevel logLevel, System.Threading.CancellationToken cancellationToken) + { + if (logLevel == null) + throw new System.ArgumentNullException("logLevel"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "api/RequiredEnum" + urlBuilder_.Append("api/RequiredEnum"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("logLevel")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(logLevel, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum LogLevel + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + _3 = 3, + + _4 = 4, + + _5 = 5, + + _6 = 6, + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/ApiRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/ApiRequestBuilder.verified.cs new file mode 100644 index 0000000000..26c519e671 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/ApiRequestBuilder.verified.cs @@ -0,0 +1,47 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.EnumNamespace; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.RequiredEnum; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api +{ + /// + /// Builds and executes requests for operations under \api + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ApiRequestBuilder : BaseRequestBuilder + { + /// The Enum property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.EnumNamespace.EnumRequestBuilder Enum + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.EnumNamespace.EnumRequestBuilder(PathParameters, RequestAdapter); + } + /// The RequiredEnum property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.RequiredEnum.RequiredEnumRequestBuilder RequiredEnum + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.RequiredEnum.RequiredEnumRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ApiRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api", rawUrl) + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/EnumNamespace/EnumRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/EnumNamespace/EnumRequestBuilder.verified.cs new file mode 100644 index 0000000000..a214bf9719 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/EnumNamespace/EnumRequestBuilder.verified.cs @@ -0,0 +1,99 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.EnumNamespace +{ + /// + /// Builds and executes requests for operations under \api\Enum + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class EnumRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public EnumRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/Enum{?logLevel*}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public EnumRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/Enum{?logLevel*}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.EnumNamespace.EnumRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.EnumNamespace.EnumRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class EnumRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("logLevel")] + public string? LogLevel { get; set; } +#nullable restore +#else + [QueryParameter("logLevel")] + public string LogLevel { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class EnumRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/RequiredEnum/RequiredEnumRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/RequiredEnum/RequiredEnumRequestBuilder.verified.cs new file mode 100644 index 0000000000..3dfdde81dd --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/Api/RequiredEnum/RequiredEnumRequestBuilder.verified.cs @@ -0,0 +1,99 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.RequiredEnum +{ + /// + /// Builds and executes requests for operations under \api\RequiredEnum + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RequiredEnumRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public RequiredEnumRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/RequiredEnum?logLevel={logLevel}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public RequiredEnumRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/RequiredEnum?logLevel={logLevel}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.RequiredEnum.RequiredEnumRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.RequiredEnum.RequiredEnumRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class RequiredEnumRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("logLevel")] + public string? LogLevel { get; set; } +#nullable restore +#else + [QueryParameter("logLevel")] + public string LogLevel { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class RequiredEnumRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..f1c91cb638 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_d8671235c41dfbe0/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The api property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder Api + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Api.ApiRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_dde2647b4ed96daa/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_dde2647b4ed96daa/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..fd39c6bc34 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_dde2647b4ed96daa/NSwagOpenApiClient.verified.cs @@ -0,0 +1,645 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = "/resource-server"; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAllAsync() + { + return ProductsAllAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAllAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 401) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Unauthorized", status_, responseText_, headers_, null); + } + else + if (status_ == 403) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Forbidden", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsPOSTAsync(Product body) + { + return ProductsPOSTAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsPOSTAsync(Product body, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + if (status_ == 401) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Unauthorized", status_, responseText_, headers_, null); + } + else + if (status_ == 403) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Forbidden", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsGETAsync(int id) + { + return ProductsGETAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsGETAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products/{id}" + urlBuilder_.Append("products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + if (status_ == 401) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Unauthorized", status_, responseText_, headers_, null); + } + else + if (status_ == 403) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Forbidden", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task ProductsDELETEAsync(int id) + { + return ProductsDELETEAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task ProductsDELETEAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("DELETE"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products/{id}" + urlBuilder_.Append("products/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + if (status_ == 401) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Unauthorized", status_, responseText_, headers_, null); + } + else + if (status_ == 403) + { + string responseText_ = ( response_.Content == null ) ? string.Empty : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("Forbidden", status_, responseText_, headers_, null); + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("serialNo", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string SerialNo { get; set; } + + [Newtonsoft.Json.JsonProperty("status", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public ProductStatus Status { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum ProductStatus + { + + _0 = 0, + + _1 = 1, + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Animals/AnimalsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Animals/AnimalsRequestBuilder.verified.cs new file mode 100644 index 0000000000..7347f6f205 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Animals/AnimalsRequestBuilder.verified.cs @@ -0,0 +1,185 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals +{ + /// + /// Builds and executes requests for operations under \Animals + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AnimalsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public AnimalsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Animals", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public AnimalsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Animals", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder.AnimalsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder.AnimalsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder.AnimalsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder.AnimalsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Composed type wrapper for classes , , + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AnimalsPostRequestBody : IComposedTypeWrapper, IParsable + { + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Animal? Animal { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Animal Animal { get; set; } +#endif + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cat? Cat { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cat Cat { get; set; } +#endif + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Dog? Dog { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Dog Dog { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder.AnimalsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("animalType")?.GetStringValue(); + var result = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder.AnimalsPostRequestBody(); + if("".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.Animal = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Animal(); + } + else if("Cat".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.Cat = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cat(); + } + else if("Dog".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.Dog = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Dog(); + } + return result; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + if(Animal != null) + { + return Animal.GetFieldDeserializers(); + } + else if(Cat != null) + { + return Cat.GetFieldDeserializers(); + } + else if(Dog != null) + { + return Dog.GetFieldDeserializers(); + } + return new Dictionary>(); + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + if(Animal != null) + { + writer.WriteObjectValue(null, Animal); + } + else if(Cat != null) + { + writer.WriteObjectValue(null, Cat); + } + else if(Dog != null) + { + writer.WriteObjectValue(null, Dog); + } + } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class AnimalsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..1d33d61c09 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/KiotaOpenApiClient.verified.cs @@ -0,0 +1,61 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SecondLevel; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The Animals property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder Animals + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Animals.AnimalsRequestBuilder(PathParameters, RequestAdapter); + } + /// The SecondLevel property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SecondLevel.SecondLevelRequestBuilder SecondLevel + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SecondLevel.SecondLevelRequestBuilder(PathParameters, RequestAdapter); + } + /// The SystemTextJsonAnimals property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder SystemTextJsonAnimals + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder(PathParameters, RequestAdapter); + } + /// The SystemTextJsonDefaultDiscriminatorAnimals property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder SystemTextJsonDefaultDiscriminatorAnimals + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Animal.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Animal.verified.cs new file mode 100644 index 0000000000..3b792099e5 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Animal.verified.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Animal : IParsable + #pragma warning restore CS1591 + { + /// The animalType property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.AnimalType? AnimalType { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Animal CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("animalType")?.GetStringValue(); + return mappingValue switch + { + "Cat" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cat(), + "Dog" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Dog(), + _ => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Animal(), + }; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "animalType", n => { AnimalType = n.GetEnumValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteEnumValue("animalType", AnimalType); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/AnimalType.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/AnimalType.verified.cs new file mode 100644 index 0000000000..32e4d2d2ba --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/AnimalType.verified.cs @@ -0,0 +1,20 @@ +// +using System.Runtime.Serialization; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public enum AnimalType + #pragma warning restore CS1591 + { + [EnumMember(Value = "Cat")] + #pragma warning disable CS1591 + Cat, + #pragma warning restore CS1591 + [EnumMember(Value = "Dog")] + #pragma warning disable CS1591 + Dog, + #pragma warning restore CS1591 + } +} diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/BaseType.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/BaseType.verified.cs new file mode 100644 index 0000000000..6aecf467ed --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/BaseType.verified.cs @@ -0,0 +1,70 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class BaseType : IParsable + #pragma warning restore CS1591 + { + /// The discriminator property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Discriminator { get; set; } +#nullable restore +#else + public string Discriminator { get; set; } +#endif + /// The property property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Property { get; set; } +#nullable restore +#else + public string Property { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.BaseType CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("discriminator")?.GetStringValue(); + return mappingValue switch + { + "SubSubType" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SubSubType(), + _ => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.BaseType(), + }; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "discriminator", n => { Discriminator = n.GetStringValue(); } }, + { "property", n => { Property = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("discriminator", Discriminator); + writer.WriteStringValue("property", Property); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Cat.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Cat.verified.cs new file mode 100644 index 0000000000..b543db143c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Cat.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Cat : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Animal, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The catSpecificProperty property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CatSpecificProperty { get; set; } +#nullable restore +#else + public string CatSpecificProperty { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public Cat() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cat CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Cat(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "catSpecificProperty", n => { CatSpecificProperty = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("catSpecificProperty", CatSpecificProperty); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Dog.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Dog.verified.cs new file mode 100644 index 0000000000..27ded33c37 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/Dog.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Dog : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Animal, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The dogSpecificProperty property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? DogSpecificProperty { get; set; } +#nullable restore +#else + public string DogSpecificProperty { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public Dog() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Dog CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Dog(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "dogSpecificProperty", n => { DogSpecificProperty = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("dogSpecificProperty", DogSpecificProperty); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SubSubType.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SubSubType.verified.cs new file mode 100644 index 0000000000..1f0e7e3261 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SubSubType.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class SubSubType : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.BaseType, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The property2 property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Property2 { get; set; } +#nullable restore +#else + public string Property2 { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public SubSubType() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SubSubType CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SubSubType(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "property2", n => { Property2 = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("property2", Property2); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonAnimal.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonAnimal.verified.cs new file mode 100644 index 0000000000..0ccd4e00ed --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonAnimal.verified.cs @@ -0,0 +1,61 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class SystemTextJsonAnimal : IParsable + #pragma warning restore CS1591 + { + /// The animalType property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? AnimalType { get; set; } +#nullable restore +#else + public string AnimalType { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonAnimal CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("animalType")?.GetStringValue(); + return mappingValue switch + { + "Cat" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonCat(), + "Dog" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDog(), + _ => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonAnimal(), + }; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "animalType", n => { AnimalType = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("animalType", AnimalType); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonCat.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonCat.verified.cs new file mode 100644 index 0000000000..487bfccb5c --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonCat.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class SystemTextJsonCat : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonAnimal, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The catSpecificProperty property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CatSpecificProperty { get; set; } +#nullable restore +#else + public string CatSpecificProperty { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public SystemTextJsonCat() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonCat CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonCat(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "catSpecificProperty", n => { CatSpecificProperty = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("catSpecificProperty", CatSpecificProperty); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorAnimal.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorAnimal.verified.cs new file mode 100644 index 0000000000..5be70bae09 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorAnimal.verified.cs @@ -0,0 +1,71 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class SystemTextJsonDefaultDiscriminatorAnimal : IParsable + #pragma warning restore CS1591 + { + /// The animalType property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? AnimalType { get; set; } +#nullable restore +#else + public string AnimalType { get; set; } +#endif + /// The Type property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Type { get; set; } +#nullable restore +#else + public string Type { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorAnimal CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("$type")?.GetStringValue(); + return mappingValue switch + { + "Cat" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorCat(), + "Dog" => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorDog(), + _ => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorAnimal(), + }; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "animalType", n => { AnimalType = n.GetStringValue(); } }, + { "$type", n => { Type = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("animalType", AnimalType); + writer.WriteStringValue("$type", Type); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorCat.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorCat.verified.cs new file mode 100644 index 0000000000..e90be4a5fb --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorCat.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class SystemTextJsonDefaultDiscriminatorCat : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorAnimal, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The catSpecificProperty property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? CatSpecificProperty { get; set; } +#nullable restore +#else + public string CatSpecificProperty { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public SystemTextJsonDefaultDiscriminatorCat() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorCat CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorCat(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "catSpecificProperty", n => { CatSpecificProperty = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("catSpecificProperty", CatSpecificProperty); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorDog.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorDog.verified.cs new file mode 100644 index 0000000000..fe72a52723 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDefaultDiscriminatorDog.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class SystemTextJsonDefaultDiscriminatorDog : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorAnimal, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The dogSpecificProperty property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? DogSpecificProperty { get; set; } +#nullable restore +#else + public string DogSpecificProperty { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public SystemTextJsonDefaultDiscriminatorDog() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorDog CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorDog(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "dogSpecificProperty", n => { DogSpecificProperty = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("dogSpecificProperty", DogSpecificProperty); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDog.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDog.verified.cs new file mode 100644 index 0000000000..75bcc5d387 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/Models/SystemTextJsonDog.verified.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class SystemTextJsonDog : global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonAnimal, IAdditionalDataHolder, IParsable + #pragma warning restore CS1591 + { + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { get; set; } + /// The dogSpecificProperty property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? DogSpecificProperty { get; set; } +#nullable restore +#else + public string DogSpecificProperty { get; set; } +#endif + /// + /// Instantiates a new and sets the default values. + /// + public SystemTextJsonDog() : base() + { + AdditionalData = new Dictionary(); + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDog CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDog(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public override IDictionary> GetFieldDeserializers() + { + return new Dictionary>(base.GetFieldDeserializers()) + { + { "dogSpecificProperty", n => { DogSpecificProperty = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public override void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + base.Serialize(writer); + writer.WriteStringValue("dogSpecificProperty", DogSpecificProperty); + writer.WriteAdditionalData(AdditionalData); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SecondLevel/SecondLevelRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SecondLevel/SecondLevelRequestBuilder.verified.cs new file mode 100644 index 0000000000..46f7836857 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SecondLevel/SecondLevelRequestBuilder.verified.cs @@ -0,0 +1,91 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SecondLevel +{ + /// + /// Builds and executes requests for operations under \SecondLevel + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SecondLevelRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public SecondLevelRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/SecondLevel", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public SecondLevelRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/SecondLevel", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SubSubType body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SubSubType body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SubSubType body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SubSubType body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "application/json"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SecondLevel.SecondLevelRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SecondLevel.SecondLevelRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SecondLevelRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SystemTextJsonAnimals/SystemTextJsonAnimalsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SystemTextJsonAnimals/SystemTextJsonAnimalsRequestBuilder.verified.cs new file mode 100644 index 0000000000..e2ae00df7f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SystemTextJsonAnimals/SystemTextJsonAnimalsRequestBuilder.verified.cs @@ -0,0 +1,185 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals +{ + /// + /// Builds and executes requests for operations under \SystemTextJsonAnimals + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SystemTextJsonAnimalsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public SystemTextJsonAnimalsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/SystemTextJsonAnimals", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public SystemTextJsonAnimalsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/SystemTextJsonAnimals", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder.SystemTextJsonAnimalsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder.SystemTextJsonAnimalsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder.SystemTextJsonAnimalsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder.SystemTextJsonAnimalsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Composed type wrapper for classes , , + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SystemTextJsonAnimalsPostRequestBody : IComposedTypeWrapper, IParsable + { + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonAnimal? SystemTextJsonAnimal { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonAnimal SystemTextJsonAnimal { get; set; } +#endif + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonCat? SystemTextJsonCat { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonCat SystemTextJsonCat { get; set; } +#endif + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDog? SystemTextJsonDog { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDog SystemTextJsonDog { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder.SystemTextJsonAnimalsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("animalType")?.GetStringValue(); + var result = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonAnimals.SystemTextJsonAnimalsRequestBuilder.SystemTextJsonAnimalsPostRequestBody(); + if("".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.SystemTextJsonAnimal = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonAnimal(); + } + else if("Cat".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.SystemTextJsonCat = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonCat(); + } + else if("Dog".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.SystemTextJsonDog = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDog(); + } + return result; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + if(SystemTextJsonAnimal != null) + { + return SystemTextJsonAnimal.GetFieldDeserializers(); + } + else if(SystemTextJsonCat != null) + { + return SystemTextJsonCat.GetFieldDeserializers(); + } + else if(SystemTextJsonDog != null) + { + return SystemTextJsonDog.GetFieldDeserializers(); + } + return new Dictionary>(); + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + if(SystemTextJsonAnimal != null) + { + writer.WriteObjectValue(null, SystemTextJsonAnimal); + } + else if(SystemTextJsonCat != null) + { + writer.WriteObjectValue(null, SystemTextJsonCat); + } + else if(SystemTextJsonDog != null) + { + writer.WriteObjectValue(null, SystemTextJsonDog); + } + } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SystemTextJsonAnimalsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SystemTextJsonDefaultDiscriminatorAnimals/SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SystemTextJsonDefaultDiscriminatorAnimals/SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.verified.cs new file mode 100644 index 0000000000..004c2186fc --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_e697641459ecbe2d/SystemTextJsonDefaultDiscriminatorAnimals/SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.verified.cs @@ -0,0 +1,185 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals +{ + /// + /// Builds and executes requests for operations under \SystemTextJsonDefaultDiscriminatorAnimals + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/SystemTextJsonDefaultDiscriminatorAnimals", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/SystemTextJsonDefaultDiscriminatorAnimals", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.SystemTextJsonDefaultDiscriminatorAnimalsPostRequestBody body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.SystemTextJsonDefaultDiscriminatorAnimalsPostRequestBody body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.SystemTextJsonDefaultDiscriminatorAnimalsPostRequestBody body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.SystemTextJsonDefaultDiscriminatorAnimalsPostRequestBody body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Composed type wrapper for classes , , + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SystemTextJsonDefaultDiscriminatorAnimalsPostRequestBody : IComposedTypeWrapper, IParsable + { + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorAnimal? SystemTextJsonDefaultDiscriminatorAnimal { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorAnimal SystemTextJsonDefaultDiscriminatorAnimal { get; set; } +#endif + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorCat? SystemTextJsonDefaultDiscriminatorCat { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorCat SystemTextJsonDefaultDiscriminatorCat { get; set; } +#endif + /// Composed type representation for type +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorDog? SystemTextJsonDefaultDiscriminatorDog { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorDog SystemTextJsonDefaultDiscriminatorDog { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.SystemTextJsonDefaultDiscriminatorAnimalsPostRequestBody CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + var mappingValue = parseNode.GetChildNode("$type")?.GetStringValue(); + var result = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.SystemTextJsonDefaultDiscriminatorAnimals.SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilder.SystemTextJsonDefaultDiscriminatorAnimalsPostRequestBody(); + if("".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.SystemTextJsonDefaultDiscriminatorAnimal = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorAnimal(); + } + else if("Cat".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.SystemTextJsonDefaultDiscriminatorCat = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorCat(); + } + else if("Dog".Equals(mappingValue, StringComparison.OrdinalIgnoreCase)) + { + result.SystemTextJsonDefaultDiscriminatorDog = new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.SystemTextJsonDefaultDiscriminatorDog(); + } + return result; + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + if(SystemTextJsonDefaultDiscriminatorAnimal != null) + { + return SystemTextJsonDefaultDiscriminatorAnimal.GetFieldDeserializers(); + } + else if(SystemTextJsonDefaultDiscriminatorCat != null) + { + return SystemTextJsonDefaultDiscriminatorCat.GetFieldDeserializers(); + } + else if(SystemTextJsonDefaultDiscriminatorDog != null) + { + return SystemTextJsonDefaultDiscriminatorDog.GetFieldDeserializers(); + } + return new Dictionary>(); + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + if(SystemTextJsonDefaultDiscriminatorAnimal != null) + { + writer.WriteObjectValue(null, SystemTextJsonDefaultDiscriminatorAnimal); + } + else if(SystemTextJsonDefaultDiscriminatorCat != null) + { + writer.WriteObjectValue(null, SystemTextJsonDefaultDiscriminatorCat); + } + else if(SystemTextJsonDefaultDiscriminatorDog != null) + { + writer.WriteObjectValue(null, SystemTextJsonDefaultDiscriminatorDog); + } + } + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class SystemTextJsonDefaultDiscriminatorAnimalsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..c672df5e27 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The Products property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder Products + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Models/Product.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Models/Product.verified.cs new file mode 100644 index 0000000000..97de045e50 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Models/Product.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Product : IParsable + #pragma warning restore CS1591 + { + /// The description property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Description { get; set; } +#nullable restore +#else + public string Description { get; set; } +#endif + /// The id property + public int? Id { get; set; } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "description", n => { Description = n.GetStringValue(); } }, + { "id", n => { Id = n.GetIntValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("description", Description); + writer.WriteIntValue("id", Id); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Products/Item/ProductsItemRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Products/Item/ProductsItemRequestBuilder.verified.cs new file mode 100644 index 0000000000..a1092fb977 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Products/Item/ProductsItemRequestBuilder.verified.cs @@ -0,0 +1,158 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item +{ + /// + /// Builds and executes requests for operations under \Products\{id} + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Products/{id}?api-version={api%2Dversion}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsItemRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Products/{id}?api-version={api%2Dversion}", rawUrl) + { + } + /// A + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task DeleteAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task DeleteAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToDeleteRequestInformation(requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PutAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PutAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPutRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToDeleteRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToDeleteRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.DELETE, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + return requestInfo; + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPutRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPutRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.PUT, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProductsItemRequestBuilderDeleteQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("api%2Dversion")] + public string? ApiVersion { get; set; } +#nullable restore +#else + [QueryParameter("api%2Dversion")] + public string ApiVersion { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderDeleteRequestConfiguration : RequestConfiguration + { + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProductsItemRequestBuilderPutQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("api%2Dversion")] + public string? ApiVersion { get; set; } +#nullable restore +#else + [QueryParameter("api%2Dversion")] + public string ApiVersion { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsItemRequestBuilderPutRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Products/ProductsRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Products/ProductsRequestBuilder.verified.cs new file mode 100644 index 0000000000..5048027f5a --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_ef221d99380f04b3/Products/ProductsRequestBuilder.verified.cs @@ -0,0 +1,187 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products +{ + /// + /// Builds and executes requests for operations under \Products + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilder : BaseRequestBuilder + { + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.item collection + /// Unique identifier of the item + /// A + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[int position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// Gets an item from the Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.item collection + /// Unique identifier of the item + /// A + [Obsolete("This indexer is deprecated and will be removed in the next major version. Use the one with the typed parameter instead.")] + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder this[string position] + { + get + { + var urlTplParams = new Dictionary(PathParameters); + if (!string.IsNullOrWhiteSpace(position)) urlTplParams.Add("id", position); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.Item.ProductsItemRequestBuilder(urlTplParams, RequestAdapter); + } + } + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Products?api-version={api%2Dversion}", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public ProductsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/Products?api-version={api%2Dversion}", rawUrl) + { + } + /// A List<global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product> + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task?> GetAsync(Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task> GetAsync(Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + var requestInfo = ToGetRequestInformation(requestConfiguration); + var collectionResult = await RequestAdapter.SendCollectionAsync(requestInfo, global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false); + return collectionResult?.AsList(); + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task PostAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToPostRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(Action> requestConfiguration = default) + { +#endif + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + return requestInfo; + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToPostRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Product body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.POST, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.Headers.TryAdd("Accept", "text/plain;q=0.9"); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Products.ProductsRequestBuilder(rawUrl, RequestAdapter); + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProductsRequestBuilderGetQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("api%2Dversion")] + public string? ApiVersion { get; set; } +#nullable restore +#else + [QueryParameter("api%2Dversion")] + public string ApiVersion { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class ProductsRequestBuilderPostQueryParameters + #pragma warning restore CS1591 + { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + [QueryParameter("api%2Dversion")] + public string? ApiVersion { get; set; } +#nullable restore +#else + [QueryParameter("api%2Dversion")] + public string ApiVersion { get; set; } +#endif + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class ProductsRequestBuilderPostRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f2a4d1a266495eca/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f2a4d1a266495eca/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..795937b1e2 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f2a4d1a266495eca/NSwagOpenApiClient.verified.cs @@ -0,0 +1,2347 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// + /// CreateFruit + /// + /// + /// Create a fruit + /// + /// The id of the fruit that will be created + /// Description for Body + /// Description for response + /// A server side error occurred. + public virtual System.Threading.Tasks.Task FruitAsync(string id, Fruit body) + { + return FruitAsync(id, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// CreateFruit + /// + /// + /// Create a fruit + /// + /// The id of the fruit that will be created + /// Description for Body + /// Description for response + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task FruitAsync(string id, Fruit body, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/fruit/{id}" + urlBuilder_.Append("annotations/fruit/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description for FirstName + /// Description for LastName + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task SingleFormAsync(string firstName, string lastName) + { + return SingleFormAsync(firstName, lastName, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description for FirstName + /// Description for LastName + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task SingleFormAsync(string firstName, string lastName, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (firstName != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("firstName", ConvertToString(firstName, System.Globalization.CultureInfo.InvariantCulture))); + if (lastName != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("lastName", ConvertToString(lastName, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/singleForm" + urlBuilder_.Append("annotations/singleForm"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description for Street + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task MultipleFormsAsync(string street, string city, string state, string zipCode) + { + return MultipleFormsAsync(street, city, state, zipCode, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description for Street + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task MultipleFormsAsync(string street, string city, string state, string zipCode, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (street != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("street", ConvertToString(street, System.Globalization.CultureInfo.InvariantCulture))); + if (city != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("city", ConvertToString(city, System.Globalization.CultureInfo.InvariantCulture))); + if (state != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("state", ConvertToString(state, System.Globalization.CultureInfo.InvariantCulture))); + if (zipCode != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("zipCode", ConvertToString(zipCode, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/multipleForms" + urlBuilder_.Append("annotations/multipleForms"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description for File + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndStringAsync(FileParameter file, string tags) + { + return IFromFileAndStringAsync(file, tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description for File + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndStringAsync(FileParameter file, string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture)), "tags"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/IFromFileAndString" + urlBuilder_.Append("annotations/IFromFileAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndEnumAsync(FileParameter file, DateTimeKind? dateTimeKind) + { + return IFromFileAndEnumAsync(file, dateTimeKind, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndEnumAsync(FileParameter file, DateTimeKind? dateTimeKind, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (dateTimeKind == null) + throw new System.ArgumentNullException("dateTimeKind"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(dateTimeKind, System.Globalization.CultureInfo.InvariantCulture)), "dateTimeKind"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/IFromFileAndEnum" + urlBuilder_.Append("annotations/IFromFileAndEnum"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromObjectAndStringAsync(string tags) + { + return IFromObjectAndStringAsync(tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromObjectAndStringAsync(string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + keyValues_.Add(new System.Collections.Generic.KeyValuePair("tags", ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/IFromObjectAndString" + urlBuilder_.Append("annotations/IFromObjectAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task AsParametersAsync(System.Guid? paramOne, System.Guid paramTwo, System.DateTimeOffset? paramThree, System.DateTimeOffset paramFour, System.DateTimeOffset? paramFive, System.DateTimeOffset paramSix, System.TimeSpan? paramSeven, System.TimeSpan paramEight, DateTimeKind? paramNine, DateTimeKind paramTen, double? paramEleven, double paramTwelve) + { + return AsParametersAsync(paramOne, paramTwo, paramThree, paramFour, paramFive, paramSix, paramSeven, paramEight, paramNine, paramTen, paramEleven, paramTwelve, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task AsParametersAsync(System.Guid? paramOne, System.Guid paramTwo, System.DateTimeOffset? paramThree, System.DateTimeOffset paramFour, System.DateTimeOffset? paramFive, System.DateTimeOffset paramSix, System.TimeSpan? paramSeven, System.TimeSpan paramEight, DateTimeKind? paramNine, DateTimeKind paramTen, double? paramEleven, double paramTwelve, System.Threading.CancellationToken cancellationToken) + { + if (paramTwo == null) + throw new System.ArgumentNullException("paramTwo"); + + if (paramFour == null) + throw new System.ArgumentNullException("paramFour"); + + if (paramSix == null) + throw new System.ArgumentNullException("paramSix"); + + if (paramEight == null) + throw new System.ArgumentNullException("paramEight"); + + if (paramTen == null) + throw new System.ArgumentNullException("paramTen"); + + if (paramTwelve == null) + throw new System.ArgumentNullException("paramTwelve"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/AsParameters" + urlBuilder_.Append("annotations/AsParameters"); + urlBuilder_.Append('?'); + if (paramOne != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramOne")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramOne, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramTwo")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramTwo, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramThree != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramThree")).Append('=').Append(System.Uri.EscapeDataString(paramThree.Value.ToString("s", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramFour")).Append('=').Append(System.Uri.EscapeDataString(paramFour.ToString("s", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramFive != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramFive")).Append('=').Append(System.Uri.EscapeDataString(paramFive.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramSix")).Append('=').Append(System.Uri.EscapeDataString(paramSix.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramSeven != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramSeven")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramSeven, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramEight")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramEight, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramNine != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramNine")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramNine, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramTen")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramTen, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramEleven != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramEleven")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramEleven, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramTwelve")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramTwelve, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task TypeWithTryParseAsync(string tryParse) + { + return TypeWithTryParseAsync(tryParse, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task TypeWithTryParseAsync(string tryParse, System.Threading.CancellationToken cancellationToken) + { + if (tryParse == null) + throw new System.ArgumentNullException("tryParse"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "TypeWithTryParse/{tryParse}" + urlBuilder_.Append("TypeWithTryParse/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tryParse, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> GetWeatherForecastAsync() + { + return GetWeatherForecastAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> GetWeatherForecastAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/weatherforecast" + urlBuilder_.Append("WithOpenApi/weatherforecast"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task MultipleForms2Async(string street, string city, string state, string zipCode) + { + return MultipleForms2Async(street, city, state, zipCode, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task MultipleForms2Async(string street, string city, string state, string zipCode, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (street != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("street", ConvertToString(street, System.Globalization.CultureInfo.InvariantCulture))); + if (city != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("city", ConvertToString(city, System.Globalization.CultureInfo.InvariantCulture))); + if (state != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("state", ConvertToString(state, System.Globalization.CultureInfo.InvariantCulture))); + if (zipCode != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("zipCode", ConvertToString(zipCode, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/multipleForms" + urlBuilder_.Append("WithOpenApi/multipleForms"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAsync(string queryParameter, FileParameter file) + { + return IFromFileAsync(queryParameter, file, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAsync(string queryParameter, FileParameter file, System.Threading.CancellationToken cancellationToken) + { + if (queryParameter == null) + throw new System.ArgumentNullException("queryParameter"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFile" + urlBuilder_.Append("WithOpenApi/IFromFile"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("queryParameter")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(queryParameter, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileCollectionAsync(System.Collections.Generic.IEnumerable collection) + { + return IFromFileCollectionAsync(collection, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileCollectionAsync(System.Collections.Generic.IEnumerable collection, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (collection == null) + throw new System.ArgumentNullException("collection"); + else + { + foreach (var item_ in collection) + { + var content_collection_ = new System.Net.Http.StreamContent(item_.Data); + if (!string.IsNullOrEmpty(item_.ContentType)) + content_collection_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(item_.ContentType); + content_.Add(content_collection_, "collection", item_.FileName ?? "collection"); + } + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFileCollection" + urlBuilder_.Append("WithOpenApi/IFromFileCollection"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromBodyAsync(OrganizationCustomExchangeRatesDto body) + { + return IFromBodyAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromBodyAsync(OrganizationCustomExchangeRatesDto body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromBody" + urlBuilder_.Append("WithOpenApi/IFromBody"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndString2Async(FileParameter file, string tags) + { + return IFromFileAndString2Async(file, tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndString2Async(FileParameter file, string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture)), "tags"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFileAndString" + urlBuilder_.Append("WithOpenApi/IFromFileAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndEnum2Async(FileParameter file, DateTimeKind? dateTimeKind) + { + return IFromFileAndEnum2Async(file, dateTimeKind, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndEnum2Async(FileParameter file, DateTimeKind? dateTimeKind, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (dateTimeKind == null) + throw new System.ArgumentNullException("dateTimeKind"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(dateTimeKind, System.Globalization.CultureInfo.InvariantCulture)), "dateTimeKind"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFileAndEnum" + urlBuilder_.Append("WithOpenApi/IFromFileAndEnum"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromObjectAndString2Async(string tags) + { + return IFromObjectAndString2Async(tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromObjectAndString2Async(string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + keyValues_.Add(new System.Collections.Generic.KeyValuePair("tags", ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromObjectAndString" + urlBuilder_.Append("WithOpenApi/IFromObjectAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product + /// + /// The product id + /// A Product Id + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CarAsync(int id) + { + return CarAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product + /// + /// The product id + /// A Product Id + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CarAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/Car/{id}" + urlBuilder_.Append("XmlComments/Car/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product using asParameters record + /// + /// Uniquely identifies the product + /// Describes the product + /// A Product + /// A server side error occurred. + public virtual System.Threading.Tasks.Task Car2Async(int id, string description) + { + return Car2Async(id, description, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product using asParameters record + /// + /// Uniquely identifies the product + /// Describes the product + /// A Product + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task Car2Async(int id, string description, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/Car" + urlBuilder_.Append("XmlComments/Car"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("Id")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (description != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("Description")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(description, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product With Produces attribute + /// + /// A Product + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CarWithProducesAsync(int id) + { + return CarWithProducesAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product With Produces attribute + /// + /// A Product + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CarWithProducesAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/CarWithProduces" + urlBuilder_.Append("XmlComments/CarWithProduces"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("id")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CarWithProducesDefaultResponseTypeAsync(int id) + { + return CarWithProducesDefaultResponseTypeAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CarWithProducesDefaultResponseTypeAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/CarWithProducesDefaultResponseType" + urlBuilder_.Append("XmlComments/CarWithProducesDefaultResponseType"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("id")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("A Product", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Address + { + + [Newtonsoft.Json.JsonProperty("street", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Street { get; set; } + + [Newtonsoft.Json.JsonProperty("city", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string City { get; set; } + + [Newtonsoft.Json.JsonProperty("state", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string State { get; set; } + + [Newtonsoft.Json.JsonProperty("zipCode", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ZipCode { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddressAnnotated + { + + /// + /// Description for Street + /// + [Newtonsoft.Json.JsonProperty("street", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Street { get; set; } + + [Newtonsoft.Json.JsonProperty("city", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string City { get; set; } + + [Newtonsoft.Json.JsonProperty("state", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string State { get; set; } + + [Newtonsoft.Json.JsonProperty("zipCode", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ZipCode { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AsParametersRecord + { + + [Newtonsoft.Json.JsonProperty("paramOne", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid? ParamOne { get; set; } + + [Newtonsoft.Json.JsonProperty("paramTwo", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ParamTwo { get; set; } + + [Newtonsoft.Json.JsonProperty("paramThree", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset? ParamThree { get; set; } + + [Newtonsoft.Json.JsonProperty("paramFour", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset ParamFour { get; set; } + + [Newtonsoft.Json.JsonProperty("paramFive", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))] + public System.DateTimeOffset? ParamFive { get; set; } + + [Newtonsoft.Json.JsonProperty("paramSix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))] + public System.DateTimeOffset ParamSix { get; set; } + + [Newtonsoft.Json.JsonProperty("paramSeven", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.TimeSpan? ParamSeven { get; set; } + + [Newtonsoft.Json.JsonProperty("paramEight", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.TimeSpan ParamEight { get; set; } + + [Newtonsoft.Json.JsonProperty("paramNine", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public DateTimeKind ParamNine { get; set; } + + [Newtonsoft.Json.JsonProperty("paramTen", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public DateTimeKind ParamTen { get; set; } + + [Newtonsoft.Json.JsonProperty("paramEleven", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double? ParamEleven { get; set; } + + [Newtonsoft.Json.JsonProperty("paramTwelve", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double ParamTwelve { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class CurrenciesRate + { + + /// + /// Currency From + /// + [Newtonsoft.Json.JsonProperty("currencyFrom", Required = Newtonsoft.Json.Required.AllowNull)] + public string CurrencyFrom { get; set; } + + [Newtonsoft.Json.JsonProperty("currencyTo", Required = Newtonsoft.Json.Required.AllowNull)] + public string CurrencyTo { get; set; } + + [Newtonsoft.Json.JsonProperty("rate", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double Rate { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum DateTimeKind + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + /// + /// Description for Schema + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Fruit + { + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class OrganizationCustomExchangeRatesDto + { + + [Newtonsoft.Json.JsonProperty("currenciesRates", Required = Newtonsoft.Json.Required.AllowNull)] + public System.Collections.Generic.ICollection CurrenciesRates { get; set; } + + [Newtonsoft.Json.JsonProperty("isUpdated", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool IsUpdated { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Person + { + + [Newtonsoft.Json.JsonProperty("firstName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string FirstName { get; set; } + + [Newtonsoft.Json.JsonProperty("lastName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string LastName { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class PersonAnnotated + { + + /// + /// Description for FirstName + /// + [Newtonsoft.Json.JsonProperty("firstName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string FirstName { get; set; } + + /// + /// Description for LastName + /// + [Newtonsoft.Json.JsonProperty("lastName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string LastName { get; set; } + + } + + /// + /// Represents a product + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + /// + /// Uniquely identifies the product + /// + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + /// + /// Describes the product + /// + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class WeatherForecast + { + + [Newtonsoft.Json.JsonProperty("date", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))] + public System.DateTimeOffset Date { get; set; } + + [Newtonsoft.Json.JsonProperty("temperatureC", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int TemperatureC { get; set; } + + [Newtonsoft.Json.JsonProperty("summary", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Summary { get; set; } + + [Newtonsoft.Json.JsonProperty("temperatureF", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int TemperatureF { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter + { + public DateFormatConverter() + { + DateTimeFormat = "yyyy-MM-dd"; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class FileParameter + { + public FileParameter(System.IO.Stream data) + : this (data, null, null) + { + } + + public FileParameter(System.IO.Stream data, string fileName) + : this (data, fileName, null) + { + } + + public FileParameter(System.IO.Stream data, string fileName, string contentType) + { + Data = data; + FileName = fileName; + ContentType = contentType; + } + + public System.IO.Stream Data { get; private set; } + + public string FileName { get; private set; } + + public string ContentType { get; private set; } + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f6775c4367939921/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f6775c4367939921/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..25296f73c5 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f6775c4367939921/NSwagOpenApiClient.verified.cs @@ -0,0 +1,350 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> ProductsAsync() + { + return ProductsAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> ProductsAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "products" + urlBuilder_.Append("products"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f7cb563c23f74db2/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f7cb563c23f74db2/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..795937b1e2 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f7cb563c23f74db2/NSwagOpenApiClient.verified.cs @@ -0,0 +1,2347 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// + /// CreateFruit + /// + /// + /// Create a fruit + /// + /// The id of the fruit that will be created + /// Description for Body + /// Description for response + /// A server side error occurred. + public virtual System.Threading.Tasks.Task FruitAsync(string id, Fruit body) + { + return FruitAsync(id, body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// CreateFruit + /// + /// + /// Create a fruit + /// + /// The id of the fruit that will be created + /// Description for Body + /// Description for response + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task FruitAsync(string id, Fruit body, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/fruit/{id}" + urlBuilder_.Append("annotations/fruit/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description for FirstName + /// Description for LastName + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task SingleFormAsync(string firstName, string lastName) + { + return SingleFormAsync(firstName, lastName, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description for FirstName + /// Description for LastName + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task SingleFormAsync(string firstName, string lastName, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (firstName != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("firstName", ConvertToString(firstName, System.Globalization.CultureInfo.InvariantCulture))); + if (lastName != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("lastName", ConvertToString(lastName, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/singleForm" + urlBuilder_.Append("annotations/singleForm"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description for Street + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task MultipleFormsAsync(string street, string city, string state, string zipCode) + { + return MultipleFormsAsync(street, city, state, zipCode, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description for Street + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task MultipleFormsAsync(string street, string city, string state, string zipCode, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (street != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("street", ConvertToString(street, System.Globalization.CultureInfo.InvariantCulture))); + if (city != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("city", ConvertToString(city, System.Globalization.CultureInfo.InvariantCulture))); + if (state != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("state", ConvertToString(state, System.Globalization.CultureInfo.InvariantCulture))); + if (zipCode != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("zipCode", ConvertToString(zipCode, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/multipleForms" + urlBuilder_.Append("annotations/multipleForms"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description for File + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndStringAsync(FileParameter file, string tags) + { + return IFromFileAndStringAsync(file, tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description for File + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndStringAsync(FileParameter file, string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture)), "tags"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/IFromFileAndString" + urlBuilder_.Append("annotations/IFromFileAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndEnumAsync(FileParameter file, DateTimeKind? dateTimeKind) + { + return IFromFileAndEnumAsync(file, dateTimeKind, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndEnumAsync(FileParameter file, DateTimeKind? dateTimeKind, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (dateTimeKind == null) + throw new System.ArgumentNullException("dateTimeKind"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(dateTimeKind, System.Globalization.CultureInfo.InvariantCulture)), "dateTimeKind"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/IFromFileAndEnum" + urlBuilder_.Append("annotations/IFromFileAndEnum"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromObjectAndStringAsync(string tags) + { + return IFromObjectAndStringAsync(tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromObjectAndStringAsync(string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + keyValues_.Add(new System.Collections.Generic.KeyValuePair("tags", ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/IFromObjectAndString" + urlBuilder_.Append("annotations/IFromObjectAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// Description + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task AsParametersAsync(System.Guid? paramOne, System.Guid paramTwo, System.DateTimeOffset? paramThree, System.DateTimeOffset paramFour, System.DateTimeOffset? paramFive, System.DateTimeOffset paramSix, System.TimeSpan? paramSeven, System.TimeSpan paramEight, DateTimeKind? paramNine, DateTimeKind paramTen, double? paramEleven, double paramTwelve) + { + return AsParametersAsync(paramOne, paramTwo, paramThree, paramFour, paramFive, paramSix, paramSeven, paramEight, paramNine, paramTen, paramEleven, paramTwelve, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Description + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task AsParametersAsync(System.Guid? paramOne, System.Guid paramTwo, System.DateTimeOffset? paramThree, System.DateTimeOffset paramFour, System.DateTimeOffset? paramFive, System.DateTimeOffset paramSix, System.TimeSpan? paramSeven, System.TimeSpan paramEight, DateTimeKind? paramNine, DateTimeKind paramTen, double? paramEleven, double paramTwelve, System.Threading.CancellationToken cancellationToken) + { + if (paramTwo == null) + throw new System.ArgumentNullException("paramTwo"); + + if (paramFour == null) + throw new System.ArgumentNullException("paramFour"); + + if (paramSix == null) + throw new System.ArgumentNullException("paramSix"); + + if (paramEight == null) + throw new System.ArgumentNullException("paramEight"); + + if (paramTen == null) + throw new System.ArgumentNullException("paramTen"); + + if (paramTwelve == null) + throw new System.ArgumentNullException("paramTwelve"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "annotations/AsParameters" + urlBuilder_.Append("annotations/AsParameters"); + urlBuilder_.Append('?'); + if (paramOne != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramOne")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramOne, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramTwo")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramTwo, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramThree != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramThree")).Append('=').Append(System.Uri.EscapeDataString(paramThree.Value.ToString("s", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramFour")).Append('=').Append(System.Uri.EscapeDataString(paramFour.ToString("s", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramFive != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramFive")).Append('=').Append(System.Uri.EscapeDataString(paramFive.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramSix")).Append('=').Append(System.Uri.EscapeDataString(paramSix.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramSeven != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramSeven")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramSeven, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramEight")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramEight, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramNine != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramNine")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramNine, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramTen")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramTen, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (paramEleven != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("paramEleven")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramEleven, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Append(System.Uri.EscapeDataString("paramTwelve")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(paramTwelve, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task TypeWithTryParseAsync(string tryParse) + { + return TypeWithTryParseAsync(tryParse, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task TypeWithTryParseAsync(string tryParse, System.Threading.CancellationToken cancellationToken) + { + if (tryParse == null) + throw new System.ArgumentNullException("tryParse"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "TypeWithTryParse/{tryParse}" + urlBuilder_.Append("TypeWithTryParse/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(tryParse, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> GetWeatherForecastAsync() + { + return GetWeatherForecastAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> GetWeatherForecastAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/weatherforecast" + urlBuilder_.Append("WithOpenApi/weatherforecast"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task MultipleForms2Async(string street, string city, string state, string zipCode) + { + return MultipleForms2Async(street, city, state, zipCode, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task MultipleForms2Async(string street, string city, string state, string zipCode, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (street != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("street", ConvertToString(street, System.Globalization.CultureInfo.InvariantCulture))); + if (city != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("city", ConvertToString(city, System.Globalization.CultureInfo.InvariantCulture))); + if (state != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("state", ConvertToString(state, System.Globalization.CultureInfo.InvariantCulture))); + if (zipCode != null) + keyValues_.Add(new System.Collections.Generic.KeyValuePair("zipCode", ConvertToString(zipCode, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/multipleForms" + urlBuilder_.Append("WithOpenApi/multipleForms"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAsync(string queryParameter, FileParameter file) + { + return IFromFileAsync(queryParameter, file, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAsync(string queryParameter, FileParameter file, System.Threading.CancellationToken cancellationToken) + { + if (queryParameter == null) + throw new System.ArgumentNullException("queryParameter"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFile" + urlBuilder_.Append("WithOpenApi/IFromFile"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("queryParameter")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(queryParameter, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileCollectionAsync(System.Collections.Generic.IEnumerable collection) + { + return IFromFileCollectionAsync(collection, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileCollectionAsync(System.Collections.Generic.IEnumerable collection, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (collection == null) + throw new System.ArgumentNullException("collection"); + else + { + foreach (var item_ in collection) + { + var content_collection_ = new System.Net.Http.StreamContent(item_.Data); + if (!string.IsNullOrEmpty(item_.ContentType)) + content_collection_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(item_.ContentType); + content_.Add(content_collection_, "collection", item_.FileName ?? "collection"); + } + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFileCollection" + urlBuilder_.Append("WithOpenApi/IFromFileCollection"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromBodyAsync(OrganizationCustomExchangeRatesDto body) + { + return IFromBodyAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromBodyAsync(OrganizationCustomExchangeRatesDto body, System.Threading.CancellationToken cancellationToken) + { + if (body == null) + throw new System.ArgumentNullException("body"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, JsonSerializerSettings); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromBody" + urlBuilder_.Append("WithOpenApi/IFromBody"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndString2Async(FileParameter file, string tags) + { + return IFromFileAndString2Async(file, tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndString2Async(FileParameter file, string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture)), "tags"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFileAndString" + urlBuilder_.Append("WithOpenApi/IFromFileAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromFileAndEnum2Async(FileParameter file, DateTimeKind? dateTimeKind) + { + return IFromFileAndEnum2Async(file, dateTimeKind, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromFileAndEnum2Async(FileParameter file, DateTimeKind? dateTimeKind, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var boundary_ = System.Guid.NewGuid().ToString(); + var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); + content_.Headers.Remove("Content-Type"); + content_.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary_); + + if (file == null) + throw new System.ArgumentNullException("file"); + else + { + var content_file_ = new System.Net.Http.StreamContent(file.Data); + if (!string.IsNullOrEmpty(file.ContentType)) + content_file_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType); + content_.Add(content_file_, "file", file.FileName ?? "file"); + } + + if (dateTimeKind == null) + throw new System.ArgumentNullException("dateTimeKind"); + else + { + content_.Add(new System.Net.Http.StringContent(ConvertToString(dateTimeKind, System.Globalization.CultureInfo.InvariantCulture)), "dateTimeKind"); + } + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromFileAndEnum" + urlBuilder_.Append("WithOpenApi/IFromFileAndEnum"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task IFromObjectAndString2Async(string tags) + { + return IFromObjectAndString2Async(tags, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task IFromObjectAndString2Async(string tags, System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + var keyValues_ = new System.Collections.Generic.List>(); + if (tags == null) + throw new System.ArgumentNullException("tags"); + else + keyValues_.Add(new System.Collections.Generic.KeyValuePair("tags", ConvertToString(tags, System.Globalization.CultureInfo.InvariantCulture))); + request_.Content = new System.Net.Http.FormUrlEncodedContent(keyValues_); + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "WithOpenApi/IFromObjectAndString" + urlBuilder_.Append("WithOpenApi/IFromObjectAndString"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string)); + return result_; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product + /// + /// The product id + /// A Product Id + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CarAsync(int id) + { + return CarAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product + /// + /// The product id + /// A Product Id + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CarAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/Car/{id}" + urlBuilder_.Append("XmlComments/Car/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product using asParameters record + /// + /// Uniquely identifies the product + /// Describes the product + /// A Product + /// A server side error occurred. + public virtual System.Threading.Tasks.Task Car2Async(int id, string description) + { + return Car2Async(id, description, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product using asParameters record + /// + /// Uniquely identifies the product + /// Describes the product + /// A Product + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task Car2Async(int id, string description, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/Car" + urlBuilder_.Append("XmlComments/Car"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("Id")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + if (description != null) + { + urlBuilder_.Append(System.Uri.EscapeDataString("Description")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(description, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + } + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product With Produces attribute + /// + /// A Product + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CarWithProducesAsync(int id) + { + return CarWithProducesAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product With Produces attribute + /// + /// A Product + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CarWithProducesAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/CarWithProduces" + urlBuilder_.Append("XmlComments/CarWithProduces"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("id")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task CarWithProducesDefaultResponseTypeAsync(int id) + { + return CarWithProducesDefaultResponseTypeAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns a specific product With ProducesDefaultResponseType attribute + /// + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task CarWithProducesDefaultResponseTypeAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "XmlComments/CarWithProducesDefaultResponseType" + urlBuilder_.Append("XmlComments/CarWithProducesDefaultResponseType"); + urlBuilder_.Append('?'); + urlBuilder_.Append(System.Uri.EscapeDataString("id")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); + urlBuilder_.Length--; + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + throw new ApiException("A Product", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Address + { + + [Newtonsoft.Json.JsonProperty("street", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Street { get; set; } + + [Newtonsoft.Json.JsonProperty("city", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string City { get; set; } + + [Newtonsoft.Json.JsonProperty("state", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string State { get; set; } + + [Newtonsoft.Json.JsonProperty("zipCode", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ZipCode { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AddressAnnotated + { + + /// + /// Description for Street + /// + [Newtonsoft.Json.JsonProperty("street", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Street { get; set; } + + [Newtonsoft.Json.JsonProperty("city", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string City { get; set; } + + [Newtonsoft.Json.JsonProperty("state", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string State { get; set; } + + [Newtonsoft.Json.JsonProperty("zipCode", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string ZipCode { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class AsParametersRecord + { + + [Newtonsoft.Json.JsonProperty("paramOne", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid? ParamOne { get; set; } + + [Newtonsoft.Json.JsonProperty("paramTwo", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid ParamTwo { get; set; } + + [Newtonsoft.Json.JsonProperty("paramThree", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset? ParamThree { get; set; } + + [Newtonsoft.Json.JsonProperty("paramFour", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.DateTimeOffset ParamFour { get; set; } + + [Newtonsoft.Json.JsonProperty("paramFive", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))] + public System.DateTimeOffset? ParamFive { get; set; } + + [Newtonsoft.Json.JsonProperty("paramSix", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))] + public System.DateTimeOffset ParamSix { get; set; } + + [Newtonsoft.Json.JsonProperty("paramSeven", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.TimeSpan? ParamSeven { get; set; } + + [Newtonsoft.Json.JsonProperty("paramEight", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.TimeSpan ParamEight { get; set; } + + [Newtonsoft.Json.JsonProperty("paramNine", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public DateTimeKind ParamNine { get; set; } + + [Newtonsoft.Json.JsonProperty("paramTen", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public DateTimeKind ParamTen { get; set; } + + [Newtonsoft.Json.JsonProperty("paramEleven", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double? ParamEleven { get; set; } + + [Newtonsoft.Json.JsonProperty("paramTwelve", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double ParamTwelve { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class CurrenciesRate + { + + /// + /// Currency From + /// + [Newtonsoft.Json.JsonProperty("currencyFrom", Required = Newtonsoft.Json.Required.AllowNull)] + public string CurrencyFrom { get; set; } + + [Newtonsoft.Json.JsonProperty("currencyTo", Required = Newtonsoft.Json.Required.AllowNull)] + public string CurrencyTo { get; set; } + + [Newtonsoft.Json.JsonProperty("rate", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public double Rate { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public enum DateTimeKind + { + + _0 = 0, + + _1 = 1, + + _2 = 2, + + } + + /// + /// Description for Schema + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Fruit + { + + [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Name { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class OrganizationCustomExchangeRatesDto + { + + [Newtonsoft.Json.JsonProperty("currenciesRates", Required = Newtonsoft.Json.Required.AllowNull)] + public System.Collections.Generic.ICollection CurrenciesRates { get; set; } + + [Newtonsoft.Json.JsonProperty("isUpdated", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool IsUpdated { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Person + { + + [Newtonsoft.Json.JsonProperty("firstName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string FirstName { get; set; } + + [Newtonsoft.Json.JsonProperty("lastName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string LastName { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class PersonAnnotated + { + + /// + /// Description for FirstName + /// + [Newtonsoft.Json.JsonProperty("firstName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string FirstName { get; set; } + + /// + /// Description for LastName + /// + [Newtonsoft.Json.JsonProperty("lastName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string LastName { get; set; } + + } + + /// + /// Represents a product + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Product + { + + /// + /// Uniquely identifies the product + /// + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + /// + /// Describes the product + /// + [Newtonsoft.Json.JsonProperty("description", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Description { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class WeatherForecast + { + + [Newtonsoft.Json.JsonProperty("date", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))] + public System.DateTimeOffset Date { get; set; } + + [Newtonsoft.Json.JsonProperty("temperatureC", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int TemperatureC { get; set; } + + [Newtonsoft.Json.JsonProperty("summary", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Summary { get; set; } + + [Newtonsoft.Json.JsonProperty("temperatureF", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int TemperatureF { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter + { + public DateFormatConverter() + { + DateTimeFormat = "yyyy-MM-dd"; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class FileParameter + { + public FileParameter(System.IO.Stream data) + : this (data, null, null) + { + } + + public FileParameter(System.IO.Stream data, string fileName) + : this (data, fileName, null) + { + } + + public FileParameter(System.IO.Stream data, string fileName, string contentType) + { + Data = data; + FileName = fileName; + ContentType = contentType; + } + + public System.IO.Stream Data { get; private set; } + + public string FileName { get; private set; } + + public string ContentType { get; private set; } + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f93b96252989bd4b/NSwagOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f93b96252989bd4b/NSwagOpenApiClient.verified.cs new file mode 100644 index 0000000000..86defb12b5 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_f93b96252989bd4b/NSwagOpenApiClient.verified.cs @@ -0,0 +1,442 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 649 // Disable "CS0649 Field is never assigned to, and will always have its default value null" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8600 // Disable "CS8600 Converting null literal or possible null value to non-nullable type" +#pragma warning disable 8602 // Disable "CS8602 Dereference of a possibly null reference" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" +#pragma warning disable 8604 // Disable "CS8604 Possible null reference argument for parameter" +#pragma warning disable 8625 // Disable "CS8625 Cannot convert null literal to non-nullable reference type" +#pragma warning disable 8765 // Disable "CS8765 Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes)." + +namespace Swashbuckle.AspNetCore.IntegrationTests.NSwagTests +{ + using System = global::System; + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class NSwagOpenApiClient + { + #pragma warning disable 8618 + private string _baseUrl; + #pragma warning restore 8618 + + private System.Net.Http.HttpClient _httpClient; + private static System.Lazy _settings = new System.Lazy(CreateSerializerSettings, true); + private Newtonsoft.Json.JsonSerializerSettings _instanceSettings; + + #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + public NSwagOpenApiClient(string baseUrl, System.Net.Http.HttpClient httpClient) + #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + { + BaseUrl = baseUrl; + _httpClient = httpClient; + Initialize(); + } + + private static Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() + { + var settings = new Newtonsoft.Json.JsonSerializerSettings(); + UpdateJsonSerializerSettings(settings); + return settings; + } + + public string BaseUrl + { + get { return _baseUrl; } + set + { + _baseUrl = value; + if (!string.IsNullOrEmpty(_baseUrl) && !_baseUrl.EndsWith("/")) + _baseUrl += '/'; + } + } + + protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings.Value; } } + + static partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings); + + partial void Initialize(); + + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url); + partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder); + partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response); + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task> TodosAllAsync() + { + return TodosAllAsync(System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task> TodosAllAsync(System.Threading.CancellationToken cancellationToken) + { + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "todos" + urlBuilder_.Append("todos"); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync>(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + /// OK + /// A server side error occurred. + public virtual System.Threading.Tasks.Task TodosAsync(int id) + { + return TodosAsync(id, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// OK + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task TodosAsync(int id, System.Threading.CancellationToken cancellationToken) + { + if (id == null) + throw new System.ArgumentNullException("id"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = new System.Net.Http.HttpRequestMessage()) + { + request_.Method = new System.Net.Http.HttpMethod("GET"); + + var urlBuilder_ = new System.Text.StringBuilder(); + if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl); + // Operation Path: "todos/{id}" + urlBuilder_.Append("todos/"); + urlBuilder_.Append(System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = new System.Collections.Generic.Dictionary>(); + foreach (var item_ in response_.Headers) + headers_[item_.Key] = item_.Value; + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + return; + } + else + { + var responseData_ = response_.Content == null ? null : await ReadAsStringAsync(response_.Content, cancellationToken).ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + + protected struct ObjectResponseResult + { + public ObjectResponseResult(T responseObject, string responseText) + { + this.Object = responseObject; + this.Text = responseText; + } + + public T Object { get; } + + public string Text { get; } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStringAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStringAsync(cancellationToken); + #else + return content.ReadAsStringAsync(); + #endif + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + private static System.Threading.Tasks.Task ReadAsStreamAsync(System.Net.Http.HttpContent content, System.Threading.CancellationToken cancellationToken) + { + #if NET5_0_OR_GREATER + return content.ReadAsStreamAsync(cancellationToken); + #else + return content.ReadAsStreamAsync(); + #endif + } + + public bool ReadResponseAsString { get; set; } + + protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) + { + if (response == null || response.Content == null) + { + return new ObjectResponseResult(default(T), string.Empty); + } + + if (ReadResponseAsString) + { + var responseText = await ReadAsStringAsync(response.Content, cancellationToken).ConfigureAwait(false); + try + { + var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject(responseText, JsonSerializerSettings); + return new ObjectResponseResult(typedBody, responseText); + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await ReadAsStreamAsync(response.Content, cancellationToken).ConfigureAwait(false)) + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); + return new ObjectResponseResult(typedBody, string.Empty); + } + } + catch (Newtonsoft.Json.JsonException exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } + } + + private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo) + { + if (value == null) + { + return ""; + } + + if (value is System.Enum) + { + var name = System.Enum.GetName(value.GetType(), value); + if (name != null) + { + var field_ = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name); + if (field_ != null) + { + var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field_, typeof(System.Runtime.Serialization.EnumMemberAttribute)) + as System.Runtime.Serialization.EnumMemberAttribute; + if (attribute != null) + { + return attribute.Value != null ? attribute.Value : name; + } + } + + var converted = System.Convert.ToString(System.Convert.ChangeType(value, System.Enum.GetUnderlyingType(value.GetType()), cultureInfo)); + return converted == null ? string.Empty : converted; + } + } + else if (value is bool) + { + return System.Convert.ToString((bool)value, cultureInfo).ToLowerInvariant(); + } + else if (value is byte[]) + { + return System.Convert.ToBase64String((byte[]) value); + } + else if (value is string[]) + { + return string.Join(",", (string[])value); + } + else if (value.GetType().IsArray) + { + var valueArray = (System.Array)value; + var valueTextArray = new string[valueArray.Length]; + for (var i = 0; i < valueArray.Length; i++) + { + valueTextArray[i] = ConvertToString(valueArray.GetValue(i), cultureInfo); + } + return string.Join(",", valueTextArray); + } + + var result = System.Convert.ToString(value, cultureInfo); + return result == null ? "" : result; + } + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Todo + { + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public int Id { get; set; } + + [Newtonsoft.Json.JsonProperty("title", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Title { get; set; } + + [Newtonsoft.Json.JsonProperty("dueBy", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))] + public System.DateTimeOffset? DueBy { get; set; } + + [Newtonsoft.Json.JsonProperty("isComplete", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool IsComplete { get; set; } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + internal class DateFormatConverter : Newtonsoft.Json.Converters.IsoDateTimeConverter + { + public DateFormatConverter() + { + DateTimeFormat = "yyyy-MM-dd"; + } + } + + + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : System.Exception + { + public int StatusCode { get; private set; } + + public string Response { get; private set; } + + public System.Collections.Generic.IReadOnlyDictionary> Headers { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Exception innerException) + : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException) + { + StatusCode = statusCode; + Response = response; + Headers = headers; + } + + public override string ToString() + { + return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString()); + } + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.6.3.0 (NJsonSchema v11.5.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class ApiException : ApiException + { + public TResult Result { get; private set; } + + public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary> headers, TResult result, System.Exception innerException) + : base(message, statusCode, response, headers, innerException) + { + Result = result; + } + } + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 649 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8600 +#pragma warning restore 8602 +#pragma warning restore 8603 +#pragma warning restore 8604 +#pragma warning restore 8625 +#pragma warning restore 8765 \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/KiotaOpenApiClient.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/KiotaOpenApiClient.verified.cs new file mode 100644 index 0000000000..829aa7a776 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/KiotaOpenApiClient.verified.cs @@ -0,0 +1,43 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions; +using Microsoft.Kiota.Serialization.Form; +using Microsoft.Kiota.Serialization.Json; +using Microsoft.Kiota.Serialization.Multipart; +using Microsoft.Kiota.Serialization.Text; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Weatherforecast; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests +{ + /// + /// The main entry point of the SDK, exposes the configuration and the fluent API. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class KiotaOpenApiClient : BaseRequestBuilder + { + /// The weatherforecast property + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Weatherforecast.WeatherforecastRequestBuilder Weatherforecast + { + get => new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Weatherforecast.WeatherforecastRequestBuilder(PathParameters, RequestAdapter); + } + /// + /// Instantiates a new and sets the default values. + /// + /// The request adapter to use to execute the requests. + public KiotaOpenApiClient(IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}", new Dictionary()) + { + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultSerializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + ApiClientBuilder.RegisterDefaultDeserializer(); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Models/Child.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Models/Child.verified.cs new file mode 100644 index 0000000000..bb075a8ff9 --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Models/Child.verified.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Child : IParsable + #pragma warning restore CS1591 + { + /// The name property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? Name { get; set; } +#nullable restore +#else + public string Name { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Child CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Child(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "name", n => { Name = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("name", Name); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Models/Parent.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Models/Parent.verified.cs new file mode 100644 index 0000000000..4405ca15fe --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Models/Parent.verified.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using System.Collections.Generic; +using System.IO; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models +{ + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + #pragma warning disable CS1591 + public partial class Parent : IParsable + #pragma warning restore CS1591 + { + /// The category property + public int? Category { get; set; } + /// The child property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Child? Child { get; set; } +#nullable restore +#else + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Child Child { get; set; } +#endif + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// A + /// The parse node to use to read the discriminator value and create the object + public static global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Parent CreateFromDiscriminatorValue(IParseNode parseNode) + { + if(ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode)); + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Parent(); + } + /// + /// The deserialization information for the current model + /// + /// A IDictionary<string, Action<IParseNode>> + public virtual IDictionary> GetFieldDeserializers() + { + return new Dictionary> + { + { "category", n => { Category = n.GetIntValue(); } }, + { "child", n => { Child = n.GetObjectValue(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Child.CreateFromDiscriminatorValue); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public virtual void Serialize(ISerializationWriter writer) + { + if(ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer)); + writer.WriteIntValue("category", Category); + writer.WriteObjectValue("child", Child); + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Weatherforecast/WeatherforecastRequestBuilder.verified.cs b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Weatherforecast/WeatherforecastRequestBuilder.verified.cs new file mode 100644 index 0000000000..49d9856bcf --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/GeneratesValidClient_fed5e45cef80b2b2/Weatherforecast/WeatherforecastRequestBuilder.verified.cs @@ -0,0 +1,90 @@ +// +#pragma warning disable CS0618 +using Microsoft.Kiota.Abstractions.Extensions; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions; +using Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Threading; +using System; +namespace Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Weatherforecast +{ + /// + /// Builds and executes requests for operations under \weatherforecast + /// + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherforecastRequestBuilder : BaseRequestBuilder + { + /// + /// Instantiates a new and sets the default values. + /// + /// Path parameters for the request + /// The request adapter to use to execute the requests. + public WeatherforecastRequestBuilder(Dictionary pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/weatherforecast", pathParameters) + { + } + /// + /// Instantiates a new and sets the default values. + /// + /// The raw URL to use for the request builder. + /// The request adapter to use to execute the requests. + public WeatherforecastRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/weatherforecast", rawUrl) + { + } + /// A + /// The request body + /// Cancellation token to use when cancelling requests + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public async Task GetAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Parent body, Action>? requestConfiguration = default, CancellationToken cancellationToken = default) + { +#nullable restore +#else + public async Task GetAsync(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Parent body, Action> requestConfiguration = default, CancellationToken cancellationToken = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = ToGetRequestInformation(body, requestConfiguration); + return await RequestAdapter.SendPrimitiveAsync(requestInfo, default, cancellationToken).ConfigureAwait(false); + } + /// A + /// The request body + /// Configuration for the request such as headers, query parameters, and middleware options. +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public RequestInformation ToGetRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Parent body, Action>? requestConfiguration = default) + { +#nullable restore +#else + public RequestInformation ToGetRequestInformation(global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Models.Parent body, Action> requestConfiguration = default) + { +#endif + if(ReferenceEquals(body, null)) throw new ArgumentNullException(nameof(body)); + var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters); + requestInfo.Configure(requestConfiguration); + requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body); + return requestInfo; + } + /// + /// Returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored. + /// + /// A + /// The raw URL to use for the request builder. + public global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Weatherforecast.WeatherforecastRequestBuilder WithUrl(string rawUrl) + { + return new global::Swashbuckle.AspNetCore.IntegrationTests.KiotaTests.Weatherforecast.WeatherforecastRequestBuilder(rawUrl, RequestAdapter); + } + /// + /// Configuration for the request such as headers, query parameters, and middleware options. + /// + [Obsolete("This class is deprecated. Please use the generic RequestConfiguration class generated by the generator.")] + [global::System.CodeDom.Compiler.GeneratedCode("Kiota", "1.0.0")] + public partial class WeatherforecastRequestBuilderGetRequestConfiguration : RequestConfiguration + { + } + } +} +#pragma warning restore CS0618 diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt index 2b12527895..f5c7e14f4c 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt @@ -48,12 +48,9 @@ "type": "object", "properties": { "child": { - "oneOf": [ + "allOf": [ { "$ref": "#/components/schemas/Child" - }, - { - "type": "null" } ] }, diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt index 2b12527895..f5c7e14f4c 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt @@ -48,12 +48,9 @@ "type": "object", "properties": { "child": { - "oneOf": [ + "allOf": [ { "$ref": "#/components/schemas/Child" - }, - { - "type": "null" } ] }, diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt index 2b12527895..f5c7e14f4c 100644 --- a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=MinimalAppWithNullableEnums.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt @@ -48,12 +48,9 @@ "type": "object", "properties": { "child": { - "oneOf": [ + "allOf": [ { "$ref": "#/components/schemas/Child" - }, - { - "type": "null" } ] }, diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt new file mode 100644 index 0000000000..cf2b5c482a --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet10_0.verified.txt @@ -0,0 +1,474 @@ +{ + "openapi": "3.0.4", + "info": { + "title": "Todo API", + "version": "v1" + }, + "paths": { + "/api/items": { + "get": { + "tags": [ + "TodoApp" + ], + "summary": "Get all Todo items", + "description": "Gets all of the current user's todo items.", + "operationId": "ListTodos", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + }, + "post": { + "tags": [ + "TodoApp" + ], + "summary": "Create a new Todo item", + "description": "Creates a new todo item for the current user and returns its ID.", + "operationId": "CreateTodo", + "requestBody": { + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/CreateTodoItemModel" + } + ], + "description": "Represents the model for creating a new Todo item." + } + } + }, + "required": true + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreatedTodoItemModel" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}": { + "get": { + "tags": [ + "TodoApp" + ], + "summary": "Get a specific Todo item", + "description": "Gets the todo item with the specified ID.", + "operationId": "GetTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoItemModel" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + }, + "delete": { + "tags": [ + "TodoApp" + ], + "summary": "Delete a Todo item", + "description": "Deletes the todo item with the specified ID.", + "operationId": "DeleteTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}/complete": { + "post": { + "tags": [ + "TodoApp" + ], + "summary": "Mark a Todo item as completed", + "description": "Marks the todo item with the specified ID as complete.", + "operationId": "CompleteTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}/priority": { + "patch": { + "tags": [ + "TodoApp" + ], + "summary": "Updates the priority of a Todo item", + "description": "Updates the priority of the todo item with the specified ID to the specified priority.", + "operationId": "UpdateTodoPriority", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/UpdateTodoItemPriorityModel" + } + ], + "description": "Represents the model for updating the priority of a Todo item." + } + } + }, + "required": true + }, + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/find": { + "get": { + "tags": [ + "TodoApp" + ], + "operationId": "FindTodo", + "parameters": [ + { + "name": "Text", + "in": "query", + "description": "Gets or sets the text of the filter.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "IsCompleted", + "in": "query", + "description": "Gets or sets a value indicating whether to search completed Todo items.", + "required": true, + "schema": { + "type": "boolean" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + } + }, + "/api/items/getAfter": { + "get": { + "tags": [ + "TodoApp" + ], + "operationId": "GetAfterDate", + "parameters": [ + { + "name": "value", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "date-time" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "CreateTodoItemModel": { + "type": "object", + "properties": { + "text": { + "type": "string", + "description": "Gets or sets the text of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for creating a new Todo item." + }, + "CreatedTodoItemModel": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Gets or sets the ID of the created Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for a created Todo item." + }, + "ProblemDetails": { + "type": "object", + "properties": { + "type": { + "type": "string", + "nullable": true + }, + "title": { + "type": "string", + "nullable": true + }, + "status": { + "type": "integer", + "format": "int32", + "nullable": true + }, + "detail": { + "type": "string", + "nullable": true + }, + "instance": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": { } + }, + "TodoItemModel": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Gets or sets the ID of the Todo item." + }, + "text": { + "type": "string", + "description": "Gets or sets the text of the Todo item." + }, + "createdAt": { + "type": "string", + "description": "Gets or sets the date and time the item was created.", + "format": "date-time" + }, + "completedAt": { + "type": "string", + "description": "Gets or sets the date and time the item was completed.", + "format": "date-time", + "nullable": true + }, + "lastUpdated": { + "type": "string", + "description": "Gets or sets the date and time the Todo item was last updated.", + "format": "date-time" + }, + "priority": { + "allOf": [ + { + "$ref": "#/components/schemas/TodoPriority" + } + ], + "description": "Gets or sets the optional priority of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents a Todo item." + }, + "TodoListViewModel": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TodoItemModel" + }, + "description": "Gets or sets the Todo item(s)." + } + }, + "additionalProperties": false, + "description": "Represents a collection of Todo items." + }, + "TodoPriority": { + "enum": [ + "Normal", + "Low", + "High" + ], + "type": "string", + "description": "The priority levels for a Todo item." + }, + "UpdateTodoItemPriorityModel": { + "type": "object", + "properties": { + "priority": { + "allOf": [ + { + "$ref": "#/components/schemas/TodoPriority" + } + ], + "description": "Gets or sets the new priority of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for updating the priority of a Todo item." + } + } + }, + "tags": [ + { + "name": "TodoApp" + } + ] +} \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt new file mode 100644 index 0000000000..fc9cebee4f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet8_0.verified.txt @@ -0,0 +1,472 @@ +{ + "openapi": "3.0.4", + "info": { + "title": "Todo API", + "version": "v1" + }, + "paths": { + "/api/items": { + "get": { + "tags": [ + "TodoApp" + ], + "summary": "Get all Todo items", + "description": "Gets all of the current user's todo items.", + "operationId": "ListTodos", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + }, + "post": { + "tags": [ + "TodoApp" + ], + "summary": "Create a new Todo item", + "description": "Creates a new todo item for the current user and returns its ID.", + "operationId": "CreateTodo", + "requestBody": { + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/CreateTodoItemModel" + } + ], + "description": "Represents the model for creating a new Todo item." + } + } + }, + "required": true + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreatedTodoItemModel" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}": { + "get": { + "tags": [ + "TodoApp" + ], + "summary": "Get a specific Todo item", + "description": "Gets the todo item with the specified ID.", + "operationId": "GetTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoItemModel" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + }, + "delete": { + "tags": [ + "TodoApp" + ], + "summary": "Delete a Todo item", + "description": "Deletes the todo item with the specified ID.", + "operationId": "DeleteTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}/complete": { + "post": { + "tags": [ + "TodoApp" + ], + "summary": "Mark a Todo item as completed", + "description": "Marks the todo item with the specified ID as complete.", + "operationId": "CompleteTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}/priority": { + "patch": { + "tags": [ + "TodoApp" + ], + "summary": "Updates the priority of a Todo item", + "description": "Updates the priority of the todo item with the specified ID to the specified priority.", + "operationId": "UpdateTodoPriority", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/UpdateTodoItemPriorityModel" + } + ], + "description": "Represents the model for updating the priority of a Todo item." + } + } + }, + "required": true + }, + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/find": { + "get": { + "tags": [ + "TodoApp" + ], + "operationId": "FindTodo", + "parameters": [ + { + "name": "Text", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "IsCompleted", + "in": "query", + "required": true, + "schema": { + "type": "boolean" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + } + }, + "/api/items/getAfter": { + "get": { + "tags": [ + "TodoApp" + ], + "operationId": "GetAfterDate", + "parameters": [ + { + "name": "value", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "date-time" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "CreateTodoItemModel": { + "type": "object", + "properties": { + "text": { + "type": "string", + "description": "Gets or sets the text of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for creating a new Todo item." + }, + "CreatedTodoItemModel": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Gets or sets the ID of the created Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for a created Todo item." + }, + "ProblemDetails": { + "type": "object", + "properties": { + "type": { + "type": "string", + "nullable": true + }, + "title": { + "type": "string", + "nullable": true + }, + "status": { + "type": "integer", + "format": "int32", + "nullable": true + }, + "detail": { + "type": "string", + "nullable": true + }, + "instance": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": { } + }, + "TodoItemModel": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Gets or sets the ID of the Todo item." + }, + "text": { + "type": "string", + "description": "Gets or sets the text of the Todo item." + }, + "createdAt": { + "type": "string", + "description": "Gets or sets the date and time the item was created.", + "format": "date-time" + }, + "completedAt": { + "type": "string", + "description": "Gets or sets the date and time the item was completed.", + "format": "date-time", + "nullable": true + }, + "lastUpdated": { + "type": "string", + "description": "Gets or sets the date and time the Todo item was last updated.", + "format": "date-time" + }, + "priority": { + "allOf": [ + { + "$ref": "#/components/schemas/TodoPriority" + } + ], + "description": "Gets or sets the optional priority of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents a Todo item." + }, + "TodoListViewModel": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TodoItemModel" + }, + "description": "Gets or sets the Todo item(s)." + } + }, + "additionalProperties": false, + "description": "Represents a collection of Todo items." + }, + "TodoPriority": { + "enum": [ + "Normal", + "Low", + "High" + ], + "type": "string", + "description": "The priority levels for a Todo item." + }, + "UpdateTodoItemPriorityModel": { + "type": "object", + "properties": { + "priority": { + "allOf": [ + { + "$ref": "#/components/schemas/TodoPriority" + } + ], + "description": "Gets or sets the new priority of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for updating the priority of a Todo item." + } + } + }, + "tags": [ + { + "name": "TodoApp" + } + ] +} \ No newline at end of file diff --git a/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt new file mode 100644 index 0000000000..fc9cebee4f --- /dev/null +++ b/test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/VerifyTests.Swagger_IsValidJson_No_Startup_entryPointType=TodoApp.Program_swaggerRequestUri=v1.DotNet9_0.verified.txt @@ -0,0 +1,472 @@ +{ + "openapi": "3.0.4", + "info": { + "title": "Todo API", + "version": "v1" + }, + "paths": { + "/api/items": { + "get": { + "tags": [ + "TodoApp" + ], + "summary": "Get all Todo items", + "description": "Gets all of the current user's todo items.", + "operationId": "ListTodos", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + }, + "post": { + "tags": [ + "TodoApp" + ], + "summary": "Create a new Todo item", + "description": "Creates a new todo item for the current user and returns its ID.", + "operationId": "CreateTodo", + "requestBody": { + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/CreateTodoItemModel" + } + ], + "description": "Represents the model for creating a new Todo item." + } + } + }, + "required": true + }, + "responses": { + "201": { + "description": "Created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreatedTodoItemModel" + } + } + } + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}": { + "get": { + "tags": [ + "TodoApp" + ], + "summary": "Get a specific Todo item", + "description": "Gets the todo item with the specified ID.", + "operationId": "GetTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoItemModel" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + }, + "delete": { + "tags": [ + "TodoApp" + ], + "summary": "Delete a Todo item", + "description": "Deletes the todo item with the specified ID.", + "operationId": "DeleteTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}/complete": { + "post": { + "tags": [ + "TodoApp" + ], + "summary": "Mark a Todo item as completed", + "description": "Marks the todo item with the specified ID as complete.", + "operationId": "CompleteTodo", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/{id}/priority": { + "patch": { + "tags": [ + "TodoApp" + ], + "summary": "Updates the priority of a Todo item", + "description": "Updates the priority of the todo item with the specified ID to the specified priority.", + "operationId": "UpdateTodoPriority", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The Todo item's ID.", + "required": true, + "schema": { + "type": "string", + "description": "The Todo item's ID.", + "format": "uuid" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "allOf": [ + { + "$ref": "#/components/schemas/UpdateTodoItemPriorityModel" + } + ], + "description": "Represents the model for updating the priority of a Todo item." + } + } + }, + "required": true + }, + "responses": { + "204": { + "description": "No Content" + }, + "400": { + "description": "Bad Request", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/problem+json": { + "schema": { + "$ref": "#/components/schemas/ProblemDetails" + } + } + } + } + } + } + }, + "/api/items/find": { + "get": { + "tags": [ + "TodoApp" + ], + "operationId": "FindTodo", + "parameters": [ + { + "name": "Text", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "IsCompleted", + "in": "query", + "required": true, + "schema": { + "type": "boolean" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + } + }, + "/api/items/getAfter": { + "get": { + "tags": [ + "TodoApp" + ], + "operationId": "GetAfterDate", + "parameters": [ + { + "name": "value", + "in": "query", + "required": true, + "schema": { + "type": "string", + "format": "date-time" + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/TodoListViewModel" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "CreateTodoItemModel": { + "type": "object", + "properties": { + "text": { + "type": "string", + "description": "Gets or sets the text of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for creating a new Todo item." + }, + "CreatedTodoItemModel": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Gets or sets the ID of the created Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for a created Todo item." + }, + "ProblemDetails": { + "type": "object", + "properties": { + "type": { + "type": "string", + "nullable": true + }, + "title": { + "type": "string", + "nullable": true + }, + "status": { + "type": "integer", + "format": "int32", + "nullable": true + }, + "detail": { + "type": "string", + "nullable": true + }, + "instance": { + "type": "string", + "nullable": true + } + }, + "additionalProperties": { } + }, + "TodoItemModel": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Gets or sets the ID of the Todo item." + }, + "text": { + "type": "string", + "description": "Gets or sets the text of the Todo item." + }, + "createdAt": { + "type": "string", + "description": "Gets or sets the date and time the item was created.", + "format": "date-time" + }, + "completedAt": { + "type": "string", + "description": "Gets or sets the date and time the item was completed.", + "format": "date-time", + "nullable": true + }, + "lastUpdated": { + "type": "string", + "description": "Gets or sets the date and time the Todo item was last updated.", + "format": "date-time" + }, + "priority": { + "allOf": [ + { + "$ref": "#/components/schemas/TodoPriority" + } + ], + "description": "Gets or sets the optional priority of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents a Todo item." + }, + "TodoListViewModel": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "$ref": "#/components/schemas/TodoItemModel" + }, + "description": "Gets or sets the Todo item(s)." + } + }, + "additionalProperties": false, + "description": "Represents a collection of Todo items." + }, + "TodoPriority": { + "enum": [ + "Normal", + "Low", + "High" + ], + "type": "string", + "description": "The priority levels for a Todo item." + }, + "UpdateTodoItemPriorityModel": { + "type": "object", + "properties": { + "priority": { + "allOf": [ + { + "$ref": "#/components/schemas/TodoPriority" + } + ], + "description": "Gets or sets the new priority of the Todo item." + } + }, + "additionalProperties": false, + "description": "Represents the model for updating the priority of a Todo item." + } + } + }, + "tags": [ + { + "name": "TodoApp" + } + ] +} \ No newline at end of file diff --git a/test/WebSites/TodoApp/ApiEndpoints.cs b/test/WebSites/TodoApp/ApiEndpoints.cs new file mode 100644 index 0000000000..6efa9b0b92 --- /dev/null +++ b/test/WebSites/TodoApp/ApiEndpoints.cs @@ -0,0 +1,187 @@ +using System.ComponentModel; +using Microsoft.EntityFrameworkCore; +using TodoApp.Data; +using TodoApp.Models; + +namespace TodoApp; + +public static class ApiEndpoints +{ + public static IServiceCollection AddTodoApi(this IServiceCollection services) + { + services.AddSingleton(TimeProvider.System); + services.AddScoped(); + services.AddScoped(); + + services.AddDbContext((options) => options.UseInMemoryDatabase("Todos")); + + services.ConfigureHttpJsonOptions((options) => + { + options.SerializerOptions.DefaultIgnoreCondition = TodoJsonSerializerContext.Default.Options.DefaultIgnoreCondition; + options.SerializerOptions.NumberHandling = TodoJsonSerializerContext.Default.Options.NumberHandling; + options.SerializerOptions.PropertyNamingPolicy = TodoJsonSerializerContext.Default.Options.PropertyNamingPolicy; + options.SerializerOptions.WriteIndented = TodoJsonSerializerContext.Default.Options.WriteIndented; + options.SerializerOptions.TypeInfoResolverChain.Add(TodoJsonSerializerContext.Default); + + options.SerializerOptions.Converters.Clear(); + + foreach (var converter in TodoJsonSerializerContext.Default.Options.Converters) + { + options.SerializerOptions.Converters.Add(converter); + } + }); + + return services; + } + + public static IEndpointRouteBuilder MapTodoApiRoutes(this IEndpointRouteBuilder builder) + { + var group = builder.MapGroup("/api/items") + .WithTags("TodoApp"); + { + group.MapGet("/", async (TodoService service, CancellationToken cancellationToken) => await service.GetListAsync(cancellationToken)) + .WithName("ListTodos") + .WithSummary("Get all Todo items") + .WithDescription("Gets all of the current user's todo items.") + .Produces(StatusCodes.Status200OK); + + group.MapGet( + "/{id}", + async ( + [Description("The Todo item's ID.")] Guid id, + TodoService service, + CancellationToken cancellationToken) => + { + var model = await service.GetAsync(id, cancellationToken); + return model switch + { + null => Results.Problem("Item not found.", statusCode: StatusCodes.Status404NotFound), + _ => Results.Ok(model), + }; + }) + .WithName("GetTodo") + .WithSummary("Get a specific Todo item") + .WithDescription("Gets the todo item with the specified ID.") + .Produces(StatusCodes.Status200OK) + .ProducesProblem(StatusCodes.Status404NotFound); + + group.MapPost( + "/", + async ( + [Description("The Todo item to create.")] CreateTodoItemModel model, + TodoService service, + CancellationToken cancellationToken) => + { + if (string.IsNullOrWhiteSpace(model.Text)) + { + return Results.Problem("No item text specified.", statusCode: StatusCodes.Status400BadRequest); + } + + var id = await service.AddItemAsync(model.Text, cancellationToken); + + return Results.Created($"/api/items/{id}", new CreatedTodoItemModel() { Id = id }); + }) + .WithName("CreateTodo") + .WithSummary("Create a new Todo item") + .WithDescription("Creates a new todo item for the current user and returns its ID.") + .Produces(StatusCodes.Status201Created) + .ProducesProblem(StatusCodes.Status400BadRequest); + + group.MapPost( + "/{id}/complete", + async ( + [Description("The Todo item's ID.")] Guid id, + TodoService service, + CancellationToken cancellationToken) => + { + var wasCompleted = await service.CompleteItemAsync(id, cancellationToken); + + return wasCompleted switch + { + true => Results.NoContent(), + false => Results.Problem("Item already completed.", statusCode: StatusCodes.Status400BadRequest), + _ => Results.Problem("Item not found.", statusCode: StatusCodes.Status404NotFound), + }; + }) + .WithName("CompleteTodo") + .WithSummary("Mark a Todo item as completed") + .WithDescription("Marks the todo item with the specified ID as complete.") + .Produces(StatusCodes.Status204NoContent) + .ProducesProblem(StatusCodes.Status400BadRequest) + .ProducesProblem(StatusCodes.Status404NotFound); + + group.MapDelete( + "/{id}", + async ( + [Description("The Todo item's ID.")] Guid id, + TodoService service, + CancellationToken cancellationToken) => + { + var wasDeleted = await service.DeleteItemAsync(id, cancellationToken); + return wasDeleted switch + { + true => Results.NoContent(), + false => Results.Problem("Item not found.", statusCode: StatusCodes.Status404NotFound), + }; + }) + .WithName("DeleteTodo") + .WithSummary("Delete a Todo item") + .WithDescription("Deletes the todo item with the specified ID.") + .Produces(StatusCodes.Status204NoContent) + .ProducesProblem(StatusCodes.Status404NotFound); + + group.MapPatch( + "/{id}/priority", + async ( + [Description("The Todo item's ID.")] Guid id, + [Description("The Todo item's new priority.")] UpdateTodoItemPriorityModel priority, + TodoService service, + CancellationToken cancellationToken) => + { + if (priority.Priority < TodoPriority.Low || priority.Priority > TodoPriority.High) + { + return Results.Problem("Invalid priority.", statusCode: StatusCodes.Status400BadRequest); + } + + var wasUpdated = await service.SetPriorityAsync(id, priority.Priority, cancellationToken); + + return wasUpdated switch + { + true => Results.NoContent(), + false => Results.Problem("Item not found.", statusCode: StatusCodes.Status404NotFound), + }; + }) + .WithName("UpdateTodoPriority") + .WithSummary("Updates the priority of a Todo item") + .WithDescription("Updates the priority of the todo item with the specified ID to the specified priority.") + .Produces(StatusCodes.Status204NoContent) + .ProducesProblem(StatusCodes.Status400BadRequest) + .ProducesProblem(StatusCodes.Status404NotFound); + + group.MapGet("/find", FindTodoItem) + .WithName("FindTodo") + .Produces(); + + group.MapGet("/getAfter", GetAfterDate) + .WithName("GetAfterDate") + .Produces(); + } + + builder.MapGet("/", () => Results.Redirect("/swagger")) + .ExcludeFromDescription(); + + return builder; + } + + private static async Task FindTodoItem( + [AsParameters] TodoItemFilterModel filter, + TodoService service, + CancellationToken cancellationToken) => + await service.FindAsync(filter, cancellationToken); + + private static async Task GetAfterDate( + DateTime value, + TodoService service, + CancellationToken cancellationToken) => + await service.GetAfterDateAsync(value, cancellationToken); +} diff --git a/test/WebSites/TodoApp/Data/TodoContext.cs b/test/WebSites/TodoApp/Data/TodoContext.cs new file mode 100644 index 0000000000..37d484abf3 --- /dev/null +++ b/test/WebSites/TodoApp/Data/TodoContext.cs @@ -0,0 +1,8 @@ +using Microsoft.EntityFrameworkCore; + +namespace TodoApp.Data; + +public class TodoContext(DbContextOptions options) : DbContext(options) +{ + public DbSet Items { get; set; } = default!; +} diff --git a/test/WebSites/TodoApp/Data/TodoItem.cs b/test/WebSites/TodoApp/Data/TodoItem.cs new file mode 100644 index 0000000000..f489274091 --- /dev/null +++ b/test/WebSites/TodoApp/Data/TodoItem.cs @@ -0,0 +1,14 @@ +namespace TodoApp.Data; + +public class TodoItem +{ + public Guid Id { get; set; } + + public string Text { get; set; } = default!; + + public DateTime CreatedAt { get; set; } + + public DateTime? CompletedAt { get; set; } + + public int? Priority { get; set; } +} diff --git a/test/WebSites/TodoApp/Data/TodoRepository.cs b/test/WebSites/TodoApp/Data/TodoRepository.cs new file mode 100644 index 0000000000..786b1d6e01 --- /dev/null +++ b/test/WebSites/TodoApp/Data/TodoRepository.cs @@ -0,0 +1,124 @@ +using Microsoft.EntityFrameworkCore; + +namespace TodoApp.Data; + +public class TodoRepository(TimeProvider timeProvider, TodoContext context) +{ + public async Task AddItemAsync(string text, CancellationToken cancellationToken = default) + { + await EnsureDatabaseAsync(cancellationToken); + + var item = new TodoItem + { + CreatedAt = UtcNow(), + Text = text, + }; + + context.Add(item); + + await context.SaveChangesAsync(cancellationToken); + + return item; + } + + public async Task CompleteItemAsync(Guid itemId, CancellationToken cancellationToken = default) + { + var item = await GetItemAsync(itemId, cancellationToken); + + if (item is null) + { + return null; + } + + if (item.CompletedAt.HasValue) + { + return false; + } + + item.CompletedAt = UtcNow(); + + context.Items.Update(item); + + await context.SaveChangesAsync(cancellationToken); + + return true; + } + + public async Task DeleteItemAsync(Guid itemId, CancellationToken cancellationToken = default) + { + var item = await GetItemAsync(itemId, cancellationToken); + + if (item is null) + { + return false; + } + + context.Items.Remove(item); + + await context.SaveChangesAsync(cancellationToken); + + return true; + } + + public async Task GetItemAsync(Guid itemId, CancellationToken cancellationToken = default) + { + await EnsureDatabaseAsync(cancellationToken); + + return await context.Items.FindItemAsync(itemId, cancellationToken); + } + + public async Task> GetItemsAsync(CancellationToken cancellationToken = default) + { + await EnsureDatabaseAsync(cancellationToken); + + return await context.Items + .OrderBy(x => x.CompletedAt.HasValue) + .ThenBy(x => x.CreatedAt) + .ToListAsync(cancellationToken); + } + + public async Task> FindAsync( + string prefix, + bool isCompleted, + CancellationToken cancellationToken = default) + { + await EnsureDatabaseAsync(cancellationToken); + + return await context.Items + .Where(x => x.Text.StartsWith(prefix)) + .Where(x => x.CompletedAt.HasValue == isCompleted) + .ToListAsync(cancellationToken); + } + + public async Task> GetAfterDateAsync(DateTime value, CancellationToken cancellationToken) + { + await EnsureDatabaseAsync(cancellationToken); + + return await context.Items + .Where(x => x.CreatedAt > value) + .ToListAsync(cancellationToken); + } + + public async Task SetPriorityAsync(Guid itemId, int priority, CancellationToken cancellationToken = default) + { + var item = await GetItemAsync(itemId, cancellationToken); + + if (item is null) + { + return false; + } + + item.Priority = priority; + + context.Items.Update(item); + + await context.SaveChangesAsync(cancellationToken); + + return true; + } + + private async Task EnsureDatabaseAsync(CancellationToken cancellationToken) + => await context.Database.EnsureCreatedAsync(cancellationToken); + + private DateTime UtcNow() => timeProvider.GetUtcNow().UtcDateTime; +} diff --git a/test/WebSites/TodoApp/DbSetExtensions.cs b/test/WebSites/TodoApp/DbSetExtensions.cs new file mode 100644 index 0000000000..3cbf323f06 --- /dev/null +++ b/test/WebSites/TodoApp/DbSetExtensions.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; + +namespace TodoApp; + +public static class DbSetExtensions +{ + public static ValueTask FindItemAsync( + this DbSet set, + TKey keyValue, + CancellationToken cancellationToken) + where TEntity : class + { + ArgumentNullException.ThrowIfNull(keyValue); + return set.FindAsync([keyValue], cancellationToken); + } +} diff --git a/test/WebSites/TodoApp/Models/CreateTodoItemModel.cs b/test/WebSites/TodoApp/Models/CreateTodoItemModel.cs new file mode 100644 index 0000000000..0fca50f3f7 --- /dev/null +++ b/test/WebSites/TodoApp/Models/CreateTodoItemModel.cs @@ -0,0 +1,12 @@ +namespace TodoApp.Models; + +/// +/// Represents the model for creating a new Todo item. +/// +public class CreateTodoItemModel +{ + /// + /// Gets or sets the text of the Todo item. + /// + public string Text { get; set; } = string.Empty; +} diff --git a/test/WebSites/TodoApp/Models/CreatedTodoItemModel.cs b/test/WebSites/TodoApp/Models/CreatedTodoItemModel.cs new file mode 100644 index 0000000000..3433804c96 --- /dev/null +++ b/test/WebSites/TodoApp/Models/CreatedTodoItemModel.cs @@ -0,0 +1,12 @@ +namespace TodoApp.Models; + +/// +/// Represents the model for a created Todo item. +/// +public class CreatedTodoItemModel +{ + /// + /// Gets or sets the ID of the created Todo item. + /// + public string Id { get; set; } = string.Empty; +} diff --git a/test/WebSites/TodoApp/Models/TodoItemFilterModel.cs b/test/WebSites/TodoApp/Models/TodoItemFilterModel.cs new file mode 100644 index 0000000000..7fcb17151e --- /dev/null +++ b/test/WebSites/TodoApp/Models/TodoItemFilterModel.cs @@ -0,0 +1,17 @@ +namespace TodoApp.Models; + +/// +/// Represents the model for searching for Todo items. +/// +public class TodoItemFilterModel +{ + /// + /// Gets or sets the text of the filter. + /// + public string Text { get; set; } = string.Empty; + + /// + /// Gets or sets a value indicating whether to search completed Todo items. + /// + public bool IsCompleted { get; set; } +} diff --git a/test/WebSites/TodoApp/Models/TodoItemModel.cs b/test/WebSites/TodoApp/Models/TodoItemModel.cs new file mode 100644 index 0000000000..dcfa054f70 --- /dev/null +++ b/test/WebSites/TodoApp/Models/TodoItemModel.cs @@ -0,0 +1,37 @@ +namespace TodoApp.Models; + +/// +/// Represents a Todo item. +/// +public class TodoItemModel +{ + /// + /// Gets or sets the ID of the Todo item. + /// + public string Id { get; set; } = default!; + + /// + /// Gets or sets the text of the Todo item. + /// + public string Text { get; set; } = default!; + + /// + /// Gets or sets the date and time the item was created. + /// + public DateTimeOffset CreatedAt { get; set; } + + /// + /// Gets or sets the date and time the item was completed. + /// + public DateTimeOffset? CompletedAt { get; set; } + + /// + /// Gets or sets the date and time the Todo item was last updated. + /// + public DateTimeOffset LastUpdated { get; set; } = default!; + + /// + /// Gets or sets the optional priority of the Todo item. + /// + public TodoPriority? Priority { get; set; } +} diff --git a/test/WebSites/TodoApp/Models/TodoListViewModel.cs b/test/WebSites/TodoApp/Models/TodoListViewModel.cs new file mode 100644 index 0000000000..25d96cef40 --- /dev/null +++ b/test/WebSites/TodoApp/Models/TodoListViewModel.cs @@ -0,0 +1,12 @@ +namespace TodoApp.Models; + +/// +/// Represents a collection of Todo items. +/// +public class TodoListViewModel +{ + /// + /// Gets or sets the Todo item(s). + /// + public ICollection Items { get; set; } = []; +} diff --git a/test/WebSites/TodoApp/Models/TodoPriority.cs b/test/WebSites/TodoApp/Models/TodoPriority.cs new file mode 100644 index 0000000000..e38af006d6 --- /dev/null +++ b/test/WebSites/TodoApp/Models/TodoPriority.cs @@ -0,0 +1,25 @@ +using System.Text.Json.Serialization; + +namespace TodoApp.Models; + +/// +/// The priority levels for a Todo item. +/// +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum TodoPriority +{ + /// + /// The item is of normal priority. + /// + Normal = 0, + + /// + /// The item is of low priority. + /// + Low, + + /// + /// The item is of high priority. + /// + High, +} diff --git a/test/WebSites/TodoApp/Models/UpdateTodoItemPriorityModel.cs b/test/WebSites/TodoApp/Models/UpdateTodoItemPriorityModel.cs new file mode 100644 index 0000000000..9ec8faae8f --- /dev/null +++ b/test/WebSites/TodoApp/Models/UpdateTodoItemPriorityModel.cs @@ -0,0 +1,12 @@ +namespace TodoApp.Models; + +/// +/// Represents the model for updating the priority of a Todo item. +/// +public class UpdateTodoItemPriorityModel +{ + /// + /// Gets or sets the new priority of the Todo item. + /// + public TodoPriority Priority { get; set; } +} diff --git a/test/WebSites/TodoApp/Program.cs b/test/WebSites/TodoApp/Program.cs new file mode 100644 index 0000000000..36aa2aff5c --- /dev/null +++ b/test/WebSites/TodoApp/Program.cs @@ -0,0 +1,19 @@ +using TodoApp; + +var builder = WebApplication.CreateBuilder(args); + +builder.AddTodoApp(); + +var app = builder.Build(); + +app.UseTodoApp(); + +app.Run(); + +namespace TodoApp +{ + public partial class Program + { + // Expose the Program class for use with WebApplicationFactory + } +} diff --git a/test/WebSites/TodoApp/Properties/launchSettings.json b/test/WebSites/TodoApp/Properties/launchSettings.json new file mode 100644 index 0000000000..be95968c5c --- /dev/null +++ b/test/WebSites/TodoApp/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "TodoApp": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:5916;http://localhost:5618", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/test/WebSites/TodoApp/TodoApp.csproj b/test/WebSites/TodoApp/TodoApp.csproj new file mode 100644 index 0000000000..93a1f779b2 --- /dev/null +++ b/test/WebSites/TodoApp/TodoApp.csproj @@ -0,0 +1,25 @@ + + + true + true + false + false + $(NoWarn);CA1019;CA1050;CA1813;CS1591;IDE0130 + enable + TodoApp + $(DefaultTargetFrameworks) + + + + + + + + + + + + + + + diff --git a/test/WebSites/TodoApp/TodoAppBuilder.cs b/test/WebSites/TodoApp/TodoAppBuilder.cs new file mode 100644 index 0000000000..dd32971322 --- /dev/null +++ b/test/WebSites/TodoApp/TodoAppBuilder.cs @@ -0,0 +1,56 @@ +using System.Reflection; +using Microsoft.AspNetCore.WebUtilities; + +namespace TodoApp; + +public static class TodoAppBuilder +{ + public static WebApplicationBuilder AddTodoApp(this WebApplicationBuilder builder) + { + builder.Services.AddTodoApi(); + + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen((options) => + { + options.EnableAnnotations(); + options.IncludeXmlComments(Assembly.GetExecutingAssembly()); + options.SupportNonNullableReferenceTypes(); + options.UseAllOfToExtendReferenceSchemas(); + + var version = "v1"; + options.SwaggerDoc(version, new() { Title = "Todo API", Version = version }); + }); + + if (!builder.Environment.IsDevelopment()) + { + builder.Services.AddProblemDetails(); + builder.Services.Configure((options) => + { + options.CustomizeProblemDetails = (context) => + { + if (context.Exception is not null) + { + context.ProblemDetails.Detail = "An internal error occurred."; + } + + context.ProblemDetails.Instance = context.HttpContext.Request.Path; + context.ProblemDetails.Title = ReasonPhrases.GetReasonPhrase(context.ProblemDetails.Status ?? StatusCodes.Status500InternalServerError); + }; + }); + } + + return builder; + } + + public static WebApplication UseTodoApp(this WebApplication app) + { + app.UseStatusCodePagesWithReExecute("/error", "?id={0}"); + + app.MapTodoApiRoutes(); + + app.UseSwagger((p) => p.OpenApiVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0); + app.UseSwaggerUI(); + + return app; + } +} diff --git a/test/WebSites/TodoApp/TodoJsonSerializerContext.cs b/test/WebSites/TodoApp/TodoJsonSerializerContext.cs new file mode 100644 index 0000000000..52f8b270e0 --- /dev/null +++ b/test/WebSites/TodoApp/TodoJsonSerializerContext.cs @@ -0,0 +1,25 @@ +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; +using Microsoft.AspNetCore.Mvc; +using TodoApp.Models; + +namespace TodoApp; + +[JsonSerializable(typeof(CreateTodoItemModel))] +[JsonSerializable(typeof(CreatedTodoItemModel))] +[JsonSerializable(typeof(DateTime))] +[JsonSerializable(typeof(Guid))] +[JsonSerializable(typeof(JsonObject))] +[JsonSerializable(typeof(ProblemDetails))] +[JsonSerializable(typeof(TodoItemFilterModel))] +[JsonSerializable(typeof(TodoItemModel))] +[JsonSerializable(typeof(TodoListViewModel))] +[JsonSerializable(typeof(TodoPriority))] +[JsonSerializable(typeof(UpdateTodoItemPriorityModel))] +[JsonSourceGenerationOptions( + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + NumberHandling = JsonNumberHandling.Strict, + PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, + UseStringEnumConverter = true, + WriteIndented = true)] +public sealed partial class TodoJsonSerializerContext : JsonSerializerContext; diff --git a/test/WebSites/TodoApp/TodoService.cs b/test/WebSites/TodoApp/TodoService.cs new file mode 100644 index 0000000000..9115ff7fcf --- /dev/null +++ b/test/WebSites/TodoApp/TodoService.cs @@ -0,0 +1,77 @@ +using TodoApp.Data; +using TodoApp.Models; + +namespace TodoApp; + +public class TodoService(TodoRepository repository) +{ + public async Task AddItemAsync(string text, CancellationToken cancellationToken) + { + var item = await repository.AddItemAsync(text, cancellationToken); + return item.Id.ToString(); + } + + public async Task CompleteItemAsync(Guid itemId, CancellationToken cancellationToken) + { + return await repository.CompleteItemAsync(itemId, cancellationToken); + } + + public async Task DeleteItemAsync(Guid itemId, CancellationToken cancellationToken) + { + return await repository.DeleteItemAsync(itemId, cancellationToken); + } + + public async Task GetAsync(Guid itemId, CancellationToken cancellationToken) + { + var item = await repository.GetItemAsync(itemId, cancellationToken); + return item is null ? null : MapItem(item); + } + + public async Task GetListAsync(CancellationToken cancellationToken) + { + var items = await repository.GetItemsAsync(cancellationToken); + return MapItems(items); + } + + public async Task FindAsync(TodoItemFilterModel filter, CancellationToken cancellationToken) + { + var items = await repository.FindAsync(filter.Text, filter.IsCompleted, cancellationToken); + return MapItems(items); + } + + public async Task GetAfterDateAsync(DateTime value, CancellationToken cancellationToken) + { + var items = await repository.GetAfterDateAsync(value, cancellationToken); + return MapItems(items); + } + + public async Task SetPriorityAsync(Guid itemId, TodoPriority priority, CancellationToken cancellationToken) + { + return await repository.SetPriorityAsync(itemId, (int)priority, cancellationToken); + } + + private static TodoListViewModel MapItems(IList items) + { + var result = new List(items.Count); + + foreach (var todo in items) + { + result.Add(MapItem(todo)); + } + + return new() { Items = result }; + } + + private static TodoItemModel MapItem(TodoItem item) + { + return new() + { + Id = item.Id.ToString(), + CompletedAt = item.CompletedAt, + CreatedAt = item.CreatedAt, + LastUpdated = item.CompletedAt ?? item.CreatedAt, + Priority = item.Priority is { } priority ? (TodoPriority)priority : null, + Text = item.Text, + }; + } +} diff --git a/test/WebSites/TodoApp/appsettings.Development.json b/test/WebSites/TodoApp/appsettings.Development.json new file mode 100644 index 0000000000..e62a4a3e26 --- /dev/null +++ b/test/WebSites/TodoApp/appsettings.Development.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Warning", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/test/WebSites/TodoApp/appsettings.json b/test/WebSites/TodoApp/appsettings.json new file mode 100644 index 0000000000..def9159a7d --- /dev/null +++ b/test/WebSites/TodoApp/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +}