Merge remote-tracking branch 'origin/v9/cyclehack/autogeneration_of_json_schema' into v9/cyclehack/autogeneration_of_json_schema
# Conflicts: # src/JsonSchema/UmbracoJsonSchemaGeneratorSettings.cs
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NJsonSchema.Generation;
|
||||
|
||||
namespace JsonSchema
|
||||
@@ -14,12 +18,24 @@ namespace JsonSchema
|
||||
public UmbracoJsonSchemaGeneratorSettings()
|
||||
{
|
||||
AlwaysAllowAdditionalObjectProperties = true;
|
||||
SerializerSettings = new JsonSerializerSettings();
|
||||
SerializerSettings = new JsonSerializerSettings()
|
||||
{
|
||||
ContractResolver = new WritablePropertiesOnlyResolver()
|
||||
};
|
||||
DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull;
|
||||
SchemaNameGenerator = new NamespacePrefixedSchemaNameGenerator();
|
||||
SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||
IgnoreObsoleteProperties = true;
|
||||
GenerateExamples = true;
|
||||
}
|
||||
|
||||
private class WritablePropertiesOnlyResolver : DefaultContractResolver
|
||||
{
|
||||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||
{
|
||||
IList<JsonProperty> props = base.CreateProperties(type, memberSerialization);
|
||||
return props.Where(p => p.Writable).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user