diff --git a/src/Simplify.Web.Swagger/ControllerAction.cs b/src/Simplify.Web.Swagger/ControllerAction.cs index f665274..580e6aa 100644 --- a/src/Simplify.Web.Swagger/ControllerAction.cs +++ b/src/Simplify.Web.Swagger/ControllerAction.cs @@ -1,11 +1,7 @@ using System; using System.Collections.Generic; -#if NET10_0 using Microsoft.OpenApi; using NetHttpMethod = System.Net.Http.HttpMethod; -#else -using Microsoft.OpenApi.Models; -#endif using Simplify.Web.Controllers.Meta.Routing; namespace Simplify.Web.Swagger; @@ -46,11 +42,7 @@ public class ControllerAction /// /// The type. /// -#if NET10_0 public NetHttpMethod Type { get; set; } = NetHttpMethod.Get; -#else - public OperationType Type { get; set; } -#endif /// /// Gets the path. @@ -58,13 +50,8 @@ public class ControllerAction /// /// The path. /// -#if NETSTANDARD2_0 - public string Path => ControllerRoute.Path.StartsWith("/") ? ControllerRoute.Path : "/" + ControllerRoute.Path; -#else public string Path => ControllerRoute.Path.StartsWith('/') ? ControllerRoute.Path : "/" + ControllerRoute.Path; -#endif - /// /// Gets or sets the controller route. /// diff --git a/src/Simplify.Web.Swagger/ControllerActionsFactory.cs b/src/Simplify.Web.Swagger/ControllerActionsFactory.cs index e64a497..e49d076 100644 --- a/src/Simplify.Web.Swagger/ControllerActionsFactory.cs +++ b/src/Simplify.Web.Swagger/ControllerActionsFactory.cs @@ -7,12 +7,8 @@ using Simplify.Web.Controllers.Meta.Routing; using Simplify.Web.Http; using Swashbuckle.AspNetCore.SwaggerGen; -#if NET10_0 using Microsoft.OpenApi; using NetHttpMethod = System.Net.Http.HttpMethod; -#else -using Microsoft.OpenApi.Models; -#endif namespace Simplify.Web.Swagger; @@ -127,7 +123,6 @@ private static string FormatNameSource(string str) return str; } -#if NET10_0 private static NetHttpMethod HttpMethodToOperationType(HttpMethod method) => method switch { @@ -139,19 +134,6 @@ private static NetHttpMethod HttpMethodToOperationType(HttpMethod method) => HttpMethod.Options => NetHttpMethod.Options, _ => NetHttpMethod.Get, }; -#else - private static OperationType HttpMethodToOperationType(HttpMethod method) => - method switch - { - HttpMethod.Get => OperationType.Get, - HttpMethod.Post => OperationType.Post, - HttpMethod.Put => OperationType.Put, - HttpMethod.Patch => OperationType.Patch, - HttpMethod.Delete => OperationType.Delete, - HttpMethod.Options => OperationType.Options, - _ => OperationType.Get, - }; -#endif private static OpenApiRequestBody CreateRequestBody( Type controllerType, @@ -205,9 +187,7 @@ DocumentFilterContext context foreach (var item in producesResponse.ContentTypes.Distinct()) { -#if NET10_0 response.Content ??= new Dictionary(); -#endif response.Content.Add( item, producesResponse.Type is null diff --git a/src/Simplify.Web.Swagger/EnumNamesSchemaFilter.cs b/src/Simplify.Web.Swagger/EnumNamesSchemaFilter.cs index 87f1802..6c0bcd2 100644 --- a/src/Simplify.Web.Swagger/EnumNamesSchemaFilter.cs +++ b/src/Simplify.Web.Swagger/EnumNamesSchemaFilter.cs @@ -1,14 +1,9 @@ using System; -using System.Linq; -using Swashbuckle.AspNetCore.SwaggerGen; -#if NET10_0 using System.Collections.Generic; +using System.Linq; using System.Text.Json.Nodes; using Microsoft.OpenApi; -#else -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; -#endif +using Swashbuckle.AspNetCore.SwaggerGen; namespace Simplify.Web.Swagger; @@ -18,7 +13,6 @@ namespace Simplify.Web.Swagger; public class EnumNamesSchemaFilter : ISchemaFilter { /// -#if NET10_0 public void Apply(IOpenApiSchema schema, SchemaFilterContext context) { if (!context.Type.IsEnum) @@ -38,23 +32,6 @@ public void Apply(IOpenApiSchema schema, SchemaFilterContext context) concreteSchema.Extensions["x-varnames"] = new JsonNodeExtension(varnames); concreteSchema.Description = BuildDescription(names, values); } -#else - public void Apply(OpenApiSchema schema, SchemaFilterContext context) - { - if (!context.Type.IsEnum) - return; - - var names = Enum.GetNames(context.Type); - var values = Enum.GetValues(context.Type).Cast().ToArray(); - - var varnames = new OpenApiArray(); - foreach (var name in names) - varnames.Add(new OpenApiString(name)); - - schema.Extensions["x-varnames"] = varnames; - schema.Description = BuildDescription(names, values); - } -#endif private static string BuildDescription(string[] names, object[] values) => string.Join(", ", names.Select((name, i) => $"{Convert.ToInt64(values[i])} = {name}")); diff --git a/src/Simplify.Web.Swagger/Simplify.Web.Swagger.csproj b/src/Simplify.Web.Swagger/Simplify.Web.Swagger.csproj index aa644c6..2e3a565 100644 --- a/src/Simplify.Web.Swagger/Simplify.Web.Swagger.csproj +++ b/src/Simplify.Web.Swagger/Simplify.Web.Swagger.csproj @@ -24,15 +24,10 @@ See https://github.com/SimplifyNet/Simplify.Web.Swagger/tree/master/src/Simplify.Web.Swagger/CHANGELOG.md for details - + - - - - - diff --git a/src/Simplify.Web.Swagger/SimplifyWebDocumentFilter.cs b/src/Simplify.Web.Swagger/SimplifyWebDocumentFilter.cs index fe21a07..962576e 100644 --- a/src/Simplify.Web.Swagger/SimplifyWebDocumentFilter.cs +++ b/src/Simplify.Web.Swagger/SimplifyWebDocumentFilter.cs @@ -3,12 +3,8 @@ using System.Linq; using Simplify.Web.Controllers.Meta.Routing; using Swashbuckle.AspNetCore.SwaggerGen; -#if NET10_0 using Microsoft.OpenApi; using JsonNode = System.Text.Json.Nodes.JsonNode; -#else -using Microsoft.OpenApi.Models; -#endif namespace Simplify.Web.Swagger; @@ -55,19 +51,11 @@ var item in controllerActions PopulateDocumentTags(swaggerDoc, controllerActions); } -#if NET10_0 private static IList CreateParameters(ControllerAction item, DocumentFilterContext context) => item.ControllerRoute.Items .OfType() .Select(x => (IOpenApiParameter)CreatePathParameter(x, item, context)) .ToList(); -#else - private static IList CreateParameters(ControllerAction item, DocumentFilterContext context) => - item.ControllerRoute.Items - .OfType() - .Select(x => CreatePathParameter(x, item, context)) - .ToList(); -#endif private static OpenApiParameter CreatePathParameter(PathParameter pathParam, ControllerAction item, DocumentFilterContext context) { @@ -103,21 +91,15 @@ private OpenApiOperation CreateOperation(ControllerAction item, OpenApiDocument { var operation = new OpenApiOperation(); -#if NET10_0 operation.Tags ??= new HashSet(); operation.Tags.Add(new OpenApiTagReference(item.Names.GroupName)); -#else - operation.Tags.Add(new OpenApiTag { Name = item.Names.GroupName }); -#endif if (item.Names.Summary != null) operation.Summary = item.Names.Summary; foreach (var response in item.Responses) { -#if NET10_0 operation.Responses ??= new OpenApiResponses(); -#endif operation.Responses.Add(response.Key.ToString(), response.Value); } @@ -130,7 +112,6 @@ private OpenApiOperation CreateOperation(ControllerAction item, OpenApiDocument { var schemeNames = ResolveSecuritySchemeNames(swaggerDoc); -#if NET10_0 if (schemeNames.Count > 0) operation.Security = schemeNames .Select(name => new OpenApiSecurityRequirement @@ -138,25 +119,6 @@ private OpenApiOperation CreateOperation(ControllerAction item, OpenApiDocument [new OpenApiSecuritySchemeReference(name, swaggerDoc)] = [], }) .ToList(); -#else - if (schemeNames.Count > 0) - operation.Security = schemeNames - .Select(name => new OpenApiSecurityRequirement - { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = name, - }, - }, - new List() - }, - }) - .ToList(); -#endif } if (_args == null) @@ -190,21 +152,12 @@ private static OpenApiParameter CreateAcceptLanguageParameter(AcceptLanguageHead AllowEmptyValue = true, }; -#if NET10_0 param.Example = args.Default; param.Schema = new OpenApiSchema { Default = args.Default, Enum = args.Languages.Select(l => (JsonNode)l).ToList() }; -#else - param.Example = new Microsoft.OpenApi.Any.OpenApiString(args.Default); - param.Schema = new OpenApiSchema - { - Default = new Microsoft.OpenApi.Any.OpenApiString(args.Default), - Enum = args.Languages.Select(l => (Microsoft.OpenApi.Any.IOpenApiAny)new Microsoft.OpenApi.Any.OpenApiString(l)).ToList() - }; -#endif return param; } @@ -214,12 +167,8 @@ private static void PopulateDocumentTags( IEnumerable actions ) { -#if NET10_0 var existingNames = swaggerDoc.Tags?.Select(t => t.Name).ToHashSet(StringComparer.Ordinal) ?? []; -#else - var existingNames = swaggerDoc.Tags.Select(t => t.Name).ToHashSet(StringComparer.Ordinal); -#endif foreach ( var name in actions @@ -228,9 +177,7 @@ var name in actions .Where(n => !existingNames.Contains(n)) ) { -#if NET10_0 swaggerDoc.Tags ??= new HashSet(); -#endif swaggerDoc.Tags.Add(new OpenApiTag { Name = name }); } } diff --git a/src/Simplify.Web.Swagger/SimplifyWebSwaggerArgs.cs b/src/Simplify.Web.Swagger/SimplifyWebSwaggerArgs.cs index 54353d9..4aa9788 100644 --- a/src/Simplify.Web.Swagger/SimplifyWebSwaggerArgs.cs +++ b/src/Simplify.Web.Swagger/SimplifyWebSwaggerArgs.cs @@ -1,9 +1,5 @@ using System.Collections.Generic; -#if NET10_0 using Microsoft.OpenApi; -#else -using Microsoft.OpenApi.Models; -#endif namespace Simplify.Web.Swagger; diff --git a/src/TesterApp/Program.cs b/src/TesterApp/Program.cs index b8f1bd9..432bed6 100644 --- a/src/TesterApp/Program.cs +++ b/src/TesterApp/Program.cs @@ -1,12 +1,8 @@ +using Microsoft.OpenApi; using Simplify.DI; using Simplify.Web; using Simplify.Web.Swagger; using TesterApp.Setup; -#if NET10_0 -using Microsoft.OpenApi; -#else -using Microsoft.OpenApi.Models; -#endif var builder = WebApplication.CreateBuilder(args);