Skip to content

Default attribute capabilities #707

Closed
@bart-degreed

Description

@bart-degreed

What my team loves about JADNC is that resource properties require explicit annotation to expose them (opt-in). This guards against someone adding a new entity property that gets exposed unintentionally, requiring a breaking change to fix that.

But the capabilities on such annotated properties are opt-out. Adding [Attr] without arguments makes them mutable, filterable and sortable. We'd like to require explicitly stating that as well, to prevent users searching on columns that are not indexed in the database, resulting in a full table scan that kills performance on large tables.

If changing the defaults for parameterless AttrAttribute is too much of a breaking change, we can add a fallback setting to IJonApiOptions that controls the parameterless behavior. For example:

options => options.DefaultAttributeCapabilities = AttributeCapabilities.None

Where AttributeCapabilities is defined as:

[Flags]
public enum AttributeCapabilities
{
  None = 0,
  AllowMutate = 1,
  AllowFilter = 2,
  AllowSort = 4,
  All = AllowMutate | AllowFilter | AllowSort
}

And then we can replace the existing constructor overload that takes multiple booleans with one that accepts these flags. For example:

public class Article : Identifyable
{
    [Attr(AttributeCapabilities.AllowFilter | AttributeCapabilities.AllowMutate)]
    public string Description { get; set; }
}

Which would improve code readability over a line like:

Attr(true, true, false)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions