Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why swagger return "Failed to load api definition"?

This is my code.
I’m trying to overload GET with 2 function :

  • With one parameter
  • With two parameter

I’m getting Swagger error "Failed to load API definition". Why ?

[Route("api/[controller]")]
[ApiController] 
public class HospitalizedController : ControllerBase
{
    [HttpGet("")]
    public string Get(string MedicID)
    {
        string jsonData;

        string connString = gsUtils.GetDbConnectionString();
        // dosomething
    
    }

    [HttpGet("")]
    public string Get(string MedicID, string PatientID)
    {
        string jsonData;

        string connString = gsUtils.GetDbConnectionString();
        
        //do something
    }

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The error "Failed to load API definition" occurs because the two methods are on the same Route.

You can specify a more specific route to distinguish them, like this:

[Route("api/[controller]")]
[ApiController] 
public class HospitalizedController : ControllerBase
{
    [HttpGet]
    [Route("{medicId}")]
    public string Get(string medicID)
    {
    
    }

    [HttpGet]
    [Route("{medicId}/patients/{patientId}")]
    public string Get(string medicID, string patientID)
    {

    }

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading