fix: sanitize JSON Schema $defs keys to produce valid $ref URI references#77
Open
lior1997k wants to merge 2 commits intoIvanMurzak:mainfrom
Open
fix: sanitize JSON Schema $defs keys to produce valid $ref URI references#77lior1997k wants to merge 2 commits intoIvanMurzak:mainfrom
lior1997k wants to merge 2 commits intoIvanMurzak:mainfrom
Conversation
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>
Owner
|
@lior1997k that is an interesting solution! Thanks for fixing it. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make JSON Schema $ref values valid URI references by sanitizing schema type identifiers derived from C# type names (notably array and generic syntax).
Changes:
- Update
TypeUtils.GetSchemaTypeId(Type)to percent-encode[]<>in the returned schema type ID. - Update
TestSchemaTypeIdassertions to expect the new percent-encoded output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ReflectorNet/src/Utils/TypeUtils.Name.cs | Adds SanitizeForJsonSchemaRef() and routes GetSchemaTypeId through it to percent-encode certain characters. |
| ReflectorNet.Tests/src/SchemaTests/TestSchemaTypeId.cs | Updates expected strings for arrays/generics to use %5B%5D and %3C%3E. |
Comment on lines
+129
to
+130
| return typeId.Replace("[", "%5B").Replace("]", "%5D") | ||
| .Replace("<", "%3C").Replace(">", "%3E"); |
Comment on lines
20
to
22
| // Assert | ||
| Assert.Equal($"System.Int32{TypeUtils.ArraySuffix}", result); | ||
| Assert.Equal("System.Int32%5B%5D", result); | ||
| _output.WriteLine($"int[] -> {result}"); |
Owner
|
IMPORTANT after sanitization need to check that the new Json Schema works well for |
Owner
|
Related issue: IvanMurzak/Unity-MCP#668 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GetSchemaTypeId()returns raw C# type names (e.g.System.String[],IEnumerable<System.Int32>) which are used as$defskeys in JSON Schema. These contain characters ([]<>) that violate RFC 3986 URI-reference rules, producing invalid$refvalues.Changes
GetSchemaTypeId()now percent-encodes[]<>characters before returning the type IDTesting
All 1,423 tests pass on both net8.0 and net9.0.
Fixes IvanMurzak/Unity-MCP#715