Skip to content

Feat/schema test coverage#79

Closed
lior1997k wants to merge 6 commits intoIvanMurzak:mainfrom
lior1997k:feat/schema-test-coverage
Closed

Feat/schema test coverage#79
lior1997k wants to merge 6 commits intoIvanMurzak:mainfrom
lior1997k:feat/schema-test-coverage

Conversation

@lior1997k
Copy link
Copy Markdown

Here's a PR description for feat/schema-test-coverage:

Summary
This PR significantly expands JSON Schema test coverage for nested class scenarios, ensuring that $defs keys and $ref URI references remain valid for complex C# type hierarchies.

Motivation
Following the fix for + symbol sanitization in nested class names (#78), there was limited test coverage for:

Deeply nested classes (A.B.C.D)
Generic nested classes (Outer.Inner)
Schema generation validation for nested types
Cross-assembly nested type resolution
Changes
New Test Types (ReflectorNet.Tests.OuterAssembly)
LevelOne.LevelTwo.LevelThree.LevelFour — deeply nested class hierarchy
GenericOuter.GenericInner — generic nested classes with self-referencing
Type ID Sanitization Tests (TestSchemaTypeId.cs)
GetSchemaTypeId_NestedClass_ShouldEncodePlusSymbol — verifies + → %2B
GetSchemaTypeId_DeeplyNestedClass_ShouldEncodeAllPlusSymbols — verifies multiple + encoding
GetSchemaTypeId_GenericNestedClass_ShouldEncodePlusAndAngleBrackets — verifies +, <, > all encoded
Schema Generation Tests (NestedClassSchemaTests.cs)
Schema generation for nested, deeply nested, and generic nested classes
$defs key validation for deeply nested hierarchies
Return schema, argument schema, and array schema tests
Cross-assembly nested class schema validation
Self-referencing generic nested class schema validation
Verification
All 1438 tests pass (27 new, 1411 existing)
No breaking changes
No public API changes

lior1997k and others added 3 commits May 2, 2026 16:38
GetSchemaTypeId() now percent-encodes [ ] < > characters in type IDs to produce valid JSON Schema $ref URI-reference keys. This fixes invalid $defs keys like System.String[] and IEnumerable<System.Int32> which violate RFC 3986.

Also updates TestSchemaTypeId assertions to match the new sanitized output.

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@IvanMurzak IvanMurzak requested a review from Copilot May 4, 2026 07:50
@IvanMurzak IvanMurzak added bug Something isn't working enhancement New feature or request labels May 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands JSON Schema-related test coverage for nested, deeply nested, and generic nested C# types, and adjusts the schema type-id generation used for $defs keys and $ref targets to use percent-encoded identifiers.

Changes:

  • Updated TypeUtils.GetSchemaTypeId to return a percent-encoded form of GetTypeId (encoding [], <>, and +).
  • Added/updated tests validating GetSchemaTypeId output for nested types, generics, and arrays.
  • Added new nested and generic nested model types in the outer test assembly and introduced schema generation tests covering $defs and $ref validity for nested scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ReflectorNet/src/Utils/TypeUtils.Name.cs Changes schema type-id generation to return percent-encoded IDs used by schema $defs/$ref.
ReflectorNet.Tests/src/SchemaTests/TestSchemaTypeId.cs Extends and updates assertions for encoded schema type IDs (nested, deeply nested, generic nested, arrays, generics).
ReflectorNet.Tests/src/SchemaTests/NestedClassSchemaTests.cs Adds new schema generation tests ensuring nested-type schemas produce resolvable refs/defs and expected properties.
ReflectorNet.Tests.OuterAssembly/src/Model/NestedClass.cs Adds deeply nested and generic nested model types used by the new schema tests.

Comment on lines +118 to +132
public static string GetSchemaTypeId<T>() => GetSchemaTypeId(typeof(T));
public static string GetSchemaTypeId(Type type)
{
var typeId = GetTypeId(type);
return SanitizeForJsonSchemaRef(typeId);
}

private static string SanitizeForJsonSchemaRef(string typeId)
{
if (string.IsNullOrEmpty(typeId))
return typeId;
return typeId.Replace("[", "%5B").Replace("]", "%5D")
.Replace("<", "%3C").Replace(">", "%3E")
.Replace("+", "%2B");
}
Comment on lines +118 to +123
public static string GetSchemaTypeId<T>() => GetSchemaTypeId(typeof(T));
public static string GetSchemaTypeId(Type type)
{
var typeId = GetTypeId(type);
return SanitizeForJsonSchemaRef(typeId);
}
private ParentClass.NestedClass NestedClassReturnMethod() => new ParentClass.NestedClass();
private LevelOne.LevelTwo.LevelThree.LevelFour DeeplyNestedClassReturnMethod() => new LevelOne.LevelTwo.LevelThree.LevelFour();
private GenericOuter<int>.GenericInner<string> GenericNestedClassReturnMethod() => new GenericOuter<int>.GenericInner<string>();
private ParentClass.NestedClass[] NestedClassArrayReturnMethod() => new ParentClass.NestedClass[0];
lior1997k added 3 commits May 4, 2026 11:14
- Add deeply nested (LevelOne.LevelTwo.LevelThree.LevelFour) test types
- Add generic nested (GenericOuter<T>.GenericInner<U>) test types
- Add type ID sanitization tests for +, <, > characters
- Add schema generation tests for nested class / validation
- Add return schema, argument schema, and array schema tests for nested types
- Add cross-assembly nested class schema validation

All 1438 tests pass (including 27 new ones).
@lior1997k lior1997k force-pushed the feat/schema-test-coverage branch from 3cb132e to 46d88b1 Compare May 4, 2026 08:15
@IvanMurzak
Copy link
Copy Markdown
Owner

Use the first PR which you made to add this changes there. Don't need to add new PRs for the same thing.

Just combine all together.

@IvanMurzak IvanMurzak closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants