Grant M
Grant M

Reputation: 658

Newtonsoft.Json.Schema how not generate references $ref in schema

Json.Net.Schema is generating refernces for all of my string arrays. for example this c#

public string[] ovoImageUrl;    
public string[] ovoMetaprofile;

produces this Json schema

"ovoImageUrl": {
  "type": [
    "array",
    "null"
  ],
  "items": {
    "type": [
      "string",
      "null"
    ]
  }
},
"ovoMetaprofile": {
  "$ref": "#/properties/ovoImageUrl"
},

Since I am using the Json Schema as human readable documentation this is not desirable. is there any way, maybe with attributes, stop these "$ref" from being created?

Cheers, Grant

Upvotes: 2

Views: 1587

Answers (1)

James Newton-King
James Newton-King

Reputation: 49052

The latest version of Newtonsoft.Json.Schema has a SchemaReferenceHandling setting on JSchemaGenerator for controlling references.

JSchemaGenerator generator = new JSchemaGenerator();
generator.SchemaReferenceHandling = SchemaReferenceHandling.None;
JSchema schema = generator.Generate(typeof(Person));

http://www.newtonsoft.com/jsonschema/help/html/P_Newtonsoft_Json_Schema_Generation_JSchemaGenerator_SchemaReferenceHandling.htm

Upvotes: 4

Related Questions