I'm using NJsonSchema v2.6 for generating the JSON Schema for the following class:
[DataContract(Name = "Message", Namespace = "")]
public class AMessageModel
{
[DataMember]
internal Guid MessageId { get; set; }
internal DateTime MessageDate { get; set; }
}
[DataContract(Name = "Message", Namespace = "")]
public class AddUserMessage : AMessageModel
{
[DataMember]
public string AccountName { get; set; }
[DataMember]
public string FistName { get; set; }
[Range(2, 5)]
[DataMember]
public string LastName { get; set; }
[DataMember]
public string Email { get; set; }
[DataMember]
public string Password { get; set; }
}
The generated JSON Schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"typeName": "AddFitnessHubAccountMessage",
"additionalProperties": false,
"properties": {
"AccountName": {
"type": [
"null",
"string"
]
},
"FistName": {
"type": [
"null",
"string"
]
},
"LastName": {
"type": [
"null",
"string"
]
},
"Email": {
"type": [
"null",
"string"
]
},
"Password": {
"type": [
"null",
"string"
]
}
},
"allOf": [
{
"type": "object",
"typeName": "AMessageModel",
"additionalProperties": false,
"properties": {
"MessageId": {
"type": "string",
"format": "guid"
},
"MessageDate": {
"type": "string",
"format": "date-time"
}
}
}
]
}
Even though the MessageDate property is not marked as a DataMember, it is always included in the schema, also the generated schema includes two schema paths when it should only include one, it seems that the parser is not flattening the properties.
UPDATE
This fixes the issue with multiple schema paths being created
new JsonSchemaGeneratorSettings
{
FlattenInheritanceHierarchy = true
}
GitHub Issue: https://github.com/NJsonSchema/NJsonSchema/issues/53