I'm using NJsonSchema to convert a normal Json to Schema. However, NJsonSchema returns the Schema with $ref fields, but I want to have the actual structure.
For example:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Property1": {
"$ref": "#/definitions/Property1"
},
"Property2": {
"$ref": "#/definitions/Property2"
},
"Property3": {
"type": "array",
"items": {
"$ref": "#/definitions/Property3"
}
},
"Property4": {
"type": "array",
"items": {
"$ref": "#/definitions/Property4"
}
}
},
"definitions": {
"Property1": {
"type": "object",
"properties": {
"Property1_1": {
"type": "string"
},
"Property1_2": {
"type": "boolean"
},
"Property1_3": {
"type": "integer"
},
"Property1_4": {
"type": "integer"
}
}
},
"Property2": {
"type": "object",
"properties": {
"Property2_1": {
"$ref": "#/definitions/Property2_1"
},
"Property2_2": {
"$ref": "#/definitions/Property2_2"
}
}
},
"Property2_1": {
"type": "object",
"properties": {
"Property2_1_1": {
"type": "array",
"items": {
"$ref": "#/definitions/Property2_1_1"
}
},
"Property2_1_2": {
"type": "array",
"items": {
"$ref": "#/definitions/Property2_1_2"
}
},
"Property2_1_3": {
"type": "array",
"items": {
"$ref": "#/definitions/Property2_1_3"
}
},
"Property2_1_4": {
"type": "array",
"items": {
"$ref": "#/definitions/Property2_1_4"
}
}
}
},
"Property2_1_1": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
},
"_Comment": {
"type": "string"
}
}
},
"Property2_1_2": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
},
"_Comment": {
"type": "string"
}
}
},
"Property2_1_3": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
}
}
},
"Property2_1_4": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
}
}
},
"Property2_2": {
"type": "object",
"properties": {
"dtm_file_name": {
"type": "string"
},
"dtm_file_name_ext": {
"type": "string"
},
"_Comment": {
"type": "string"
}
}
},
"Property3": {
"type": "object",
"properties": {
"offset": {
"type": "integer"
},
"value": {
"type": "string"
}
}
},
"Property4": {
"type": "object",
"properties": {
"attr_name": {
"type": "string"
},
"offset": {
"type": "integer"
}
}
}
}
}
Got the above JSON using:
JsonSchema bodySchema = JsonSchema.FromSampleJson(jsonStr);
string schemaStr = bodySchema.ToJson();
How can I remove these references and replace to the actual structures?
Such as:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Property1": {
"type": "object",
"properties": {
"Property1_1": {
"type": "string"
},
"Property1_2": {
"type": "boolean"
},
"Property1_3": {
"type": "integer"
},
"Property1_4": {
"type": "integer"
}
}
},
"Property2": {
"type": "object",
"properties": {
"Property2_1": {
"type": "object",
"properties": {
"Property2_1_1": {
"type": "array",
"items": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
},
"_Comment": {
"type": "string"
}
}
}
},
"Property2_1_2": {
"type": "array",
"items": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
},
"_Comment": {
"type": "string"
}
}
}
},
"Property2_1_3": {
"type": "array",
"items": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
}
}
}
},
"Property2_1_4": {
"type": "array",
"items": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"interface": {
"type": "string"
}
}
}
}
}
},
"Property2_2": {
"type": "object",
"properties": {
"dtm_file_name": {
"type": "string"
},
"dtm_file_name_ext": {
"type": "string"
},
"_Comment": {
"type": "string"
}
}
}
}
},
"Property3": {
"type": "array",
"items": {
"type": "object",
"properties": {
"offset": {
"type": "integer"
},
"value": {
"type": "string"
}
}
}
},
"Property4": {
"type": "array",
"items": {
"type": "object",
"properties": {
"attr_name": {
"type": "string"
},
"offset": {
"type": "integer"
}
}
}
}
}
}
Is there any method that does that inside NJsonSchema or some other way?
Regards,
Thiago