quijames
quijames

Reputation: 537

How to generate Swagger 1.2 JSON with .NET Web API

We're trying to generate Swagger 1.2 spec JSON for our .NET Web API. I've tried using Swashbuckle, but it only seems to generate Swagger 2.0 spec JSON.

Does anyone know how to generate Swagger 1.2 JSON from a .NET Web API (using Swashbuckle or not)?

Upvotes: 3

Views: 2453

Answers (2)

user3558233
user3558233

Reputation: 1

This swagger.json file can be generated as an ouput of the project build, using swagger. In your webApi .csproj file, add this section:

<Target Name="NSwag" AfterTargets="Build">
    <Exec Command="$(NSwagExe) webapi2swagger /infotitle:&quot;$(AssemblyName)&quot; /assembly:$(TargetPath) /output:$(OutDir)/$(AssemblyName).swagger.json" />
  </Target>

You also need to attribute your API controller methods like this, e.g.: [SwaggerResponse(HttpStatusCode.OK, Type = typeof(object))]

Upvotes: 0

Ron
Ron

Reputation: 14840

Not really sure why you want to use Swagger 1.2 over Swagger 2.0, but you can still use Swashbuckle, only an older version of it such as https://github.com/domaindrivendev/Swashbuckle/tree/v4.2.0.

Upvotes: 2

Related Questions