Skip to content

Commit

Permalink
Update annotations project as discussed, #1641
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico Suter committed Oct 31, 2023
2 parents 8189415 + 47e494b commit c7dc2b7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/NJsonSchema.Annotations/JsonFormatStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using System;

namespace NJsonSchema.Annotations;
namespace NJsonSchema;

/// <summary>Class containing the constants available as format string. </summary>
public static class JsonFormatStrings
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema.Annotations/JsonObjectType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace NJsonSchema.Annotations;
namespace NJsonSchema;

/// <summary>
/// Enumeration of the possible object types.
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema.Annotations/NJsonSchema.Annotations.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions src/NJsonSchema.Tests/Generation/AnnotationsGenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class AnnotationClass
{
public MyPoint Point { get; set; }

[JsonSchema(Annotations.JsonObjectType.String, Format = "point")]
[JsonSchema(JsonObjectType.String, Format = "point")]
public AnnotationClass ClassAsString { get; set; }

[JsonSchema(Annotations.JsonObjectType.String, Format = "point")]
[JsonSchema(JsonObjectType.String, Format = "point")]
public class MyPoint
{
public decimal X { get; set; }
Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task When_multipleOf_is_fraction_then_it_is_validated_correctly()
Assert.Equal(0, errors.Count);
}

[JsonSchema(Annotations.JsonObjectType.Array, ArrayItem = typeof(string))]
[JsonSchema(JsonObjectType.Array, ArrayItem = typeof(string))]
public class ArrayModel : IEnumerable<string>
{
public IEnumerator<string> GetEnumerator()
Expand All @@ -172,7 +172,7 @@ public async Task When_class_has_array_item_type_defined_then_schema_has_this_it
Assert.Equal(JsonObjectType.String, schema.Item.Type);
}

[JsonSchema(Annotations.JsonObjectType.Array, ArrayItem = typeof(string))]
[JsonSchema(JsonObjectType.Array, ArrayItem = typeof(string))]
public class ArrayModel<T> : List<T>
{
}
Expand All @@ -197,7 +197,7 @@ public class MyStructContainer
public MyStruct? NullableStruct { get; set; }
}

[JsonSchema(Annotations.JsonObjectType.String)]
[JsonSchema(JsonObjectType.String)]
public struct MyStruct
{
}
Expand Down
34 changes: 25 additions & 9 deletions src/NJsonSchema.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00 Build", "00 Build", "{863B2D88-A0BD-4466-8583-AAD0B8D3F182}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
..\README.md = ..\README.md
Directory.Packages.props = Directory.Packages.props
..\README.md = ..\README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "..\build\_build.csproj", "{8E4E5A64-B5B7-4718-A92F-CB6B08512264}"
Expand Down Expand Up @@ -244,6 +244,22 @@ Global
{990EF464-C967-4E08-8C3D-0568A47B6D2A}.Release|x64.Build.0 = Release|Any CPU
{990EF464-C967-4E08-8C3D-0568A47B6D2A}.Release|x86.ActiveCfg = Release|Any CPU
{990EF464-C967-4E08-8C3D-0568A47B6D2A}.Release|x86.Build.0 = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|ARM.ActiveCfg = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|ARM.Build.0 = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|x64.ActiveCfg = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|x64.Build.0 = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|x86.ActiveCfg = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Debug|x86.Build.0 = Debug|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|Any CPU.Build.0 = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|ARM.ActiveCfg = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|ARM.Build.0 = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|x64.ActiveCfg = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|x64.Build.0 = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|x86.ActiveCfg = Release|Any CPU
{8E4E5A64-B5B7-4718-A92F-CB6B08512264}.Release|x86.Build.0 = Release|Any CPU
{A9C2A9CD-44F6-4A21-9D72-00CF5BE0A36F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9C2A9CD-44F6-4A21-9D72-00CF5BE0A36F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9C2A9CD-44F6-4A21-9D72-00CF5BE0A36F}.Debug|ARM.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -297,20 +313,20 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8E4E5A64-B5B7-4718-A92F-CB6B08512264} = {863B2D88-A0BD-4466-8583-AAD0B8D3F182}
{7B7A2E32-E808-4A19-98B1-37E766580F8C} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{E59CE32B-181F-4AAE-BF62-772AEEFC3177} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{A9C2A9CD-44F6-4A21-9D72-00CF5BE0A36F} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{AFA1E1E7-37F9-4958-B0E3-ADB12F53E563} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{9EAB6FAB-10AC-4AB2-BA5B-103CE6A17E88} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{990EF464-C967-4E08-8C3D-0568A47B6D2A} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{4F0A74F2-54BE-4747-8EDB-562ABB6E0B64} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{8A463FA0-DAAF-483C-813E-AE9C6153CBF7} = {62F296F1-8CE9-493C-9022-35F4C687460B}
{546CF985-2029-4CBB-8F7D-303C037EB293} = {62F296F1-8CE9-493C-9022-35F4C687460B}
{3D8BA0A7-65AF-4328-82DC-8C131D9A9EA8} = {62F296F1-8CE9-493C-9022-35F4C687460B}
{0873FE5E-4A46-48B5-A171-AC629EC7C263} = {62F296F1-8CE9-493C-9022-35F4C687460B}
{974ED050-4A34-4513-8048-139B1AF1A95D} = {62F296F1-8CE9-493C-9022-35F4C687460B}
{3D8BA0A7-65AF-4328-82DC-8C131D9A9EA8} = {62F296F1-8CE9-493C-9022-35F4C687460B}
{E767A007-6007-4898-B80A-FE4ACBF2C588} = {62F296F1-8CE9-493C-9022-35F4C687460B}
{4F0A74F2-54BE-4747-8EDB-562ABB6E0B64} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{9EAB6FAB-10AC-4AB2-BA5B-103CE6A17E88} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{E59CE32B-181F-4AAE-BF62-772AEEFC3177} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{990EF464-C967-4E08-8C3D-0568A47B6D2A} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{8E4E5A64-B5B7-4718-A92F-CB6B08512264} = {863B2D88-A0BD-4466-8583-AAD0B8D3F182}
{A9C2A9CD-44F6-4A21-9D72-00CF5BE0A36F} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{AFA1E1E7-37F9-4958-B0E3-ADB12F53E563} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
{526020E1-D3B5-49F6-BE11-5F4402A02E92} = {CDBC7AC4-9D3D-430D-86BF-CDAECBDD715A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
14 changes: 1 addition & 13 deletions src/NJsonSchema/Generation/ReflectionServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,14 @@ public JsonTypeDescription GetDescription(ContextualType contextualType, Referen
var jsonSchemaAttribute = contextualType.GetContextOrTypeAttribute<JsonSchemaAttribute>(true); ;
if (jsonSchemaAttribute != null)
{
var classType = ToJsonObjectType(jsonSchemaAttribute.Type);
if (classType == JsonObjectType.None)
{
classType = JsonObjectType.Object;
}

var classType = jsonSchemaAttribute.Type != JsonObjectType.None ? jsonSchemaAttribute.Type : JsonObjectType.Object;
var format = !string.IsNullOrEmpty(jsonSchemaAttribute.Format) ? jsonSchemaAttribute.Format : null;
return JsonTypeDescription.Create(contextualType, classType, isNullable, format);
}

return GetDescription(contextualType, settings, type, isNullable, defaultReferenceTypeNullHandling);
}

/// <summary>
/// Convert <see cref="Annotations.JsonObjectType"/> into <see cref="JsonObjectType"/>
/// </summary>
/// <param name="jsonObjectType"></param>
/// <returns></returns>
protected JsonObjectType ToJsonObjectType(Annotations.JsonObjectType jsonObjectType) => (JsonObjectType) jsonObjectType;

/// <summary>Creates a <see cref="JsonTypeDescription"/> from a <see cref="Type"/>. </summary>
/// <param name="contextualType">The type.</param>
/// <param name="settings">The settings.</param>
Expand Down
58 changes: 0 additions & 58 deletions src/NJsonSchema/JsonObjectType.cs

This file was deleted.

0 comments on commit c7dc2b7

Please sign in to comment.