AspNetCore middleware which leverages the swagger doc schema information generated by the wonderful Swashbuckle.AspNetCore library to generate a JSON postman collection (schema version 2.1). This json document can be imported into the postman client application providing pre-populated requests for any api controllers included in the swagger doc schema.
Note: This plugin will install swashbuckle as a dependency and requires that you also configure it within your aspnet core project
-
Install the latest version from here on nuget NOTE: This is an alpha version
-
Call the services.AddSwaggerToPostman() extension method in the ConfigureServices method of your applications Startup.cs after the services.AddSwaggerGen() is called for the Swashbuckle library. This will register the required types in the applications DI container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "Swashbuckle to postman test API", Version = "v1" });
});
services.AddSwaggerToPostman();
}
-
Call the app.UseSwaggerToPostman() extension method from the Configure method in your Startup.cs class after you call to app.UseSwagger(). This will register the middleware in the api.net pipeline and expose a json document that can be imported by the postman http client.
By default, the route to this document is
~/postman/{documentname}/collection.json
where document name is the name provided in the options when calling AddSwaggerGen(). In the example above the document name isv1
.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc();
app.UseSwagger();
app.UseSwaggerToPostman();
}
To import the collection into postman click on the import button from the top menu within the app. In the modal that appears choose "Import from link" and paste your your postman collection url into the dialog box.
Please ensure that you are using a recent version of postman and choose schema version 2.1 if prompted during the import.