RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.24k forks source link

Unable to load Swagger API documentation with ODATA controller #2422

Open itsmegopi opened 4 years ago

itsmegopi commented 4 years ago

We are trying to map the OData with NSwag but we are ended up lot of issues. We are using OData controllers instead of ControllerBase

Startup file configuration services.AddOData(); services.AddSwaggerDocument();

Configure method app.UseMvc(builder => { builder.Select().Filter().Expand().MaxTop(1000).Count(); builder.MapODataServiceRoute("ODataRoutes", "api/v1", GetEdmModel(app.ApplicationServices)); builder.EnableDependencyInjection(); }); app.UseSwagger(); app.UseSwaggerUi3();`

Following is my controller

[Route("api/[controller]")] [ApiController]

public class ValuesController : Microsoft.AspNet.OData.ODataController
{
    // GET api/values
    [HttpGet]
    public ActionResult<IEnumerable<string>> Get()
    {
        return new string[] { "value1", "value2" };

    // GET api/values/5
    [HttpGet("{id}")]
    public ActionResult<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)
    {
    }
}

We getting error like " /swagger/{documentName}/swagger.json"

Thanks

RicoSuter commented 4 years ago

I think odata is not really supported but there might be solutions in other issues in the issue tracker, search for odata (also closed).

manisha201301 commented 4 years ago

https://github.com/microsoft/aspnet-api-versioning/issues/519

This has a wrok-around