i have standard ASP.NET application with controllers and what i try to do is to pass complex object as a parameter of the HttpGet request.

Like :

  [HttpGet(Name = "GetWeatherForecast")]
    
    public IEnumerable<WeatherForecast> Get([FromQuery]MyParam? myParam)
    
    {
    
    return Enumerable.Range(1, 5).Select(index => new WeatherForecast
    
    {
    
    Date = DateTime.Now.AddDays(index),
    
    TemperatureC = Random.Shared.Next(-20, 55),
    
    Summary = Summaries[Random.Shared.Next(Summaries.Length)]
    
    })
    
    .ToArray();
    
    }

MyParam class looks as follows :

public class MyParam

{

public string Name { get; set; }

public string StringValue { get; set; }

public int IntValue { get; set; }

}

What can be a reason that MyParam class is not added to the schema and i see it’s structure flattened in the parameters section of the Get request in the Swagger?

I see 3 different parameters Name, StringValue and IntValue as a Get parameters.

If i change my class definition as follows (from properties to class members) MyParam class is added to schema and i see one parameter which is called myParam and i should provide json to populate it.

public class MyParam

{

public string Name;

public string StringValue ;

public int IntValue ;

}

I don’t understand this behavior and i want to achieve the same result that i get with class members but with properties.

Thank you!