Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discuss new LinkType.Top #201

Closed
sergey-litvinov-work opened this issue Sep 24, 2018 · 3 comments
Closed

Discuss new LinkType.Top #201

sergey-litvinov-work opened this issue Sep 24, 2018 · 3 comments

Comments

@sergey-litvinov-work
Copy link
Contributor

sergey-litvinov-work commented Sep 24, 2018

Hi Jouke,

I wanted to ask one thing and i can make PR to add it, but wanted to get your opinion about it.

We have a case when we have endpoint that returns collection of items and we don't want to add additional endpoint to get specific item. The problem with the links as by default it will generate both self in each item and then links->self at top level. We want to be able to generate top level self but without self on each item level.

Right now it's impossible as if i set WithLinks(Saule.LinkType.Related); in the resource description, then it wont generate both self links and we need that top one.

Is it ok to add LinkType.Top like this

public enum Test
{
        /// <summary>
        /// No links
        /// </summary>
        None = 0,

        /// <summary>
        /// Only self links
        /// </summary>
        Self = 1,

        /// <summary>
        /// Only related links
        /// </summary>
        Related = 2,

        /// <summary>
        /// Only top links
        /// </summary>
        Top = 4,

        /// <summary>
        /// Generate all possible links
        /// </summary>
        All = ~None
}

So then i can specify LinkTypes.Top and it will display only top links.self section without self for each item.

And to prevent existing behavior i can check in the code (ResourceSerializer.CreateTopLevelLinks) to render top self link only if

if (_resource.LinkType.HasFlag(LinkType.Top) && !_resource.LinkType.HasFlag(LinkType.Self)
 || _resource.LinkType.HasFlag(LinkType.Self))
{
      result.Add("self", _baseUrl);
}

So existing code will work fine as Self would be treated as Top too. And if someone doesnt want it, then he can specify it in the resource as LinkType.Top & ~LinkType.Self

@joukevandermaas
Copy link
Owner

I think this makes sense, but I'm not sure I understand the reasoning for calling this Top. It sounds like it means "add the link for the collection, but not the items". Could we call it something like CollectionSelf? In any case I think it should have Self in the name. Does that make sense to you?

@sergey-litvinov-work
Copy link
Contributor Author

Totally makes sense. And as i renamed it to TopSelf and you merged it, i'm closing this defect. Thanks!

@sergey-litvinov-work
Copy link
Contributor Author

@joukevandermaas or if you think that CollectionSelf is better, i can rename it and make new PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants