-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field sequence definitions of schema #300
Comments
After I set SchemaPropertyOrderHandling to Alphabetical, I think the JSchema.ToString() is stable. JSchema schema = new JSchemaGenerator(){ SchemaPropertyOrderHandling = SchemaPropertyOrderHandling.Alphabetical }.Generate(typeof(Data)); |
I think we should set SchemaLocationHandling to "Inline" instead of Definitions. Because according to: And this is just a workarround. |
https://github.com/JamesNK/Newtonsoft.Json.Schema/blob/master/Src/Newtonsoft.Json.Schema/Generation/JSchemaGeneratorInternal.cs#L76 foreach (KeyValuePair<string, JSchema> definitionSchema in definitionsSchemas.OrderBy(s => s.Key)) to foreach (KeyValuePair<string, JSchema> definitionSchema in definitionsSchemas.OrderBy(s => s.Key, StringComparer.Ordinal)) The bug gone. So I replace Dictionary by SortedDictionary(xxx, StringComparer.Ordinal) as much as possible. |
I finish more tests.
So, the conclusion: |
…nitions of schema is stable (JamesNK#300) Signed-off-by: Kunlin Yu <[email protected]>
I defined a JSON file format. And generate schema by Newtonsoft.Json.Schema.
In case, I modify the C# code, which may change the schema, I will calculate the md5sum check sum for the schema for each version, and record it into file format.
Then future version may read the check sum to know the version of file format.
But I found that the JSchema.ToString() is not stable.
The order of field may change. So the schemaMd5 may change even no C# code changed.
I check the code:
https://github.com/JamesNK/Newtonsoft.Json.Schema/blob/master/Src/Newtonsoft.Json.Schema/Infrastructure/Collections/DictionaryBase.cs#L61
The JSchemaDictionary inherit from DictionaryBase which use Dictionary to be the default container.
I think if we use SortedDictionary(https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.sorteddictionary-2?view=net-6.0) then the output of JSchema.ToString() may be stable.
So my question is:
How can I use SortedDictionary to be the container of DictionaryBase?
Can we use SortedDictionary to be the default container of DictionaryBase?
The text was updated successfully, but these errors were encountered: