From 204074c871dd29dcd6898bc3b03dd06d41dc73c0 Mon Sep 17 00:00:00 2001 From: Bart Koelman <10324372+bkoelman@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:31:48 +0100 Subject: [PATCH 1/2] Mark AddOpenApiForJsonApi with [Experimental] --- docs/usage/openapi.md | 3 +++ src/Examples/JsonApiDotNetCoreExample/Program.cs | 2 ++ .../ServiceCollectionExtensions.cs | 8 +++++--- test/OpenApiTests/OpenApiStartup.cs | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/usage/openapi.md b/docs/usage/openapi.md index 870caa2e97..9d40cb5fea 100644 --- a/docs/usage/openapi.md +++ b/docs/usage/openapi.md @@ -7,6 +7,9 @@ Exposing an [OpenAPI document](https://swagger.io/specification/) for your JSON: The [JsonApiDotNetCore.OpenApi.Swashbuckle](https://github.com/json-api-dotnet/JsonApiDotNetCore/pkgs/nuget/JsonApiDotNetCore.OpenApi.Swashbuckle) NuGet package provides OpenAPI support for JSON:API by integrating with [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore). +> [!WARNING] +> OpenAPI support for JSON:API is currently experimental. The API and the structure of the OpenAPI document may change in future versions. + ## Getting started 1. Install the `JsonApiDotNetCore.OpenApi.Swashbuckle` NuGet package: diff --git a/src/Examples/JsonApiDotNetCoreExample/Program.cs b/src/Examples/JsonApiDotNetCoreExample/Program.cs index 56448b271e..d2677ea781 100644 --- a/src/Examples/JsonApiDotNetCoreExample/Program.cs +++ b/src/Examples/JsonApiDotNetCoreExample/Program.cs @@ -79,7 +79,9 @@ static void ConfigureServices(WebApplicationBuilder builder) using (CodeTimingSessionManager.Current.Measure("AddOpenApiForJsonApi()")) { +#pragma warning disable JADNC_OA_001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. builder.Services.AddOpenApiForJsonApi(options => options.DocumentFilter()); +#pragma warning restore JADNC_OA_001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. } } diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/ServiceCollectionExtensions.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/ServiceCollectionExtensions.cs index 173fb9b1d3..9b123606c7 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/ServiceCollectionExtensions.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiMetadata; using JsonApiDotNetCore.OpenApi.Swashbuckle.SchemaGenerators; using JsonApiDotNetCore.OpenApi.Swashbuckle.SchemaGenerators.Bodies; @@ -18,7 +19,8 @@ public static class ServiceCollectionExtensions /// /// Configures OpenAPI for JsonApiDotNetCore using Swashbuckle. /// - public static void AddOpenApiForJsonApi(this IServiceCollection services, Action? setupSwaggerGenAction = null) + [Experimental("JADNC_OA_001", UrlFormat = "https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/openapi/docs/usage/openapi.md")] + public static void AddOpenApiForJsonApi(this IServiceCollection services, Action? configureSwaggerGenOptions = null) { ArgumentNullException.ThrowIfNull(services); @@ -26,9 +28,9 @@ public static void AddOpenApiForJsonApi(this IServiceCollection services, Action AddCustomSwaggerComponents(services); AddSwaggerGenerator(services); - if (setupSwaggerGenAction != null) + if (configureSwaggerGenOptions != null) { - services.Configure(setupSwaggerGenAction); + services.Configure(configureSwaggerGenOptions); } } diff --git a/test/OpenApiTests/OpenApiStartup.cs b/test/OpenApiTests/OpenApiStartup.cs index bc5f50ffe6..ba0a5256ca 100644 --- a/test/OpenApiTests/OpenApiStartup.cs +++ b/test/OpenApiTests/OpenApiStartup.cs @@ -15,7 +15,9 @@ public override void ConfigureServices(IServiceCollection services) { base.ConfigureServices(services); +#pragma warning disable JADNC_OA_001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. services.AddOpenApiForJsonApi(SetupSwaggerGenAction); +#pragma warning restore JADNC_OA_001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. } protected override void SetJsonApiOptions(JsonApiOptions options) From 55faea648b451d741a4fd1246499f3f4c00bc34e Mon Sep 17 00:00:00 2001 From: Bart Koelman <10324372+bkoelman@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:37:07 +0100 Subject: [PATCH 2/2] Replace UnreachableCodeException with built-in UnreachableException --- .../JsonApiClient.cs | 5 +++-- .../UnreachableCodeException.cs | 6 ------ .../JsonApiActionDescriptorCollectionProvider.cs | 3 ++- .../JsonApiMetadata/JsonApiEndpointMetadataProvider.cs | 3 ++- .../JsonApiRequestFormatMetadataProvider.cs | 3 ++- .../OpenApiEndpointConvention.cs | 7 ++++--- .../OpenApiOperationIdSelector.cs | 7 ++++--- .../OpenApiSchemaExtensions.cs | 3 ++- .../Bodies/AtomicOperationsBodySchemaGenerator.cs | 9 +++++---- .../Components/AbstractAtomicOperationSchemaGenerator.cs | 3 ++- .../Components/AbstractResourceDataSchemaGenerator.cs | 3 ++- .../Components/DataContainerSchemaGenerator.cs | 5 +++-- .../Components/RelationshipIdentifierSchemaGenerator.cs | 3 ++- .../SchemaGenerators/JsonApiSchemaGenerator.cs | 3 ++- .../DocumentationOpenApiOperationFilter.cs | 3 ++- .../SwaggerComponents/ResourceFieldSchemaBuilder.cs | 5 +++-- .../SwaggerComponents/StringEnumOrderingFilter.cs | 3 ++- .../UnreachableCodeException.cs | 6 ------ 18 files changed, 42 insertions(+), 38 deletions(-) delete mode 100644 src/JsonApiDotNetCore.OpenApi.Client.NSwag/UnreachableCodeException.cs delete mode 100644 src/JsonApiDotNetCore.OpenApi.Swashbuckle/UnreachableCodeException.cs diff --git a/src/JsonApiDotNetCore.OpenApi.Client.NSwag/JsonApiClient.cs b/src/JsonApiDotNetCore.OpenApi.Client.NSwag/JsonApiClient.cs index 2c1603bbdb..72cbdce08a 100644 --- a/src/JsonApiDotNetCore.OpenApi.Client.NSwag/JsonApiClient.cs +++ b/src/JsonApiDotNetCore.OpenApi.Client.NSwag/JsonApiClient.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Linq.Expressions; using System.Reflection; using Newtonsoft.Json; @@ -175,7 +176,7 @@ public override bool CanConvert(Type objectType) public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) @@ -236,7 +237,7 @@ public override bool CanConvert(Type objectType) public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) diff --git a/src/JsonApiDotNetCore.OpenApi.Client.NSwag/UnreachableCodeException.cs b/src/JsonApiDotNetCore.OpenApi.Client.NSwag/UnreachableCodeException.cs deleted file mode 100644 index 7bf33d1528..0000000000 --- a/src/JsonApiDotNetCore.OpenApi.Client.NSwag/UnreachableCodeException.cs +++ /dev/null @@ -1,6 +0,0 @@ -#pragma warning disable CA1064 // Exceptions should be public - -namespace JsonApiDotNetCore.OpenApi.Client.NSwag; - -internal sealed class UnreachableCodeException() - : Exception("This code should not be reachable."); diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiActionDescriptorCollectionProvider.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiActionDescriptorCollectionProvider.cs index c145067bb3..c99384f7b8 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiActionDescriptorCollectionProvider.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiActionDescriptorCollectionProvider.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Reflection; using JsonApiDotNetCore.Errors; using JsonApiDotNetCore.Middleware; @@ -125,7 +126,7 @@ private static void UpdateProducesResponseTypeAttribute(ActionDescriptor endpoin } } - throw new UnreachableCodeException(); + throw new UnreachableException(); } private static bool ProducesJsonApiResponseDocument(ActionDescriptor endpoint) diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/JsonApiEndpointMetadataProvider.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/JsonApiEndpointMetadataProvider.cs index 85ae85482d..7d69df49a4 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/JsonApiEndpointMetadataProvider.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiMetadata/JsonApiEndpointMetadataProvider.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Reflection; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Controllers; @@ -45,7 +46,7 @@ public JsonApiEndpointMetadataContainer Get(MethodInfo controllerAction) if (primaryResourceType == null) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } IJsonApiRequestMetadata? requestMetadata = GetRequestMetadata(endpoint, primaryResourceType); diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiRequestFormatMetadataProvider.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiRequestFormatMetadataProvider.cs index 08e2844f83..6def822bd9 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiRequestFormatMetadataProvider.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/JsonApiRequestFormatMetadataProvider.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using JsonApiDotNetCore.Middleware; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Formatters; @@ -18,7 +19,7 @@ public bool CanRead(InputFormatterContext context) /// public Task ReadAsync(InputFormatterContext context) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } /// diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiEndpointConvention.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiEndpointConvention.cs index 745c435ee5..8a1d8d19a2 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiEndpointConvention.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiEndpointConvention.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Net; using System.Reflection; using JsonApiDotNetCore.Configuration; @@ -108,7 +109,7 @@ private static bool IsEndpointAvailable(JsonApiEndpoints endpoint, ResourceType JsonApiEndpoints.PatchRelationship => availableEndpoints.HasFlag(JsonApiEndpoints.PatchRelationship), JsonApiEndpoints.Delete => availableEndpoints.HasFlag(JsonApiEndpoints.Delete), JsonApiEndpoints.DeleteRelationship => availableEndpoints.HasFlag(JsonApiEndpoints.DeleteRelationship), - _ => throw new UnreachableCodeException() + _ => throw new UnreachableException() }; } @@ -178,7 +179,7 @@ private static HttpStatusCode[] GetSuccessStatusCodesForEndpoint(JsonApiEndpoint [ HttpStatusCode.NoContent ], - _ => throw new UnreachableCodeException() + _ => throw new UnreachableException() }; } @@ -236,7 +237,7 @@ private HttpStatusCode[] GetErrorStatusCodesForEndpoint(JsonApiEndpointWrapper e HttpStatusCode.NotFound, HttpStatusCode.Conflict ], - _ => throw new UnreachableCodeException() + _ => throw new UnreachableException() }; } diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiOperationIdSelector.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiOperationIdSelector.cs index 9c5552350a..5596b3a681 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiOperationIdSelector.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiOperationIdSelector.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Reflection; using System.Text.Json; using Humanizer; @@ -66,7 +67,7 @@ private static string GetTemplate(ApiDescription endpoint) if (!SchemaOpenTypeToOpenApiOperationIdTemplateMap.TryGetValue(bodyType, out string? template)) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } return template; @@ -78,7 +79,7 @@ private static Type GetBodyType(ApiDescription endpoint) if (producesResponseTypeAttribute == null) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } ControllerParameterDescriptor? requestBodyDescriptor = endpoint.ActionDescriptor.GetBodyParameterDescriptor(); @@ -96,7 +97,7 @@ private string ApplyTemplate(string openApiOperationIdTemplate, ResourceType? re { if (endpoint.RelativePath == null || endpoint.HttpMethod == null) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } string method = endpoint.HttpMethod.ToLowerInvariant(); diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiSchemaExtensions.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiSchemaExtensions.cs index 967ab69188..aa0e24e39a 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiSchemaExtensions.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/OpenApiSchemaExtensions.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Microsoft.OpenApi.Models; namespace JsonApiDotNetCore.OpenApi.Swashbuckle; @@ -21,7 +22,7 @@ public static void ReorderProperties(this OpenApiSchema fullSchema, IEnumerable< if (fullSchema.Properties.Count != propertiesInOrder.Count) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } fullSchema.Properties = propertiesInOrder; diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Bodies/AtomicOperationsBodySchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Bodies/AtomicOperationsBodySchemaGenerator.cs index 288df2a007..a33993a71c 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Bodies/AtomicOperationsBodySchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Bodies/AtomicOperationsBodySchemaGenerator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using JsonApiDotNetCore.AtomicOperations; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.Middleware; @@ -121,7 +122,7 @@ private void GenerateSchemaForResourceOperation(Type operationOpenType, Resource AtomicOperationCode.Add => WriteOperationKind.CreateResource, AtomicOperationCode.Update => WriteOperationKind.UpdateResource, AtomicOperationCode.Remove => WriteOperationKind.DeleteResource, - _ => throw new UnreachableCodeException() + _ => throw new UnreachableException() }; if (!_atomicOperationFilter.IsEnabled(resourceType, writeOperation)) @@ -158,7 +159,7 @@ private void GenerateSchemaForRelationshipOperation(Type operationOpenType, Rela AtomicOperationCode.Add => WriteOperationKind.AddToRelationship, AtomicOperationCode.Update => WriteOperationKind.SetRelationship, AtomicOperationCode.Remove => WriteOperationKind.RemoveFromRelationship, - _ => throw new UnreachableCodeException() + _ => throw new UnreachableException() }; if (!_atomicOperationFilter.IsEnabled(relationship.LeftType, writeOperation)) @@ -211,7 +212,7 @@ private static bool IsToOneRelationshipEnabled(HasOneAttribute relationship, Wri return writeOperation switch { WriteOperationKind.SetRelationship => relationship.Capabilities.HasFlag(HasOneCapabilities.AllowSet), - _ => throw new UnreachableCodeException() + _ => throw new UnreachableException() }; } @@ -222,7 +223,7 @@ private static bool IsToManyRelationshipEnabled(HasManyAttribute relationship, W WriteOperationKind.SetRelationship => relationship.Capabilities.HasFlag(HasManyCapabilities.AllowSet), WriteOperationKind.AddToRelationship => relationship.Capabilities.HasFlag(HasManyCapabilities.AllowAdd), WriteOperationKind.RemoveFromRelationship => relationship.Capabilities.HasFlag(HasManyCapabilities.AllowRemove), - _ => throw new UnreachableCodeException() + _ => throw new UnreachableException() }; } diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractAtomicOperationSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractAtomicOperationSchemaGenerator.cs index 6ba9a3868c..bd0869614c 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractAtomicOperationSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractAtomicOperationSchemaGenerator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.AtomicOperations; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; @@ -74,7 +75,7 @@ public void MapDiscriminator(OpenApiSchema referenceSchemaForOperation, string d if (!schemaRepository.TryLookupByType(AtomicOperationAbstractType, out OpenApiSchema? referenceSchemaForAbstractOperation)) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } OpenApiSchema fullSchemaForAbstractOperation = schemaRepository.Schemas[referenceSchemaForAbstractOperation.Reference.Id]; diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractResourceDataSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractResourceDataSchemaGenerator.cs index 24aae5bf80..1d47701863 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractResourceDataSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/AbstractResourceDataSchemaGenerator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.ResourceObjects; using JsonApiDotNetCore.OpenApi.Swashbuckle.SwaggerComponents; @@ -97,7 +98,7 @@ public void MapDiscriminator(Type resourceDataConstructedType, OpenApiSchema ref { if (!schemaRepository.TryLookupByType(ResourceDataAbstractType, out OpenApiSchema? referenceSchemaForAbstractResourceData)) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } OpenApiSchema fullSchemaForAbstractResourceData = schemaRepository.Schemas[referenceSchemaForAbstractResourceData.Reference.Id]; diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/DataContainerSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/DataContainerSchemaGenerator.cs index 419a6a53ca..c1dcfeb965 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/DataContainerSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/DataContainerSchemaGenerator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Reflection; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.ResourceObjects; @@ -75,7 +76,7 @@ private static Type GetElementTypeOfDataProperty(Type dataContainerConstructedTy if (dataProperty == null) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } Type innerPropertyType = dataProperty.PropertyType.ConstructedToOpenType().IsAssignableTo(typeof(ICollection<>)) @@ -89,7 +90,7 @@ private static Type GetElementTypeOfDataProperty(Type dataContainerConstructedTy if (!innerPropertyType.IsGenericType) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } return innerPropertyType; diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/RelationshipIdentifierSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/RelationshipIdentifierSchemaGenerator.cs index 303270c305..5f9fecf402 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/RelationshipIdentifierSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/Components/RelationshipIdentifierSchemaGenerator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using JsonApiDotNetCore.Configuration; using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.ResourceObjects; using JsonApiDotNetCore.Resources.Annotations; @@ -54,7 +55,7 @@ public OpenApiSchema GenerateSchema(RelationshipAttribute relationship, SchemaRe if (schemaRepository.TryLookupByType(relationshipIdentifierConstructedType, out _)) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } OpenApiSchema referenceSchemaForIdentifier = _defaultSchemaGenerator.GenerateSchema(relationshipIdentifierConstructedType, schemaRepository); diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/JsonApiSchemaGenerator.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/JsonApiSchemaGenerator.cs index 56a2211166..743878336a 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/JsonApiSchemaGenerator.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SchemaGenerators/JsonApiSchemaGenerator.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Reflection; using JsonApiDotNetCore.Controllers; using JsonApiDotNetCore.OpenApi.Swashbuckle.SchemaGenerators.Bodies; @@ -61,6 +62,6 @@ private BodySchemaGenerator GetBodySchemaGenerator(Type modelType) } } - throw new UnreachableCodeException(); + throw new UnreachableException(); } } diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/DocumentationOpenApiOperationFilter.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/DocumentationOpenApiOperationFilter.cs index 415738fc55..a539baa9d2 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/DocumentationOpenApiOperationFilter.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/DocumentationOpenApiOperationFilter.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Net; using System.Reflection; using Humanizer; @@ -437,7 +438,7 @@ private static RelationshipAttribute GetRelationshipFromRoute(ApiDescription api { if (apiDescription.RelativePath == null) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } string relationshipName = apiDescription.RelativePath.Split('/').Last(); diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/ResourceFieldSchemaBuilder.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/ResourceFieldSchemaBuilder.cs index 001d2a9fe2..a4cdcf07ce 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/ResourceFieldSchemaBuilder.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/ResourceFieldSchemaBuilder.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Reflection; using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiMetadata; using JsonApiDotNetCore.OpenApi.Swashbuckle.JsonApiObjects.ResourceObjects; @@ -109,7 +110,7 @@ private static AttrCapabilities GetRequiredCapabilityForAttributes(Type resource { return resourceDataOpenType == typeof(ResourceDataInResponse<>) ? AttrCapabilities.AllowView : resourceDataOpenType == typeof(DataInCreateResourceRequest<>) ? AttrCapabilities.AllowCreate : - resourceDataOpenType == typeof(DataInUpdateResourceRequest<>) ? AttrCapabilities.AllowChange : throw new UnreachableCodeException(); + resourceDataOpenType == typeof(DataInUpdateResourceRequest<>) ? AttrCapabilities.AllowChange : throw new UnreachableException(); } private void EnsureAttributeSchemaIsExposed(OpenApiSchema referenceSchemaForAttribute, AttrAttribute attribute, SchemaRepository schemaRepository) @@ -219,7 +220,7 @@ private static void AssertHasNoProperties(OpenApiSchema fullSchema) { if (fullSchema.Properties.Count > 0) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } } } diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/StringEnumOrderingFilter.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/StringEnumOrderingFilter.cs index 022e3ca384..0a610bba27 100644 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/StringEnumOrderingFilter.cs +++ b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/SwaggerComponents/StringEnumOrderingFilter.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using JetBrains.Annotations; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; @@ -52,7 +53,7 @@ private static void OrderEnumMembers(OpenApiSchema schema) if (ordered.Count != schema.Enum.Count) { - throw new UnreachableCodeException(); + throw new UnreachableException(); } schema.Enum = ordered; diff --git a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/UnreachableCodeException.cs b/src/JsonApiDotNetCore.OpenApi.Swashbuckle/UnreachableCodeException.cs deleted file mode 100644 index ecd1d7a74a..0000000000 --- a/src/JsonApiDotNetCore.OpenApi.Swashbuckle/UnreachableCodeException.cs +++ /dev/null @@ -1,6 +0,0 @@ -#pragma warning disable CA1064 // Exceptions should be public - -namespace JsonApiDotNetCore.OpenApi.Swashbuckle; - -internal sealed class UnreachableCodeException() - : Exception("This code should not be reachable.");