Skip to content

Commit

Permalink
Merge pull request #814 from RSuter/master
Browse files Browse the repository at this point in the history
Release v9.12.2
  • Loading branch information
RicoSuter authored Nov 13, 2018
2 parents 27e5802 + a0d077a commit 5cd46f9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.12.1</Version>
<Version>9.12.2</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2017</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.12.1</Version>
<Version>9.12.2</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2017</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;net451</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.12.1</Version>
<Version>9.12.2</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2017</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.3;net45</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.12.1</Version>
<Version>9.12.2</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2017</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down
53 changes: 35 additions & 18 deletions src/NJsonSchema/Generation/JsonSchemaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ protected virtual async Task GenerateObjectAsync(Type type,

GenerateInheritanceDiscriminator(type, rootSchema);

if (Settings.GenerateKnownTypes)
await GenerateKnownTypesAsync(type, schemaResolver).ConfigureAwait(false);
await GenerateKnownTypesAsync(type, schemaResolver).ConfigureAwait(false);

if (Settings.GenerateXmlObjects)
schema.GenerateXmlObjectForType(type);
Expand Down Expand Up @@ -644,30 +643,48 @@ protected virtual string[] GetTypeProperties(Type type)

private async Task GenerateKnownTypesAsync(Type type, JsonSchemaResolver schemaResolver)
{
var knownTypeAttributes = type.GetTypeInfo()
.GetCustomAttributes(Settings.GetActualFlattenInheritanceHierarchy(type)) // Known types of inherited classes will be generated later (in GenerateInheritanceAsync)
.Where(a => a.GetType().Name == "KnownTypeAttribute")
.OfType<Attribute>();
var attributes = type.GetTypeInfo()
.GetCustomAttributes(Settings.GetActualFlattenInheritanceHierarchy(type));

foreach (dynamic attribute in knownTypeAttributes)
if (Settings.GenerateKnownTypes)
{
if (attribute.Type != null)
await AddKnownTypeAsync(attribute.Type, schemaResolver).ConfigureAwait(false);
else if (attribute.MethodName != null)
var knownTypeAttributes = attributes
// Known types of inherited classes will be generated later (in GenerateInheritanceAsync)
.Where(a => a.GetType().IsAssignableTo("KnownTypeAttribute", TypeNameStyle.Name))
.OfType<Attribute>();

foreach (dynamic attribute in knownTypeAttributes)
{
var methodInfo = type.GetRuntimeMethod((string)attribute.MethodName, new Type[0]);
if (methodInfo != null)
if (attribute.Type != null)
await AddKnownTypeAsync(attribute.Type, schemaResolver).ConfigureAwait(false);
else if (attribute.MethodName != null)
{
var knownTypes = methodInfo.Invoke(null, null) as IEnumerable<Type>;
if (knownTypes != null)
var methodInfo = type.GetRuntimeMethod((string)attribute.MethodName, new Type[0]);
if (methodInfo != null)
{
foreach (var knownType in knownTypes)
await AddKnownTypeAsync(knownType, schemaResolver).ConfigureAwait(false);
var knownTypes = methodInfo.Invoke(null, null) as IEnumerable<Type>;
if (knownTypes != null)
{
foreach (var knownType in knownTypes)
await AddKnownTypeAsync(knownType, schemaResolver).ConfigureAwait(false);
}
}
}
else
throw new ArgumentException($"A KnownType attribute on {type.FullName} does not specify a type or a method name.", nameof(type));
}
}

foreach (var jsonConverterAttribute in attributes
.Where(a => a.GetType().IsAssignableTo("JsonInheritanceAttribute", TypeNameStyle.Name)))
{
var knownType = ReflectionExtensions.TryGetPropertyValue<Type>(
jsonConverterAttribute, "Type", null);

if (knownType != null)
{
await AddKnownTypeAsync(knownType, schemaResolver).ConfigureAwait(false);
}
else
throw new ArgumentException($"A KnownType attribute on {type.FullName} does not specify a type or a method name.", nameof(type));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/NJsonSchema/NJsonSchema.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.0;net40;net45</TargetFrameworks>
<Description>JSON Schema reader, generator and validator for .NET</Description>
<Version>9.12.1</Version>
<Version>9.12.2</Version>
<PackageTags>json schema validation generator .net</PackageTags>
<Copyright>Copyright © Rico Suter, 2017</Copyright>
<PackageLicenseUrl>https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md</PackageLicenseUrl>
Expand Down

0 comments on commit 5cd46f9

Please sign in to comment.