Skip to content
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

support JsonNode in schema generation #513

Merged
merged 2 commits into from Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions JsonSchema.Generation.Tests/ClientTests.cs
Expand Up @@ -270,4 +270,19 @@ public void Issue450_StackOverflowFromNestedCollections()

Console.WriteLine(JsonSerializer.Serialize(schema, new JsonSerializerOptions{WriteIndented = true}));
}

private class Issue512_Type
{
public IList<JsonNode> Foo { get; set; }
}

[Test]
public void Issue512_IListOfJsonNodeThrows()
{
var schema = new JsonSchemaBuilder()
.FromType<Issue512_Type>()
.Build();

Console.WriteLine(JsonSerializer.Serialize(schema, new JsonSerializerOptions { WriteIndented = true }));
}
}
1 change: 1 addition & 0 deletions JsonSchema.Generation/GeneratorRegistry.cs
Expand Up @@ -22,6 +22,7 @@ public static class GeneratorRegistry
new DateTimeSchemaGenerator(),
new GuidSchemaGenerator(),
new JsonPointerSchemaGenerator(),
new JsonNodeSchemaGenerator(),
new JsonArraySchemaGenerator(),
new JsonObjectSchemaGenerator(),
new JsonValueSchemaGenerator(),
Expand Down
17 changes: 17 additions & 0 deletions JsonSchema.Generation/Generators/JsonNodeSchemaGenerator.cs
@@ -0,0 +1,17 @@
using System;
using System.Text.Json.Nodes;

namespace Json.Schema.Generation.Generators;

internal class JsonNodeSchemaGenerator : ISchemaGenerator
{
public bool Handles(Type type)
{
return type == typeof(JsonNode);
}

public void AddConstraints(SchemaGenerationContextBase context)
{
// don't add anything. really, we want a true schema here.
}
}
4 changes: 2 additions & 2 deletions JsonSchema.Generation/JsonSchema.Generation.csproj
Expand Up @@ -19,8 +19,8 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DocumentationFile>JsonSchema.Net.Generation.xml</DocumentationFile>
<LangVersion>latest</LangVersion>
<Version>3.3.1</Version>
<FileVersion>3.3.1.0</FileVersion>
<Version>3.3.2</Version>
<FileVersion>3.3.2.0</FileVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
Expand Up @@ -4,6 +4,10 @@ title: JsonSchema.Net.Generation
icon: fas fa-tag
order: "8.02"
---
# [3.3.2](https://github.com/gregsdennis/json-everything/pull/513) {#release-schemagen-3.3.2}

[#512](https://github.com/gregsdennis/json-everything/issues/512) - There was no support for `JsonNode`, explicitly. Instead it would attempt to generate via reflection. This update adds that support and just generates a `true` schema. Thanks to [@ashek-simeon](https://github.com/ashek-simeon) for reporting and recommending a solution.

# [3.3.1](https://github.com/gregsdennis/json-everything/pull/491) {#release-schemagen-3.3.1}

[#488](https://github.com/gregsdennis/json-everything/issues/488) - `[Maximum(double.MaxValue)]` throws an overflow exception when attempting to convert to decimal. This fix updates all min/max-related attributes.
Expand Down