w3c / wot-thing-description-toolchain-tmp

work area for WoT Thing Description toolchain
2 stars 1 forks source link

LinkML JSON Schema Generator #29

Open mahdanoura opened 4 months ago

mahdanoura commented 4 months ago

LinkML support composition terms like anyOf, allOf, etc. The following snippet is how I model the security term as a class.

security:
        description: >-
          A Thing may define abstract security schemes, used to configure the secure access of (a set of) affordance(s).
        from_schema: td:definesSecurityScheme
        required: true
        exactly_one_of:
          - range: string
            multivalued: true
          - range: string

The following JSON Schema is generated from compositions:

"security": {
                    "description": "A Thing may define abstract security schemes, used to configure the secure access of (a set of) affordance(s).",
                    "oneOf": [
                        {
                            "items": {
                                "type": "string"
                            },
                            "type": "array"
                        },
                        {
                            "type": "string"
                        }
                    ],
                    "type": "string"
                }

The outer type in compositions are always translated to the type: "string". Sometimes we want a type Object in there. LinkML support the keyword: Any. But this will allow any object, which is not what we want in the json schema.

relu91 commented 4 months ago

Btw combing oneOf with type is actually allowed but JSON Schema is used to factor out similar properties. I hope it helps.