Search code examples
servicestack

Array fields are not showing in FORM tab of ServiceStack API Explorer (/ui)


I have this request DTO with several fields, including a string array (Sort)

public partial class SelectTiers : IReturn<SelectTiersResponse>, IGet
{
    public string? SearchText { get; set; }

    public string[]? Sort { get; set; }

    public int? Skip { get; set; }

    public int? Take { get; set; }
}

The corresponding page of the API explorer shows 3 inputs : SearchText, Skip and Take, but none for Sort.

enter image description here

I know it's not recommended to put complex types in GET requests but ServiceStack handles this nicely with JSV serialization.

Is there a way to show a input for these fields (at least for simples array types) ? I've tried to add a [Input(Type = "text")] to the property with no success

Edit: using ServiceStack 6.11

Thank you


Solution

  • Only types for which there exists HTML Form Inputs will be rendered which is why no Form Inputs are rendered for any Complex Types by default.

    The only built-in Vue Component that supports a List of strings is the TagInput or Combobox components which you can specify with the [Input(Type)] attribute, e.g:

    public partial class SelectTiers : IReturn<SelectTiersResponse>, IGet
    {
        public string? SearchText { get; set; }
    
        [Input(Type="tag")]
        public string[]? Sort { get; set; }
    
        public int? Skip { get; set; }
    
        public int? Take { get; set; }
    }
    

    The Combobox is a good for when you need to select from pre-defined options.

    Alternatively you can register and use your own Custom Vue Component to manage your complex data types.