diff --git a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs index deb4fed5e..b3d3362d9 100644 --- a/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs +++ b/Assets/VRM/UniVRM/Editor/Tests/UniVRMSerializeTests.cs @@ -237,10 +237,17 @@ namespace VRM [Test] public void MetaTest() { - var model = new glTF_VRM_Meta(); + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + licenseName = "CC0", + }; var json = model.ToJson(); - Assert.AreEqual(@"{""texture"":-1}", json); + Assert.AreEqual(@"{""texture"":-1,""allowedUserName"":""OnlyAuthor"",""violentUssageName"":""Disallow"",""sexualUssageName"":""Disallow"",""commercialUssageName"":""Disallow"",""licenseName"":""CC0""}", json); Debug.Log(json); var c = new JsonSchemaValidationContext("") @@ -249,7 +256,224 @@ namespace VRM }; var json2 = JsonSchema.FromType().Serialize(model, c); // NOTE: New serializer outputs values which will not be used... - Assert.AreEqual(@"{}",json2); + Assert.AreEqual(@"{""allowedUserName"":""OnlyAuthor"",""violentUssageName"":""Disallow"",""sexualUssageName"":""Disallow"",""commercialUssageName"":""Disallow"",""licenseName"":""CC0""}",json2); + } + + [Test] + public void MetaTestError() + { + { + var model = new glTF_VRM_Meta(); + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[allowedUserName.String] null", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + //licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[licenseName.String] null", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + licenseName = "_INVALID_SOME_THING_", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[licenseName.String] _INVALID_SOME_THING_ is not valid enum", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + // allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[allowedUserName.String] null", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "_INVALID_SOME_THING_", + violentUssageName = "Disallow", + sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[allowedUserName.String] _INVALID_SOME_THING_ is not valid enum", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + //violentUssageName = "Disallow", + sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[violentUssageName.String] null", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "_INVALID_SOME_THING_", + sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[violentUssageName.String] _INVALID_SOME_THING_ is not valid enum", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + //sexualUssageName = "Disallow", + commercialUssageName = "Disallow", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[sexualUssageName.String] null", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + sexualUssageName = "_INVALID_SOME_THING_", + commercialUssageName = "Disallow", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[sexualUssageName.String] _INVALID_SOME_THING_ is not valid enum", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + sexualUssageName = "Disallow", + //commercialUssageName = "Disallow", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[commercialUssageName.String] null", ex.Message); + } + + { + var model = new glTF_VRM_Meta() + { + allowedUserName = "OnlyAuthor", + violentUssageName = "Disallow", + sexualUssageName = "Disallow", + commercialUssageName = "_INVALID_SOME_THING_", + licenseName = "CC0", + }; + + var c = new JsonSchemaValidationContext("") + { + EnableDiagnosisForNotRequiredFields = true, + }; + var ex = Assert.Throws( + () => JsonSchema.FromType().Serialize(model, c) + ); + Assert.AreEqual("[commercialUssageName.String] _INVALID_SOME_THING_ is not valid enum", ex.Message); + } } // TODO: Move to another suitable location diff --git a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs index 7d8dfb0db..ceceead64 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/glTF_VRM_Meta.cs @@ -59,7 +59,7 @@ namespace VRM public int texture = -1; #region Ussage Permission - [JsonSchema(Description = "A person who can perform with this avatar ", EnumValues = new object[] { + [JsonSchema(Required = true, Description = "A person who can perform with this avatar ", EnumValues = new object[] { "OnlyAuthor", "ExplicitlyLicensedPerson", "Everyone", @@ -77,7 +77,7 @@ namespace VRM } } - [JsonSchema(Description = "Permission to perform violent acts with this avatar", EnumValues = new object[] + [JsonSchema(Required = true, Description = "Permission to perform violent acts with this avatar", EnumValues = new object[] { "Disallow", "Allow", @@ -89,7 +89,7 @@ namespace VRM set { violentUssageName = value.ToString(); } } - [JsonSchema(Description = "Permission to perform sexual acts with this avatar", EnumValues = new object[] + [JsonSchema(Required = true, Description = "Permission to perform sexual acts with this avatar", EnumValues = new object[] { "Disallow", "Allow", @@ -101,7 +101,7 @@ namespace VRM set { sexualUssageName = value.ToString(); } } - [JsonSchema(Description = "For commercial use", EnumValues = new object[] + [JsonSchema(Required = true, Description = "For commercial use", EnumValues = new object[] { "Disallow", "Allow", @@ -118,7 +118,7 @@ namespace VRM #endregion #region Distribution License - [JsonSchema(Description = "License type", EnumValues = new object[] + [JsonSchema(Required = true, Description = "License type", EnumValues = new object[] { "Redistribution_Prohibited", "CC0",