From 45512dde96f9233f8f9fd03ba722f1b3cd313b3b Mon Sep 17 00:00:00 2001 From: June Rhodes Date: Sat, 23 Nov 2024 19:25:04 +1100 Subject: [PATCH] Try to fix JSON schema generation --- .../DefaultJsonSchemaGenerator.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/UET/uet/Commands/Internal/GenerateJsonSchema/DefaultJsonSchemaGenerator.cs b/UET/uet/Commands/Internal/GenerateJsonSchema/DefaultJsonSchemaGenerator.cs index da5eaaff..d87389ed 100644 --- a/UET/uet/Commands/Internal/GenerateJsonSchema/DefaultJsonSchemaGenerator.cs +++ b/UET/uet/Commands/Internal/GenerateJsonSchema/DefaultJsonSchemaGenerator.cs @@ -105,9 +105,12 @@ private static string ProcessSummary(XmlNode summary) private void GenerateSchemaForObject(Utf8JsonWriter writer, JsonTypeInfo jsonTypeInfo, JsonSerializerContext jsonTypeInfoResolver) { + var isDynamicObject = jsonTypeInfo.Type.IsConstructedGenericType && + (jsonTypeInfo.Type.GetGenericTypeDefinition() == typeof(BuildConfigDynamic<,>) || + jsonTypeInfo.Type.GetGenericTypeDefinition() == typeof(BuildConfigPredefinedDynamic<,,>)); + var properties = jsonTypeInfo.Properties; - if (jsonTypeInfo.Type.IsConstructedGenericType && - jsonTypeInfo.Type.GetGenericTypeDefinition() == typeof(BuildConfigDynamic<,>)) + if (isDynamicObject) { // Exclude dynamically driven properties for BuildConfigDynamic. properties = properties.Where(x => x.Name != "DynamicSettings" && x.Name != "Type").ToList(); @@ -147,8 +150,7 @@ private void GenerateSchemaForObject(Utf8JsonWriter writer, JsonTypeInfo jsonTyp properties); // Write out all the possible values of Type. - if (jsonTypeInfo.Type.IsConstructedGenericType && - jsonTypeInfo.Type.GetGenericTypeDefinition() == typeof(BuildConfigDynamic<,>)) + if (isDynamicObject) { var dynamicProviderType = typeof(IDynamicProvider<,>) .MakeGenericType(jsonTypeInfo.Type.GetGenericArguments()); @@ -246,8 +248,7 @@ private void GenerateSchemaForObject(Utf8JsonWriter writer, JsonTypeInfo jsonTyp } writer.WriteEndArray(); } - else if (jsonTypeInfo.Type.IsConstructedGenericType && - jsonTypeInfo.Type.GetGenericTypeDefinition() == typeof(BuildConfigDynamic<,>)) + else if (isDynamicObject) { writer.WritePropertyName("allOf"); writer.WriteStartArray();