-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't work without AddService for examples provider #124
Comments
Have a re-read of the Installation section.
|
But all the classes are in the same assembly as the Startup class, so why wouldn't |
Swashbuckle enables filters by calling
Because I hadn't though of doing that 😀 Sounds like a good idea, and it would make the installation of the examples filter easier. We could leave the |
NP, and BTW thanks for putting this on github, will definitely be using it! |
I just had a go at implementing this, by changing my ExampleFilters extension method to take a service collection: public static void ExampleFilters(this SwaggerGenOptions swaggerGenOptions, IServiceCollection services)
{
services.AddSwaggerExamplesFromAssemblies(Assembly.GetExecutingAssembly());
ExampleFilters(swaggerGenOptions);
} which can be called via services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v2" });
options.ExampleFilters(services); It looks like it should work, I can see the Examples get registered with the ServiceCollection... but when I run my test project, it falls over at runtime 😥:
|
"Then all you need to do is implement IExamplesProvider...and that's it"
Really? Not only can I not get this to work as described, but looking at the source code I can't see any way it could ever work, as the operation filter requires that your examples provider be registered with the service provider.
I did manage to get it to work using
services.AddSingleton<IExamplesProvider<FooBarRequest>,FooBarRequestExampleProvider>();
in my app Startup, but I don't see where it says you need this?
The text was updated successfully, but these errors were encountered: