From 315dc8e29a523add831624fc977b5f268eaea69a Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Thu, 20 May 2021 13:58:26 +0200 Subject: [PATCH] Fix open api. --- .../Api/Config/OpenApi/OpenApiServices.cs | 2 + .../Api/Config/OpenApi/ReflectionServices.cs | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs index c9409e7ae..548513d56 100644 --- a/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs @@ -103,6 +103,8 @@ namespace Squidex.Areas.Api.Config.OpenApi { settings.AllowReferencesWithProperties = true; + settings.ReflectionService = new ReflectionServices(); + settings.TypeMappers = new List { CreateStringMap(), diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs new file mode 100644 index 000000000..f5416574f --- /dev/null +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/ReflectionServices.cs @@ -0,0 +1,38 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using Namotion.Reflection; +using NJsonSchema.Generation; +using Squidex.Infrastructure.Collections; + +namespace Squidex.Areas.Api.Config.OpenApi +{ + public class ReflectionServices : DefaultReflectionService + { + protected override bool IsArrayType(ContextualType contextualType) + { + if (contextualType.Type.IsGenericType && + contextualType.Type.GetGenericTypeDefinition() == typeof(ImmutableList<>)) + { + return true; + } + + return base.IsArrayType(contextualType); + } + + protected override bool IsDictionaryType(ContextualType contextualType) + { + if (contextualType.Type.IsGenericType && + contextualType.Type.GetGenericTypeDefinition() == typeof(ImmutableDictionary<,>)) + { + return true; + } + + return base.IsDictionaryType(contextualType); + } + } +}