6.02 - Overriding a DTO property results in 2 properties shown in API Explorer

I have a request model that inherits from a DTO. The request model overrides one of the DTO properties in order to decorate it with attributes which are specific to a request. This results in the API explorer display duplicate fields - one for the base DTO property and one for the property overridden in the request model. The property should only be rendered once by API explorer! Please confirm and advise fix ETA.

Thanks in advance.

Can you provide a screenshot of the issue and all C# Request DTOs that causes it please.

DTO:

public class Movie
{
    virtual public string MovieID { get; set; }
    virtual public int MovieNo { get; set; }
    virtual public string Name { get; set; }
    virtual public string Description { get; set; }
}

Request DTO:

public class MoviePOSTRequest : SSTest.DTOs.Movie, IReturn<SSTest.DTOs.Movie>
{
    [Input(Disabled = true)]
    public override string MovieID { get; set; }

    [Input(Disabled = true)]
    public override int MovieNo { get; set; }
}

Screenshot of resultant API Explorer render:

I have a simple sample project I can give you, but it seems that I am not allowed to upload *.zip type files to the forum.

VS2022 project demonstrating the issue (visit the MoviePOSTRequest route at http://localhost:8088/ui/MoviePOSTRequest):

1 Like

Thanks for the repro, this should now be resolved in the latest v6.0.3 release that’s now available on MyGet.

So you don’t have to create properties just to annotate them with [Input] attribute, I’ve added support for the [Field] class attribute you can annotate on Request DTOs with the property name to specify Input field properties, e.g. this is equivalent to your above DTO:

[Field(nameof(MovieID), Disabled = true)]
[Field(nameof(MovieNo), Disabled = true)]
public class MoviePOSTRequest : Movie, IReturn<Movie>
{
}

@Mythz - that only seems to work if I override the property. Adding the class decoration as you showed does not disable the field in the UI without also overriding the property in the inherited class.

This works:

[Field(nameof(MovieID), Disabled = true)]
[Field(nameof(MovieNo), Disabled = true)]
public class MoviePOSTRequest : Movie, IReturn<Movie>
{
    public override string MovieID { get => base.MovieID; set => base.MovieID = value; }
    public override string MovieNo { get => base.MovieNo; set => base.MovieNo = value; }
}

This does not:

 [Field(nameof(MovieID), Disabled = true)]
[Field(nameof(MovieNo), Disabled = true)]
public class MoviePOSTRequest : Movie, IReturn<Movie>
{
}

Weird it worked previously when I was testing it, will fix. Thx for reporting.

Nope it never worked with a base class property since the missing property has to be hosted into the subclass which is now done in the latest v6.0.3 that’s now available on MyGet.

I’ve also improved the auto split casing text, given the upper casing property names I’m seeing a lot of. In v6.0.3 this should now look like:

BTW I’m not sure what the purpose of disabling an input field on an API Form since it’s going to remain unpopulated.

Perhaps hiding it from the UI is preferable, which you can do with:

[Field(nameof(MovieID), Type="hidden")]
//...
[Input(Type="hidden")]
public string MovieID { get; set; }

Which styles it as hidden but leaves it in the DOM tree, you can also exclude it from the DOM entirely with:

[Field(nameof(MovieID), Ignore=true)]
//...
[Input(Ignore=true)]
public string MovieID { get; set; }
1 Like