Skip to content
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

Improve ApiVersioning support by automatically generate routes using Controllers definitions #1524

Open
OculiViridi opened this issue Aug 9, 2018 · 2 comments

Comments

@OculiViridi
Copy link

Following #1393 and #1355, I'm only suggesting a possible approach for a better API Versioning support.

It would be really useful and less mistake-prone if NSwag could handle the different decleared versions of an API automatically.
Actually, by following #1393, all the different versions of API needs to be registered and configure manually in Startup (version number matching the one in the Controller Attribute, files, etc.).
A possible different approach could be to have something like this:

app.UseSwaggerUi3(typeof(Startup).GetTypeInfo().Assembly, config =>
{
	/* Looks inside Controllers for all ApiVersion() attributes and generates a route and a JSON file for each one.
	 * Also the DefaultUrlTemplate property could be taken from Route() controller attribute, if present.
	 */
	config.GeneratorSettings.UseMultipleVersions = true;
	config.SwaggerRoutes.LoadFromControllers();

	// Generic settings for all routes
	config.GeneratorSettings.Title = "My Amazing API";
	config.GeneratorSettings.Description = "Amazing API functionalities.";
	
	// Specific settings for single route
	foreach (var route in config.SwaggerRoutes)
	{
		route.DefaultUrlTemplate = "{v:apiVersion}/{controller}/{action}/{id?}";
		route.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase;
	}
});

Thank you!

@alexsandro-xpt
Copy link

Some news about that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants