Skip to content

Commit

Permalink
Try to fix JSON schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
hach-que committed Nov 23, 2024
1 parent 51cdc9b commit 45512dd
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 45512dd

Please sign in to comment.