Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ec6d63f
feat: enhance JSON schema generation with $defs support for complex t…
IvanMurzak Oct 16, 2025
c1736e9
feat: enhance nullability checks for Task<T> and ValueTask<T> return …
IvanMurzak Oct 16, 2025
01c6f44
feat: add support for nullable Task<T?> return types in JSON schema g…
IvanMurzak Oct 16, 2025
5921a94
Refactor return schema tests to use theory data-driven approach
IvanMurzak Oct 16, 2025
18a0859
fix: update cSpell configuration in settings.json and clean up unused…
IvanMurzak Oct 16, 2025
8e04b6e
feat: add complex return type tests and assertion method for JSON sch…
IvanMurzak Oct 16, 2025
5eebfa0
feat: add AssertResultRequired method for non-nullable return type sc…
IvanMurzak Oct 16, 2025
39621f8
feat: enhance GetReturnSchemaForMethod to log return schema details
IvanMurzak Oct 16, 2025
73db3b0
feat: add Echo method to WrapperClass for value return functionality
IvanMurzak Oct 16, 2025
6fbb246
feat: add Echo and EchoNullable methods to WrapperClass for return ty…
IvanMurzak Oct 16, 2025
2126ad5
feat: add Address, Company, and Person classes for model representation
IvanMurzak Oct 16, 2025
5d669d6
feat: add tests for OuterAssembly types in ReturnSchemaTests to valid…
IvanMurzak Oct 16, 2025
2183e65
feat: add AssertResultDefines method to validate expected types in sc…
IvanMurzak Oct 16, 2025
d0a5925
fix: update schema validation logic to require both definition and re…
IvanMurzak Oct 16, 2025
b6b1557
feat: enhance schema generation by recursively collecting nested non-…
IvanMurzak Oct 16, 2025
5c8684f
Refactor schema type ID handling and enhance tests
IvanMurzak Oct 17, 2025
4ac71b9
feat: add AssertAllRefsDefined method to validate $ref references in …
IvanMurzak Oct 17, 2025
4cfd934
feat: Introduce JSON Schema Converter Interface and Implementations
IvanMurzak Oct 22, 2025
09db9f5
fix: improve nullability handling for method return types in schema g…
IvanMurzak Oct 22, 2025
b3db32d
Update ReflectorNet/src/Convertor/Json/JsonSchemaConverter.cs
IvanMurzak Oct 22, 2025
9c8265b
Update ReflectorNet/src/Utils/Json/JsonSchema.cs
IvanMurzak Oct 22, 2025
938f1fc
Update ReflectorNet.Tests/SchemaTests/TestType.cs
IvanMurzak Oct 22, 2025
f664124
refactor: remove redundant placeholder comments in schema generation …
IvanMurzak Oct 22, 2025
67fac97
fix: enhance null check for schema definitions in JsonSchema generation
IvanMurzak Oct 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"unstringified",
"Unstringify"
"Unstringify",
"Xunit"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ jsonSerializer.AddConverter(new MyCustomJsonConverter());

// Access to JSON schema generation
var jsonSchema = reflector.JsonSchema;
var schema = jsonSchema.GetSchema<MyClass>(reflector, justRef: false);
var schema = jsonSchema.GetSchema<MyClass>(reflector);
```

#### Converter System Architecture
Expand Down
11 changes: 11 additions & 0 deletions ReflectorNet.Tests.OuterAssembly/Model/Complex_Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Complex class: Address with multiple properties
namespace com.IvanMurzak.ReflectorNet.OuterAssembly.Model
{
public class Address
{
public string Street { get; set; } = string.Empty;
public string City { get; set; } = string.Empty;
public string? Zip { get; set; }
public string Country { get; set; } = string.Empty;
}
}
14 changes: 14 additions & 0 deletions ReflectorNet.Tests.OuterAssembly/Model/Complex_Company.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Complex class: Company with nested collections and references
using System.Collections.Generic;

namespace com.IvanMurzak.ReflectorNet.OuterAssembly.Model
{
public class Company
{
public string Name { get; set; } = string.Empty;
public Address? Headquarters { get; set; }
public List<Person> Employees { get; } = new List<Person>();
public Dictionary<string, List<Person>> Teams { get; } = new Dictionary<string, List<Person>>();
public Dictionary<string, Dictionary<string, Person>> Directory { get; } = new();
}
}
32 changes: 32 additions & 0 deletions ReflectorNet.Tests.OuterAssembly/Model/Complex_Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Complex class: Person with mixed fields/properties and nested types
using System;
using System.Collections.Generic;

namespace com.IvanMurzak.ReflectorNet.OuterAssembly.Model
{
public class Person
{
// Fields
public string FirstName = string.Empty;
public string LastName = string.Empty;
private DateTime _birthDate;

// Properties
public int Age { get; set; }
public Address? Address { get; set; }
public List<string> Tags { get; } = new List<string>();
public Dictionary<string, int> Scores { get; } = new Dictionary<string, int>();

// Arrays
public int[] Numbers { get; set; } = Array.Empty<int>();
public string[][] JaggedAliases { get; set; } = Array.Empty<string[]>();
public int[,] Matrix2x2 { get; set; } = new int[2, 2];

// Methods using primitives and collections
public void SetBirthDate(DateTime date) => _birthDate = date;
public DateTime GetBirthDate() => _birthDate;

public void AddTag(string tag) => Tags.Add(tag);
public void SetScore(string key, int value) => Scores[key] = value;
}
}
19 changes: 19 additions & 0 deletions ReflectorNet.Tests.OuterAssembly/Model/NestedClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,24 @@ public class WrapperClass<T>
[JsonInclude]
public T? ValueField;
public T? ValueProperty { get; set; }

public WrapperClass() { }
public WrapperClass(T? valueField, T? valueProperty)
{
ValueField = valueField;
ValueProperty = valueProperty;
}

/// <summary>
/// Echo method that returns the provided value unchanged.
/// Used for testing return type schemas with various generic types.
/// </summary>
public T Echo(T value) => value;

/// <summary>
/// Echo method that returns a nullable version of the provided value.
/// Used for testing return type schemas with nullable generic types.
/// </summary>
public T? EchoNullable(T? value) => value;
}
}
3 changes: 2 additions & 1 deletion ReflectorNet.Tests/JsonConverterTests/JsonConverterTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using com.IvanMurzak.ReflectorNet.Tests.Model;
using com.IvanMurzak.ReflectorNet.OuterAssembly.Model;
using com.IvanMurzak.ReflectorNet.Tests.Model;
using Xunit.Abstractions;

namespace com.IvanMurzak.ReflectorNet.Tests.Utils
Expand Down
9 changes: 4 additions & 5 deletions ReflectorNet.Tests/Model/JsonConvertors/ObjectRefConverter.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using com.IvanMurzak.ReflectorNet.Json;
using com.IvanMurzak.ReflectorNet.Utils;

namespace com.IvanMurzak.ReflectorNet.Tests.Model
{
public class ObjectRefConverter : JsonConverter<ObjectRef>, IJsonSchemaConverter
public class ObjectRefConverter : JsonSchemaConverter<ObjectRef>, IJsonSchemaConverter
{
public string Id => typeof(ObjectRef).GetTypeId();
public JsonNode GetScheme() => new JsonObject
public override JsonNode GetSchema() => new JsonObject
{
[JsonSchema.Type] = JsonSchema.Object,
[JsonSchema.Properties] = new JsonObject
Expand All @@ -21,7 +20,7 @@ public class ObjectRefConverter : JsonConverter<ObjectRef>, IJsonSchemaConverter
},
[JsonSchema.Required] = new JsonArray { nameof(ObjectRef.instanceID) }
};
public JsonNode GetSchemeRef() => new JsonObject
public override JsonNode GetSchemaRef() => new JsonObject
{
[JsonSchema.Ref] = JsonSchema.RefValue + Id
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using com.IvanMurzak.ReflectorNet.Json;
using com.IvanMurzak.ReflectorNet.Model;
using com.IvanMurzak.ReflectorNet.Utils;

namespace com.IvanMurzak.ReflectorNet.Tests.Model
{
public class SerializedMemberCustomDescriptionConverter : JsonConverter<SerializedMember>, IJsonSchemaConverter
public class SerializedMemberCustomDescriptionConverter : JsonSchemaConverter<SerializedMember>, IJsonSchemaConverter
{
public const string CustomDescription = "Custom description, used for testing purposes.";

public static string StaticId => TypeUtils.GetTypeId<SerializedMember>();
public static JsonNode Schema => new JsonObject
{
[JsonSchema.Type] = JsonSchema.Object,
Expand Down Expand Up @@ -64,15 +62,13 @@ public class SerializedMemberCustomDescriptionConverter : JsonConverter<Serializ

readonly Reflector _reflector;

public string Id => StaticId;

public SerializedMemberCustomDescriptionConverter(Reflector reflector)
{
_reflector = reflector ?? throw new ArgumentNullException(nameof(reflector));
}

public JsonNode GetSchemeRef() => SchemaRef;
public JsonNode GetScheme() => Schema;
public override JsonNode GetSchemaRef() => SchemaRef;
public override JsonNode GetSchema() => Schema;

public override SerializedMember? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Expand Down
56 changes: 0 additions & 56 deletions ReflectorNet.Tests/Model/NestedClass.cs

This file was deleted.

2 changes: 1 addition & 1 deletion ReflectorNet.Tests/ReflectorTests/DeserializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Text;
using com.IvanMurzak.ReflectorNet.Utils;
using com.IvanMurzak.ReflectorNet.Tests.Model;
using Xunit.Abstractions;
using com.IvanMurzak.ReflectorNet.Model;
using System.Collections.Generic;
using System;
using com.IvanMurzak.ReflectorNet.OuterAssembly.Model;

namespace com.IvanMurzak.ReflectorNet.Tests.Utils
{
Expand Down
1 change: 1 addition & 0 deletions ReflectorNet.Tests/ReflectorTests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using com.IvanMurzak.ReflectorNet.Utils;
using com.IvanMurzak.ReflectorNet.Tests.Model;
using Xunit.Abstractions;
using com.IvanMurzak.ReflectorNet.OuterAssembly.Model;

namespace com.IvanMurzak.ReflectorNet.Tests.Utils
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using com.IvanMurzak.ReflectorNet.Tests.Model;
using Xunit.Abstractions;
using System;
using com.IvanMurzak.ReflectorNet.OuterAssembly.Model;

namespace com.IvanMurzak.ReflectorNet.Tests.Utils
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using com.IvanMurzak.ReflectorNet.Tests.Model;
using Xunit.Abstractions;
using System;
using com.IvanMurzak.ReflectorNet.OuterAssembly.Model;

namespace com.IvanMurzak.ReflectorNet.Tests.Utils
{
Expand Down
3 changes: 2 additions & 1 deletion ReflectorNet.Tests/SchemaTests/CollectionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using com.IvanMurzak.ReflectorNet.Model;
using com.IvanMurzak.ReflectorNet.Utils;
using Xunit.Abstractions;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void GetTypeId_SimpleArray_ShouldAppendArray()
{
var result = reflector.GetSchema(type);

_output.WriteLine($"Type: {type.GetTypeShortName()}\n{result.ToJsonString()}\n");
_output.WriteLine($"Type: {type.GetTypeShortName()}\n{result.ToJsonString(new JsonSerializerOptions { WriteIndented = true })}\n");

// Assert
Assert.NotNull(result);
Expand Down
4 changes: 2 additions & 2 deletions ReflectorNet.Tests/SchemaTests/PerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Reflector_Introspection_Tests()
var testType = typeof(GameObjectRef);

// Act - Test introspection capabilities
var schema = testType.GetSchema(reflector, justRef: false);
var schema = testType.GetSchema(reflector);
var typeId = testType.GetTypeId();

// Assert
Expand Down Expand Up @@ -133,7 +133,7 @@ public void JsonUtils_Comprehensive_Tests()
var serializedJson = reflector.JsonSerializer.Serialize(testObject);
var deserializedObject = reflector.JsonSerializer.Deserialize<GameObjectRefList>(serializedJson);

var schema = reflector.GetSchema(typeof(GameObjectRefList), justRef: false);
var schema = reflector.GetSchema(typeof(GameObjectRefList));
var argumentsSchema = reflector.GetArgumentsSchema(
typeof(MethodHelper).GetMethod(nameof(MethodHelper.ListObject_ListObject))!);

Expand Down
Loading