Skip to content

Commit

Permalink
Fix schema generation of sealed type with extension data (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Dec 26, 2023
1 parent 93b9ed5 commit 0c1e58a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions Src/Newtonsoft.Json.Schema.Tests/Issues/Issue0331Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#region License
// Copyright (c) Newtonsoft. All Rights Reserved.
// License: https://raw.github.com/JamesNK/Newtonsoft.Json.Schema/master/LICENSE.md
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema.Generation;
using Newtonsoft.Json.Serialization;
#if DNXCORE50
using Xunit;
using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Schema.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif

namespace Newtonsoft.Json.Schema.Tests.Issues
{
[TestFixture]
public class Issue0331Tests : TestFixtureBase
{
[Test]
public void Test()
{
JSchemaGenerator generator = new JSchemaGenerator();
JSchema schema = generator.Generate(typeof(MyDto));

Assert.IsFalse(schema.AllowAdditionalPropertiesSpecified);
}

public sealed class MyDto
{
[JsonProperty("foo")]
public string Foo { get; set; }

[JsonExtensionData]
public IDictionary<string, JToken> ExtensionData { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ private void GenerateObjectSchema(JSchema schema, Type type, JsonObjectContract
}
}

if (type.IsSealed())
if (type.IsSealed() && contract.ExtensionDataGetter == null)
{
schema.AllowAdditionalProperties = false;
}
Expand Down

0 comments on commit 0c1e58a

Please sign in to comment.