donalfenwick / Swashbuckle.SwaggerToPostman

AspNetCore middleware which uses the Swashbuckle.AspNetCore library produce a postman collection (v2.1) from the swagger schema generated by swashbuckle.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Swashbuckle.SwaggerToPostman

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.

Instalation

Note: This plugin will install swashbuckle as a dependency and requires that you also configure it within your aspnet core project

  1. Install the latest version from here on nuget NOTE: This is an alpha version

  2. 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();
  }
  1. 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 is v1.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseMvc();
    app.UseSwagger();

    app.UseSwaggerToPostman();
}

Importing the collection in postman

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.

About

AspNetCore middleware which uses the Swashbuckle.AspNetCore library produce a postman collection (v2.1) from the swagger schema generated by swashbuckle.

License:MIT License


Languages

Language:C# 100.0%