To avoid trying to replicate the logic which servicestack uses to find the RequestDTO types for exposing externally, is there a public method I can call which servicestack also uses for this operation?
Externally you can get all the metadata used to generate the types at /types/metadata
e.g:
This is the source code to implement the service which you can re-use yourself internally:
public INativeTypesMetadata NativeTypesMetadata { get; set; }
public MetadataTypes Any(TypesMetadata request)
{
var typesConfig = NativeTypesMetadata.GetConfig(request);
var metadataTypes = NativeTypesMetadata.GetMetadataTypes(Request, typesConfig);
return metadataTypes;
}
However what’s returned are DTO’s, i.e. they don’t contain the original C# Type
, for that you need to get it from the metadata:
HostContext.Metadata
This contains all the operation and type metadata however determining whether to show the type can only be done at runtime since it’s based on the incoming Request, you can use the IsVisible()
API’s for this at:
HostContext.Metadata.IsVisible()
It’s for a plugin so I can’t really base the filter on an incoming request as I won’t have finished loading the apphost and like working out the hosting url:port, I’m a bit too early in the pipeline for that stuff so I have to improvise a bit.
I’ll try and work out something from what you’ve posted as I feel I am going down a painful/wrong route with the query below. Thanks for the help btw, much appreciated.
var nativeTypes = host.GetPlugin<NativeTypesFeature>();
var requestTypes =
host.Metadata.RequestTypes
.Where(x => x.AllAttributes<ExcludeAttribute>().All(a => a.Feature != Feature.Metadata))
.Where(x => !nativeTypes.MetadataTypesConfig.IgnoreTypes.Contains(x))
.Where(x => !nativeTypes.MetadataTypesConfig.IgnoreTypesInNamespaces.Contains(x.Namespace))
// need to also exclude restricted externally types?
//.Where(x => x.AllAttributes<RestrictAttribute>().Any(a => a.VisibilityTo == RequestAttributes.External)).ToArray();