Reputation: 21
I'm creating manual JSON schema using JSchema. Normally, I specify the attributes of a JSchema property like this:
JSchema props = new JSchema();
props.Properties.Add(KeyName), new JSchema { Type = JSchemaType.String });
However, for certain objects, I want the Property to be a reference to a property in another schema. When I do this by hand, this works:
"text": {
"$ref": "Common.json#/definitions/Text"
}
What I want to do is auto generate the above property using JSchema. JSchema has a property called Reference, but I can't find any documentation on how to use it. I've tried to do it this way:
props.Properties.Add("Text", new JSchema { Reference = new Uri("Common.json#/definitions/Text", UriKind.RelativeOrAbsolute) });
But no go. What is the correct method for creating references using JSchema?
Upvotes: 1
Views: 900
Reputation: 106
You can set $ref property like that
JSchema propertySchema = new JSchema();
propertySchema.ExtensionData["$ref"] = "Common.json#/definitions/Text";
schema.Properties.Add("Text", propertySchema);
Upvotes: 1