ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 8 forks source link

Comma separated tags are shown different in the metadata page or API Explorer #788

Closed digiofficerobin closed 1 year ago

digiofficerobin commented 1 year ago

Describe the issue

Create a request with tags, such as this:

[Tag("Tag1,Tag2")]
[Route("/projects", "GET")]
public class GetProjects : IReturn<List<Project>>
{
    public string SearchCriteria { get; set; }
}

[Tag("Tag2,Tag3")]
[Route("/projects", "GET")]
public class GetProjectsV2 : IReturn<List<Project>>
{
    public string SearchCriteria { get; set; }
}

public class Project
{
    public int ID { get; set; }
    public Guid GlobalID { get; set; }
    public string Number { get; set; }
    public string Name { get; set; }
    public string Description1 { get; set; }
    public string Description2 { get; set; }
    public string Description { get; set; }
    public string City { get; set; }
    public bool Active { get; set; }
}

We can conveniently filter all requests in the metadata page with tag1, tag2 or tag3, but not in API Explorer or Swagger.

TaggingInServiceStack

We want to use this tagging feature to decorate APIs which are available since a certain release. I have made a ReleaseTagAttribute to automatically determine the in-between releases.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class ReleaseTagAttribute : TagAttribute
{
    public ReleaseTagAttribute() : this(null) { }
    public ReleaseTagAttribute(string since) => Name = getInnerReleaseTags(since, "2023.2");
    public ReleaseTagAttribute(string since, string until) => Name = getInnerReleaseTags(since, until);

    private string getInnerReleaseTags(string since, string until)
    {
        var sinceMajor = int.Parse(since.Split('.')[0]);
        var sinceMinor = int.Parse(since.Split('.')[1]);
        var untilMajor = int.Parse(until.Split('.')[0]);
        var untilMinor = int.Parse(until.Split('.')[1]);

        if (sinceMajor == untilMajor && sinceMinor == untilMinor)
        {
            return sinceMajor + "." + sinceMinor;
        }
        else
        {
            var nextMajor = sinceMajor;
            var nextMinor = sinceMinor;

            if (sinceMinor == 2)
            {
                nextMajor++;
                nextMinor = 1;
            }
            else
            {
                nextMinor++;
            }

            return sinceMajor + "." + sinceMinor + "," + getInnerReleaseTags(nextMajor + "." + nextMinor, until);
        }
    }
}

Example in metadata page with release number decoration on the two GetProjects requests: image

In API Explorer the commas are not separated as different groups: image

In Swagger UI the tags are also not seen as unique tags: image

Can this issue be solved one way or the other?

Reproduction

see issue description

Expected behavior

see issue description

System Info

ServiceStack 6.4.0

Additional context

No response

Validations

mythz commented 1 year ago

Tags with commas are not supported, you need to use multiple [Tag] attributes to apply multiple tags to a Request DTO:

[Tag("Tag1"),Tag("Tag2")]
[Route("/projects", "GET")]
public class GetProjects : IReturn<List<Project>>
{
    public string SearchCriteria { get; set; }
}
digiofficerobin commented 1 year ago

I don't want to add multiple tags by hand for every release, but I want to tag the services automatically from the initial release when the request was introduced to the current release. I'll try to use the https://docs.servicestack.net/reflection-utils#dynamically-adding-attributes feature to add the in-between release tags.