Content Delivery API & SwaggerGen #14858
Closed
TradeSmash
started this conversation in
Features and ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It'd be great if we could extend models builder to help generate swagger schemas for our document types.
For those using TypeScript, having this capability would be great as it saves a lot of time doing our own mappings and possibly run into issues where the types are out of date with the CMS.
I've got a very, very basic implementation using Document Filters, which doesn't really cover complex properties such as block lists.
public static class ReflectionUtility { public static IEnumerable<Type> GetTypesInheritingFrom(Type baseType, params Assembly[] assemblies) { return assemblies.SelectMany(assembly => assembly.GetTypes()) .Where(type => baseType.IsAssignableFrom(type) && type is { IsAbstract: false, IsClass: true }); } }
`
public class CustomDocumentFilter : IDocumentFilter
{
private readonly IEnumerable _contentModelTypes;
}
`
`
services.AddSwaggerGen(options =>
{
var coreAssembly = Assembly.Load("SampleProject.Core");
var contentModelTypes = ReflectionUtility.GetTypesInheritingFrom(typeof(PublishedContentModel), coreAssembly).ToList();
`
And here's the output:

Beta Was this translation helpful? Give feedback.
All reactions