From 77f8f8f28f1dbfd014221c3c03bebe44a28849b9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 21 Jun 2021 14:35:47 +0200 Subject: [PATCH] More JSON fixes. --- .../Commands/Implementation/Sync/JsonHelper.cs | 11 +++++------ .../Squidex.ClientLibrary/ContentsClient.cs | 2 +- .../Squidex.ClientLibrary/Management/Custom.cs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/JsonHelper.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/JsonHelper.cs index 9412cd5f..61b75fb3 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/JsonHelper.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/JsonHelper.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; using NJsonSchema; @@ -43,12 +44,13 @@ public JsonHelper() ContractResolver = new CamelCaseExceptDictionaryKeysResolver() }; + jsonSerializerSettings.Converters.Add(new StringEnumConverter()); jsonSerializerSettings.Formatting = Formatting.Indented; jsonSchemaGeneratorSettings = new JsonSchemaGeneratorSettings { FlattenInheritanceHierarchy = true, - SchemaType = SchemaType.JsonSchema, + SchemaType = SchemaType.OpenApi3, SchemaNameGenerator = new DefaultSchemaNameGenerator(), SerializerSettings = jsonSerializerSettings }; @@ -104,12 +106,9 @@ public void WriteSchema(Stream stream) { using (var textWriter = new StreamWriter(stream)) { - using (var jsonWriter = new JsonTextWriter(textWriter)) - { - var obj = GetSchema(); + var schema = GetSchema(); - jsonSerializer.Serialize(jsonWriter, obj); - } + textWriter.Write(schema.ToJson()); } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs index 9afb9186..a9d16025 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs @@ -56,7 +56,7 @@ public Task GetAllAsync(int batchSize, Func callback, QueryContex /// public async Task GetAllAsync(Func callback, int batchSize = 200, QueryContext context = null, CancellationToken ct = default) { - Guard.Between(10, batchSize, 10_000, nameof(batchSize)); + Guard.Between(batchSize, 10, 10_000, nameof(batchSize)); Guard.NotNull(callback, nameof(callback)); var query = new ContentQuery { Top = batchSize }; diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Custom.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Custom.cs index 907d4734..dd603b11 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Custom.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Custom.cs @@ -210,7 +210,7 @@ public Task GetAssetsAsync(string app, AssetQuery query = null, Cance /// public async Task GetAllAsync(string app, Func callback, int batchSize = 200, CancellationToken cancellationToken = default) { - Guard.Between(10, batchSize, 10_000, nameof(batchSize)); + Guard.Between(batchSize, 10, 10_000, nameof(batchSize)); Guard.NotNull(callback, nameof(callback)); var query = new AssetQuery { Top = batchSize, Skip = 0 };