aml-org / amf-custom-validator

Other
7 stars 0 forks source link

How to create a rule for enum validation? #137

Open deiteris opened 1 year ago

deiteris commented 1 year ago

I've been following the tutorial for custom validation, but I wasn't able to figure out how to validate enums correctly.

If we consider the following RAML file:

#%RAML 1.0 Library

types:
    ScalarEnumType:
        type: string
        enum: [val1, val2]

That will generate the following graph:

{
    "@graph": [
        {
            "@id": "#4",
            "@type": [
                "doc:APIContractProcessingData"
            ],
            "apiContract:modelVersion": "3.8.1",
            "doc:transformed": true,
            "doc:sourceSpec": "RAML 1.0"
        },
        {
            "@id": "",
            "doc:declares": [
                {
                    "@id": "#1"
                }
            ],
            "@type": [
                "doc:Module",
                "doc:Unit"
            ],
            "doc:root": true,
            "doc:processingData": {
                "@id": "#4"
            }
        },
        {
            "@id": "#1",
            "@type": [
                "raml-shapes:ScalarShape",
                "raml-shapes:AnyShape",
                "sh:Shape",
                "raml-shapes:Shape",
                "doc:DomainElement"
            ],
            "sh:datatype": [
                {
                    "@id": "http://www.w3.org/2001/XMLSchema#string"
                }
            ],
            "sh:name": "ScalarEnumType",
            "sh:in": {
                "@id": "#1/list"
            }
        },
        {
            "@id": "#1/list",
            "@type": "rdfs:Seq",
            "rdfs:_1": {
                "@id": "#2"
            },
            "rdfs:_2": {
                "@id": "#3"
            }
        },
        {
            "@id": "#2",
            "@type": [
                "data:Scalar",
                "data:Node",
                "doc:DomainElement"
            ],
            "data:value": "val1",
            "sh:datatype": [
                {
                    "@id": "http://www.w3.org/2001/XMLSchema#string"
                }
            ],
            "core:name": "scalar_1"
        },
        {
            "@id": "#3",
            "@type": [
                "data:Scalar",
                "data:Node",
                "doc:DomainElement"
            ],
            "data:value": "val2",
            "sh:datatype": [
                {
                    "@id": "http://www.w3.org/2001/XMLSchema#string"
                }
            ],
            "core:name": "scalar_2"
        }
    ],
    "@context": {
        "@base": "amf://id",
        "raml-shapes": "http://a.ml/vocabularies/shapes#",
        "data": "http://a.ml/vocabularies/data#",
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
        "doc": "http://a.ml/vocabularies/document#",
        "apiContract": "http://a.ml/vocabularies/apiContract#",
        "core": "http://a.ml/vocabularies/core#",
        "sh": "http://www.w3.org/ns/shacl#"
    }
}

I see that I should be able to access the shacl:in property of the raml-shapes:ScalarShape class. But how can access RDF members that are represented as enumerated properties (rdfs:_1 and rdfs:_2)? With AMF4, I've been able to achieve this using functionConstraint with javascript code, but it seems to be no longer possible.

nschejtman commented 1 year ago

You are using this tool https://github.com/aml-org/amf-custom-validator correct?

If that is the case:

  1. You are right, at the moment you can't
  2. Please raise an issue in that repo so I can report a feature request and link to it
nschejtman commented 1 year ago

My bad, just realized you are in the correct repo

nschejtman commented 1 year ago

This is the issue in our tracker for this case