Skip to content

gen-shacl rules: translate any_of (and the other boolean operators) in rule conditions, as gen-json-schema does #54

Open

Description

@jdsika

Corrected 2026-10-15. This issue first said the rule is dropped silently. That doesn't hold on linkml#3990 (c48bb2a47) or #14 (536d6f194): gen-shacl logs WARNING … Rule 2 of class 'Thing': skipped, because its postconditions use any_of. Warnings name a rule by index and description, not title, so a search for the title finds nothing. Dropping the sibling slot_conditions follows linkml#3989's contract that a rule is translated whole or skipped. On upstream main such rules are skipped at DEBUG level only; linkml#3989 raises that to a warning. #48 is unrelated (class expressions on subclasses).

What

gen-shacl skips every rule whose conditions use an expression-level any_of (likewise all_of, exactly_one_of, none_of). gen-json-schema enforces the same rule, so the two disagree on the same instances.

Reproduction (linkml#3990 head c48bb2a47)

id: https://example.org/m
name: m
prefixes:
  ex: https://example.org/m/
  linkml: https://w3id.org/linkml/
default_prefix: ex
default_range: string
imports: [linkml:types]
classes:
  Thing:
    tree_root: true
    attributes:
      kind:   {range: string}
      status: {range: string}
      level:  {range: integer}
    rules:
      - preconditions:
          slot_conditions:
            kind: {equals_string: b}
        postconditions:
          slot_conditions:
            level: {minimum_value: 1}
          any_of:
            - slot_conditions:
                status: {equals_string: ok}
            - slot_conditions:
                status: {equals_string: fine}

gen-json-schema's then is {"anyOf": [{"properties": {"status": {"const": "ok"}}, "required": ["status"]}, {… "fine" …}], "properties": {"level": {"minimum": 1}}, "required": ["level"]}.

Instance (kind: b) JSON Schema SHACL (pyshacl)
level: 2, status: ok valid conforms
level: 2, status: bad invalid conforms
level: 0, status: ok invalid conforms

Proposed fix

Acceptance criteria

  • _json_schema_and_shacl_verdicts (test_shaclgen.py) agrees for any_of in postconditions, with sibling slot_conditions, and under open_world. The other three operators are translated the same way or stay skipped with a warning.
  • Skip warnings name the rule title when it has one.

Base: linkml#3990 (fork #20).

Activity

  1. changed the title [-]gen-shacl rules: a postcondition block containing any_of is dropped whole and silently, taking its sibling slot_conditions with it[/-] [+]gen-shacl rules: translate any_of (and the other boolean operators) in rule conditions, as gen-json-schema does[/+] on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions