ASP.NET Core - Swashbuckle schaffen nicht Gewinn.json-Datei

Ich habe Probleme damit, die Swashbuckle.AspNetCore (1.0.0) Paket erzeugen keine Ausgabe. Ich lese die Angeberei.json-Datei geschrieben werden sollten '~/swagger/docs/v1'. Aber ich bekomme keine Ausgabe.

Begann ich mit einer neuen Marke ASP.NET Kern-API Projekt. Ich sollte erwähnen, das ist ASP.NET Core 2. Die API funktioniert, und ich bin in der Lage, abrufen von Werten aus den Werte-controller einwandfrei.

Meine startup-Klasse hat die Konfiguration genau wie in diesem Artikel beschrieben (Swashbuckle.AspNetCore auf GitHub).

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    //This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
        });
    }

    //This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();

            //Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyAPI V1");
            });
        }
        else
        {
            app.UseExceptionHandler();
        }

        app.UseStatusCodePages();
        app.UseMvc();

        //throw new Exception();
    }
}

Sehen Sie die NuGet-Referenzen...

ASP.NET Core - Swashbuckle schaffen nicht Gewinn.json-Datei

Wieder, dies ist die Standard-Vorlage, aber habe ich auch die ValuesController Referenz...

[Route("api/[controller]")]
public class ValuesController : Controller
{
    //GET api/values
    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    //GET api/values/5
    [HttpGet("{id}")]
    public string Get(int id)
    {
        return "value";
    }

    //POST api/values
    [HttpPost]
    public void Post([FromBody]string value)
    {
    }

    //PUT api/values/5
    [HttpPut("{id}")]
    public void Put(int id, [FromBody]string value)
    {
    }

    //DELETE api/values/5
    [HttpDelete("{id}")]
    public void Delete(int id)
    {
    }
}

InformationsquelleAutor John Livermore | 2018-01-25

Schreibe einen Kommentar