Closed rquackenbush closed 1 year ago
Hi @rquackenbush
The result of Parse
already flattens all the elements from both interfaces. If you want to enumerate just the interfaces, you can filter the results:
var result = parser.Parse(jsonTexts);
foreach (DTInterfaceInfo item in result
.Where(r => r.Value.EntityKind == DTEntityKind.Interface)
.Select( i => (DTInterfaceInfo)i.Value))
{
Console.WriteLine(item.Id);
}
If you want to just enumerate the properties, the .Properties
already exposes the flattened list of properties.
@rido-min oh wow - thanks for that response. I hadn't thought about approaching it from that angle.
The last piece - how do we turn those results into json? The constructors for the model objects all appear to be internal:
For example: DTInterfaceInfo
ParseToJson will return the JSON serialized view of the dictionary.
also, check out the DTDLParserJSInteropSample to see how to consume the JSON using the provided typings.
That works! Thank you!
We're currently working on a project where we need the "effective" or "flattened" model definition. In other words, given the following models:
vehicle.json
car.json
We want the effective or flatted schema for dtmi:example:Car;1 - which would be:
We're planning on doing this with json manipulation, but this might be useful to other folks as well.
Proposed Solution
Perhaps add something like a
FlattenInterface
extension method: