Recursive Data Type Metadata

Hi guys,

We’re running into an issue with metadata generation. We have a recursive data type for modeling dynamic data in our system and the two main fields in the DTO are below:

DataType Parameters:
Name	Parameter	Data Type	Required	Description
TypeName	form	string	No	
Fields	form	List<DataField>	No	

DataField Parameters:
Name	Parameter	Data Type	Required	Description
Id	form	string	No	
Name	form	string	No	
Type	form	ValueTypes	No	
UIHint	form	UIHints	No	
UITab	form	string	No	
IsAsync	form	bool	No	
DisableBinding	form	bool	No	
StructType	form	DataType	No	
ListType	form	DataType	No	
Description	form	string	No	
PossibleValues	form	List<string>	No	
IsOutput	form	bool	No	
CustomFieldValuesUrl	form	string	No	
DefaultValue	form	Value	No	
TransitionNameFormat	form	string	No	
Uniqueness	form	DataFieldUniqueness	No	
VoiceOnly	form	bool	No	
ConditionalVisibilityField	form	string	No	
ConditionalVisibilityValue	form	string	No	
NoEvalTemplate	form	bool	No	
UserMode	form	UserDataFieldModes	No	
AnyValueType	form	bool	No	

You’ll note that the DataType class has a list of DataFields and one of the optional fields on a DataField is the StructType which refers back to DataType.

When going to a metadata page for this it freezes for about 20 seconds and then spits out the metadata page with the example JSON taking multiple pages:

The issue isn’t the long example text but rather that when end users think the metadata page isn’t loading, they hit refresh a few times starting multiple instances of the metadata handler and the CPU spikes considerably.

I did some digging into the code and I can see that there is some sort of recursive counter that is used to break out of these types of data structures, but it would be great to be able to exclude certain fields from metadata or something without excluding entire requests.

Any thoughts? This is on servicestack 8.7.0

There’s a MaxDepth you can use to restrict the Maximum Depth the serializer should serialize up to:

JsConfig.MaxDepth = 5;

I’ve also just added support for customizing the Example Object used in the metadata pages with the new CreateExampleObjectFn property on the MetadataFeature plugin which you can customize like:

services.ConfigurePlugin<MetadataFeature>(feature => {
    feature.CreateExampleObjectFn = type => {
        if (type == typeof(CreateJob))
        {
            return new CreateJob {
                Title = "Example Job",
                Company = "Acme",
                Description = "Job Description",
                SalaryRangeLower = 50_000,
                SalaryRangeUpper = 100_000,
            };
        }
        if (type == typeof(Job))
        {
            return new Job {
                Id = 1,
                Description = "Job Description",
                Company = "Acme",
                SalaryRangeLower = 50_000,
                SalaryRangeUpper = 100_000,
                CreatedBy = "Admin",
                CreatedDate = DateTime.UtcNow.Date,
            };
        }
        return null;
    };
});

Returning null will use the default behavior.

This change is available in the latest v8.7.1 which is now available in the latest pre-release packages.

1 Like

AMAZING! Will give it a shot. Thank you!!

1 Like

Hey mythz, so I configured my AppHost in the Configure method as follows:

But when I go to the metadata page and click on a JSON link for one of my requests, that method is never called. Is there something else I need to do to get this working? Should I be calling this method somewhere else?

Tracked it down! User error. Sorry - this is working!

1 Like