Ignore error in layered architecture for specific parameters

Open
#1,458 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
testing

Research direction

Start by reading the layered architecture API and its dependency-condition tests; the issue does not name specific files or tests. Determine whether rules can distinguish a type used in a generic parameter from one used as a return value, and whether that distinction can be configured for selected parameters. Done means the example can ignore the generic-parameter dependency while still reporting the return-value dependency.

Written by the indexing model from the issue text.

Description

Hello, I was exploring the layered architecture and I was wondering if there was a way to ignore errors that are reported between different layers for specific parameters?

For example, we have a method in our controller:

@GetMapping("/users")
public List<UserDto> findUsers(Specification<UserDao> specification) {
    return userService.findBy(specification);
}

In the layered architecture., I have the rules:

    @ArchTest
    public static final ArchRule layersShouldOnlyBeAccessedByTheCorrectLayer = layeredArchitecture()
            .consideringOnlyDependenciesInLayers()
            .layer("Controller").definedBy("..controller..")
            .layer("Service").definedBy("..service..")
            .layer("Repository").definedBy("..repository..")
            .layer("Entity").definedBy("..entity..")
            .whereLayer("Controller").mayNotBeAccessedByAnyLayer()
            .whereLayer("Service").mayOnlyBeAccessedByLayers("Controller")
            .whereLayer("Repository").mayOnlyBeAccessedByLayers("Service")
            .whereLayer("Entity").mayOnlyBeAccessedByLayers("Service", "Repository");

In this instance, I would like to ignore that UserDao is used in a generic parameter but would like to report if the UserDao was used as a return value. Is this possible?

Dominant language
Java
Stars
3.9k
Forks
350
Avg merge
3d 2m
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TNG/ArchUnit

All issues in TNG/ArchUnit

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.