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

improve definition of keyword relationships (affects and affectedBy) #125

Merged
merged 2 commits into from
Jun 5, 2024

Conversation

sebastian-toepfer
Copy link
Owner

@sebastian-toepfer sebastian-toepfer commented Jun 3, 2024

The current implementation is very limited. To change the functionality of a relationship, the keywords themselves must be changed (violation of the Openclose principle).

AffectedBy

AffectedBy defines a relationship where the output is affected by the defined keywords. In most cases, this means that a “true” can be changed to a “false” (e.g. maxContains for contains) or simply defines which data the keyword affects (e.g. additionalProperties uses properties and patternProperties). In some cases, however, the presence of the other keyword means that the keyword in question can deliver neither true nor false (e.g. minContains for contains).
To solve this problem without completely linking the keywords, we define the type of relationship (AffectByType).
AffectType:
Extends means that the keyword is fully evaluated, but the true output can be affected by another keyword and changed to false.
Replace means that the keyword is not evaluated (neither as an applicator nor as an assertion), but the other keyword takes over completely.

sample for contains Keyword:

new AffectedByKeywordType(
    ContainsKeyword.NAME,
    List.of(
        new AffectedBy(AffectByType.REPLACE, "minContains"),
        new AffectedBy(AffectByType.EXTENDS, "maxContains")
    ),
    new SubSchemaKeywordType(ContainsKeyword.NAME, ContainsKeyword::new)::createKeyword
)

Affects

Affects defines keywords that are modified by this keyword. In most cases, the absence of this keyword is not a big problem, but for some it means that the other is not needed (e.g. minContains has no meaning without contains)
Solution Affects becomes a default value if keyword is absent.

@sebastian-toepfer sebastian-toepfer changed the title improve definition auf keyword relationships (affects and affectedBy) improve definition of keyword relationships (affects and affectedBy) Jun 3, 2024
@sebastian-toepfer sebastian-toepfer force-pushed the improve_keyword_relationship branch 2 times, most recently from 04b459e to ba0012a Compare June 3, 2024 18:59
…eyword

instead of define a affectedBy relationship with list of strings we us
a list of new introduces object AffectedBy with a name (the old
string) and a new AffectByType. The AffectByType can be
Extends this only shows that the keyword stays not alone and the
validation result can be altered. Or Replace with how the names say
replace the affected keyword with the affectedBy keyword. this allow
to change the validation result in both directions und a more flexible
way to do it.
@sebastian-toepfer sebastian-toepfer force-pushed the improve_keyword_relationship branch 2 times, most recently from a8f4036 to e2ca6c0 Compare June 5, 2024 19:32
@sebastian-toepfer sebastian-toepfer marked this pull request as ready for review June 5, 2024 19:36
instead of define a affects relationship with list of strings we us
a list of new introduces object Affects with a name (the old
string) and a new AbsenceStrategy. The AbsenceStrategy can be use to
define what should be happens if the keyword is missing.
At default is exists two:
Provide a default value -> useful if the affected works without the affectedBy one
Replace -> useful if the affected doesn't works without the affectedBy one
Copy link

sonarcloud bot commented Jun 5, 2024

@sebastian-toepfer sebastian-toepfer merged commit b52da05 into main Jun 5, 2024
2 checks passed
@sebastian-toepfer sebastian-toepfer deleted the improve_keyword_relationship branch June 5, 2024 19:48
@sebastian-toepfer sebastian-toepfer added this to the 0.3.0 milestone Jun 5, 2024
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

Successfully merging this pull request may close these issues.

1 participant