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

How to create a rule for enum validation? #137

Open
deiteris opened this issue Mar 19, 2023 · 3 comments
Open

How to create a rule for enum validation? #137

deiteris opened this issue Mar 19, 2023 · 3 comments

Comments

@deiteris
Copy link

deiteris commented Mar 19, 2023

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
Copy link
Contributor

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
Copy link
Contributor

My bad, just realized you are in the correct repo

@nschejtman
Copy link
Contributor

This is the issue in our tracker for this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants