Using inheritance in DTO switches to "consumes": ["application/x-www-form-urlencoded"]

Using inheritance in DTO switches to “consumes”: [“application/x-www-form-urlencoded”] instead of [“application/json”]

Example i have on DTO inhetring a base DTO (not to duplicate code).

    Summary = "Create call",
    Notes =
        "Create Test.",
    Verbs = "POST")]
[ApiResponse(HttpStatusCode.Unauthorized, "You were unauthorized to call this service")]
public class CreateTest : TestBase,IInterval,IReturn<TestResponse>
        Description =
            "The datetime you want to start the test.",
        IsRequired = true)]
    public DateTime From { get; set; }

public class TestBase
        Description =
            "The company id, if empty will use the company id for the user you are logged in with.",
        IsRequired = false)]
    public Guid? CompanyId { get; set; }


I’ve created a new empty project with these DTOs and I’m not seeing the change you’re reporting, with or without the base class, it’s always returning:

You can use an Operation Filter to modify the Open API Response.

As for the rationale, I’d recommend against using base classes for hiding the intent of declarative service DTO contracts:

Thx Mytz,

How can i set that all service return

"consumes": “application/json” instead of application/x-www-form-urlencoded

Have you tried using the OperationFilter I linked to?

yes we are using it this way but not sure how to set the consumes.

Plugins.Add(new OpenApiFeature { OperationFilter = (verb, operation) => operation.Parameters.RemoveAll(x => x.In =="formData" ) });

There’s a Consumes property on operation which maps to the same property in Open API format.

The entire Open API DTO can be modified by the Open API Filters before it’s returned and serialized so you can modify every Open API Scheme v2 property that’s serialized, e.g:

Plugins.Add(new OpenApiFeature { 
    OperationFilter = (verb, operation) => 
        operation.Consumes = new List<string> { "application/json" } 

Thx for this. Will check this!