Bladeren bron

Updated JSonSchemaGenerator

Vicente Penades 6 jaren geleden
bovenliggende
commit
36ae08400e

+ 10 - 5
build/SharpGLTF.CodeGen/Program.cs

@@ -4,8 +4,11 @@ using System.Linq;
 using System.Reflection;
 using System.Reflection;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+
 using NJsonSchema.References;
 using NJsonSchema.References;
 
 
+using JSONSCHEMA = NJsonSchema.JsonSchema;
+
 namespace SharpGLTF
 namespace SharpGLTF
 {
 {
     using CodeGen;
     using CodeGen;
@@ -297,29 +300,31 @@ namespace SharpGLTF
             return SchemaTypesReader.Generate(ctypes);
             return SchemaTypesReader.Generate(ctypes);
         }
         }
 
 
-        static NJsonSchema.JsonSchema4 LoadSchema(string filePath)
+        static JSONSCHEMA LoadSchema(string filePath)
         {
         {
             // https://blogs.msdn.microsoft.com/benjaminperkins/2017/03/08/how-to-call-an-async-method-from-a-console-app-main-method/
             // https://blogs.msdn.microsoft.com/benjaminperkins/2017/03/08/how-to-call-an-async-method-from-a-console-app-main-method/
 
 
             if (!System.IO.File.Exists(filePath)) throw new System.IO.FileNotFoundException(nameof(filePath), filePath);
             if (!System.IO.File.Exists(filePath)) throw new System.IO.FileNotFoundException(nameof(filePath), filePath);
 
 
-            return NJsonSchema.JsonSchema4
+            return JSONSCHEMA
                 .FromFileAsync(filePath, s => _Resolver(s,filePath) )
                 .FromFileAsync(filePath, s => _Resolver(s,filePath) )
                 .ConfigureAwait(false)
                 .ConfigureAwait(false)
                 .GetAwaiter()
                 .GetAwaiter()
                 .GetResult();
                 .GetResult();
         }
         }
 
 
-        static NJsonSchema.JsonReferenceResolver _Resolver(NJsonSchema.JsonSchema4 schema, string basePath)
+        static NJsonSchema.JsonReferenceResolver _Resolver(JSONSCHEMA schema, string basePath)
         {
         {
-            var solver = new NJsonSchema.JsonSchemaResolver(schema, new NJsonSchema.Generation.JsonSchemaGeneratorSettings());
+            var generator = new NJsonSchema.Generation.JsonSchemaGeneratorSettings();
+
+            var solver = new NJsonSchema.JsonSchemaAppender(schema, generator.TypeNameGenerator);
 
 
             return new MyReferenceResolver(solver);            
             return new MyReferenceResolver(solver);            
         }
         }
 
 
         class MyReferenceResolver : NJsonSchema.JsonReferenceResolver
         class MyReferenceResolver : NJsonSchema.JsonReferenceResolver
         {
         {
-            public MyReferenceResolver(NJsonSchema.JsonSchemaResolver resolver) : base(resolver) { }
+            public MyReferenceResolver(NJsonSchema.JsonSchemaAppender resolver) : base(resolver) { }
 
 
             public override Task<IJsonReference> ResolveFileReferenceAsync(string filePath)
             public override Task<IJsonReference> ResolveFileReferenceAsync(string filePath)
             {
             {

+ 13 - 11
build/SharpGLTF.CodeGen/SchemaReflection/SchemaTypesReader.cs

@@ -4,6 +4,8 @@ using System.Linq;
 using System.Reflection;
 using System.Reflection;
 using System.Text;
 using System.Text;
 
 
+using JSONSCHEMA = NJsonSchema.JsonSchema;
+
 namespace SharpGLTF.SchemaReflection
 namespace SharpGLTF.SchemaReflection
 {
 {
     /// <summary>
     /// <summary>
@@ -35,12 +37,12 @@ namespace SharpGLTF.SchemaReflection
 
 
         #region core
         #region core
 
 
-        private static SchemaType _UseType(this SchemaType.Context ctx, NJsonSchema.JsonSchema4 schema, bool isRequired = true)
+        private static SchemaType _UseType(this SchemaType.Context ctx, JSONSCHEMA schema, bool isRequired = true)
         {
         {
             if (ctx == null) throw new ArgumentNullException(nameof(ctx));
             if (ctx == null) throw new ArgumentNullException(nameof(ctx));
             if (schema == null) throw new ArgumentNullException(nameof(schema));            
             if (schema == null) throw new ArgumentNullException(nameof(schema));            
 
 
-            if (schema is NJsonSchema.JsonProperty prop)
+            if (schema is NJsonSchema.JsonSchemaProperty prop)
             {
             {
                 // System.Diagnostics.Debug.Assert(prop.Name != "scene");
                 // System.Diagnostics.Debug.Assert(prop.Name != "scene");
 
 
@@ -71,7 +73,7 @@ namespace SharpGLTF.SchemaReflection
 
 
             if (_IsEnumeration(schema))
             if (_IsEnumeration(schema))
             {
             {
-                if (schema is NJsonSchema.JsonProperty property)
+                if (schema is NJsonSchema.JsonSchemaProperty property)
                 {
                 {
                     bool isNullable = !isRequired;
                     bool isNullable = !isRequired;
 
 
@@ -170,7 +172,7 @@ namespace SharpGLTF.SchemaReflection
             throw new NotImplementedException();
             throw new NotImplementedException();
         }
         }
 
 
-        private static bool _IsBlittableType(NJsonSchema.JsonSchema4 schema)
+        private static bool _IsBlittableType(JSONSCHEMA schema)
         {
         {
             if (schema == null) return false;
             if (schema == null) return false;
             if (schema.Type == NJsonSchema.JsonObjectType.Boolean) return true;
             if (schema.Type == NJsonSchema.JsonObjectType.Boolean) return true;
@@ -180,12 +182,12 @@ namespace SharpGLTF.SchemaReflection
             return false;
             return false;
         }        
         }        
 
 
-        private static bool _IsStringType(NJsonSchema.JsonSchema4 schema)
+        private static bool _IsStringType(JSONSCHEMA schema)
         {
         {
             return schema.Type == NJsonSchema.JsonObjectType.String;
             return schema.Type == NJsonSchema.JsonObjectType.String;
         }
         }
 
 
-        private static bool _IsEnumeration(NJsonSchema.JsonSchema4 schema)
+        private static bool _IsEnumeration(JSONSCHEMA schema)
         {
         {
             if (schema.Type != NJsonSchema.JsonObjectType.None) return false;
             if (schema.Type != NJsonSchema.JsonObjectType.None) return false;
 
 
@@ -198,7 +200,7 @@ namespace SharpGLTF.SchemaReflection
             return true;
             return true;
         }
         }
 
 
-        private static bool _IsDictionary(NJsonSchema.JsonSchema4 schema)
+        private static bool _IsDictionary(JSONSCHEMA schema)
         {
         {
             // if (schema.Type != NJsonSchema.JsonObjectType.Object) return false;
             // if (schema.Type != NJsonSchema.JsonObjectType.Object) return false;
 
 
@@ -208,7 +210,7 @@ namespace SharpGLTF.SchemaReflection
             return false;
             return false;
         }        
         }        
 
 
-        private static NJsonSchema.JsonSchema4 _GetDictionaryValue(NJsonSchema.JsonSchema4 schema)
+        private static JSONSCHEMA _GetDictionaryValue(JSONSCHEMA schema)
         {
         {
             if (schema.AdditionalPropertiesSchema != null)
             if (schema.AdditionalPropertiesSchema != null)
             {
             {
@@ -225,14 +227,14 @@ namespace SharpGLTF.SchemaReflection
             throw new NotImplementedException();
             throw new NotImplementedException();
         }
         }
 
 
-        private static bool _IsClass(NJsonSchema.JsonSchema4 schema)
+        private static bool _IsClass(JSONSCHEMA schema)
         {
         {
             if (schema.Type != NJsonSchema.JsonObjectType.Object) return false;
             if (schema.Type != NJsonSchema.JsonObjectType.Object) return false;
             
             
             return !string.IsNullOrWhiteSpace(schema.Title);            
             return !string.IsNullOrWhiteSpace(schema.Title);            
         }
         }
 
 
-        private static string[] _GetProperyNames(NJsonSchema.JsonSchema4 schema)
+        private static string[] _GetProperyNames(JSONSCHEMA schema)
         {
         {
             return schema
             return schema
                     .Properties
                     .Properties
@@ -241,7 +243,7 @@ namespace SharpGLTF.SchemaReflection
                     .ToArray();
                     .ToArray();
         }
         }
 
 
-        private static string[] _GetInheritedPropertyNames(NJsonSchema.JsonSchema4 schema)
+        private static string[] _GetInheritedPropertyNames(JSONSCHEMA schema)
         {
         {
             if (schema?.InheritedSchema == null) return Enumerable.Empty<string>().ToArray();
             if (schema?.InheritedSchema == null) return Enumerable.Empty<string>().ToArray();
 
 

+ 2 - 2
build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj

@@ -8,8 +8,8 @@
 
 
   <ItemGroup>
   <ItemGroup>
     <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
     <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
-    <PackageReference Include="NJsonSchema.CodeGeneration" Version="9.14.1" />
-    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="9.14.1" />
+    <PackageReference Include="NJsonSchema.CodeGeneration" Version="10.0.5" />
+    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.0.5" />
   </ItemGroup>
   </ItemGroup>
 
 
 </Project>
 </Project>

+ 1 - 0
src/SharpGLTF.Core/SharpGLTF.Core.csproj

@@ -40,6 +40,7 @@
   </PropertyGroup>
   </PropertyGroup>
   
   
   <ItemGroup>    
   <ItemGroup>    
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.2" />    
     <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
     <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
     <PackageReference Include="System.Memory" Version="4.5.3" />
     <PackageReference Include="System.Memory" Version="4.5.3" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">

+ 1 - 0
src/SharpGLTF.Toolkit/SharpGLTF.Toolkit.csproj

@@ -34,6 +34,7 @@
   </PropertyGroup>
   </PropertyGroup>
 
 
   <ItemGroup>
   <ItemGroup>
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.2" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
       <PrivateAssets>all</PrivateAssets>
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

+ 1 - 1
tests/SharpGLTF.Tests/SharpGLTF.Tests.csproj

@@ -10,7 +10,7 @@
 
 
   <ItemGroup>
   <ItemGroup>
     <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
     <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
-    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0" />
+    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.1.0" />
     <PackageReference Include="nunit" Version="3.12.0" />
     <PackageReference Include="nunit" Version="3.12.0" />
     <PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
     <PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />    
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />