linkml icon indicating copy to clipboard operation
linkml copied to clipboard

exactly_one_of with range: does not work as expected when using linkml:types

Open jat255 opened this issue 1 year ago • 1 comments

Describe the bug If an import of linkml:types is used in a model definition, the resulting JSON Schema is not correct when using exactly_one_of. Using the yaml provided below, running linkml generate json-schema results in the following, with an unexpected "type": "string" declaration:

    ...
    "properties": {
        "metadata": {
            "description": "An attribute consisting of one of a number of mixin classes",
            "oneOf": [
                {
                    "$ref": "#/$defs/MixinOne"
                },
                {
                    "$ref": "#/$defs/MixinTwo"
                },
                {
                    "$ref": "#/$defs/MixinThree"
                }
            ],
            "type": "string"
        }
    },
    ...

This results in the following JSON not being properly validated, even though it should:

{
    "metadata": {
        "sub_value_one": "test string"
    }
}

with a validation output of:

[ERROR] [demo_data.json/0] {'sub_value_one': 'test string'} is not of type 'string' in /metadata

If I remove the import of linkml:types, things work as expected, but then I cannot use linkml generate doc, since it gives me an error about AttributeError: type object 'NoneType' has no attribute 'class_name'

Version of LinkML you are using 1.8.2 installed via pip

Please provide a schema (and if applicable, a data file) that replicates the issue

id: example-schema
name: example-schema
title: example-schema
default_range: string
prefixes:
  linkml: https://w3id.org/linkml/

imports:
  - linkml:types

classes:
  Root:
    tree_root: true
    attributes:
      metadata:
        description: An attribute consisting of one of a number of mixin classes
        exactly_one_of:
          - range: MixinOne
          - range: MixinTwo
          - range: MixinThree

  MixinOne:
    is_a: Root
    attributes:
      sub_value_one:
  
  MixinTwo:
    is_a: Root
    attributes:
      sub_value_two:

  MixinThree:
    is_a: Root
    attributes:
      sub_value_three:

jat255 avatar Aug 22 '24 05:08 jat255

When generating documentation, it also shows an incorrect range (although it matches the JSON schema in some ways):

image

In this example, the range should just be MixinOne or MixinTwo or MixinThree, not String or MixinOne or MixinTwo or MixinThree

jat255 avatar Aug 22 '24 06:08 jat255