Skip to content

JsonSchema Generation doesn't process JObject? like it is stated in the docs #1790

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

Open
ghostiek opened this issue Apr 15, 2025 · 0 comments

Comments

@ghostiek
Copy link

ghostiek commented Apr 15, 2025

Here is the code I ran

using NJsonSchema.NewtonsoftJson.Generation;
using Newtonsoft.Json.Linq;
using NJsonSchema.Generation;
using System;
using Newtonsoft.Json.Serialization;

class Test()
{
    public int Id { get; set; }
    public JObject? Value { get; set; }
}

class Program()
{
    public static void Main(string[] args)
    {
        var settings = new NewtonsoftJsonSchemaGeneratorSettings();

        var generator = new JsonSchemaGenerator(settings);
        var schema = generator.Generate(typeof(Test));

        Console.WriteLine(schema.ToJson());
    }
}

Which generates the following

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Test",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "Id": {
      "type": "integer",
      "format": "int32"
    },
    "Value": {
      "oneOf": [
        {},
        {
          "type": "null"
        }
      ]
    }
  }
}

As the docs mention, JObject should be outputting {"type":"object", "additionalProperties": true } instead I got an empty dictionary. Is there a workaround?

@ghostiek ghostiek changed the title JsonSchema Generation doesn't process JObject? like in the docs JsonSchema Generation doesn't process JObject? like it is stated in the docs Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant