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

string does not have items #553

Merged
merged 5 commits into from Nov 3, 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
24 changes: 24 additions & 0 deletions JsonSchema.Generation.Tests/ClientTests.cs
Expand Up @@ -324,4 +324,28 @@ public void Issue544_DeprecatedSpillingOverToOtherPropertiesOfSameType()
Assert.AreEqual(1, schema.GetProperties()!["BBB"].Keywords!.Count);
Assert.AreEqual("type", schema.GetProperties()!["BBB"].Keywords!.First().Keyword());
}

private class Type551_MinItemsOnString
{
[MinItems(1)]
[MaxItems(10)]
public string Value { get; set; }
}

[Test]
public void Issue551_MinMaxItemsOnStringProperty()
{
JsonSchema expected = new JsonSchemaBuilder()
.Type(SchemaValueType.Object)
.Properties(
("Value", new JsonSchemaBuilder().Type(SchemaValueType.String))
);

JsonSchema schema = new JsonSchemaBuilder().FromType<Type551_MinItemsOnString>();
var schemaJson = JsonSerializer.Serialize(schema, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine(schemaJson);

Assert.AreEqual(1, schema.GetProperties()!["Value"].Keywords!.Count);
Assert.AreEqual("type", schema.GetProperties()!["Value"].Keywords!.First().Keyword());
}
}
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.4.1</Version>
<FileVersion>3.4.1.0</FileVersion>
<Version>3.4.2</Version>
<FileVersion>3.4.2.0</FileVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
7 changes: 4 additions & 3 deletions JsonSchema.Generation/TypeExtensions.cs
Expand Up @@ -20,9 +20,10 @@ public static class TypeExtensions
/// <returns>true if the type represents an array; false otherwise.</returns>
public static bool IsArray(this Type type)
{
return type.IsArray ||
type == typeof(Array) ||
typeof(IEnumerable).IsAssignableFrom(type);
return type != typeof(string) &&
(type.IsArray ||
type == typeof(Array) ||
typeof(IEnumerable).IsAssignableFrom(type));
}

internal static int GetAttributeSetHashCode(this IEnumerable<Attribute> items)
Expand Down
Expand Up @@ -4,6 +4,10 @@ title: JsonSchema.Net.Generation
icon: fas fa-tag
order: "8.02"
---
# [3.4.2](https://github.com/gregsdennis/json-everything/pull/553) {#release-schemagen-3.4.2}

[#551](https://github.com/gregsdennis/json-everything/issues/551) - Strings implement `IEnumerable<T>` and thus were considered arrays. As a result `minItems` and `maxItems` were being applied. Thanks to [@domchlouba](https://github.com/domchlouba) for reporting this and recommending the fix.

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

[#544](https://github.com/gregsdennis/json-everything/issues/544) - Objects that have two properties of the same type, one of which is marked with an `[Obsolete]` attribute will cause all properties to have a `deprecated: true` added to their schemas. Thanks to [@filzrev](https://github.com/filzrev) for reporting this.
Expand Down