Creating ruleset for API Governance - Anypoint Platform

233 views Asked by At
/example:    
      /{uriParams}:
        get:
          is: [defaultResponses, commonHeaders]
          uriParameters:
          uriParams:
          description: Example description uriParams
          body:
          application/json:
          example: !include examples.example.json

I would like creating the ruleset that checking the example !include and the traits (defaultResponse, commonHeaders) Now I have like this but this ruleset working separately.(It's mean that if I have ruleset with "traits" and "example" in the same file there is only working "traits". If I delete the ruleset from file "traits". It's working the ruleset "example".) But I would like that they working together. And also I'm trying doing ruleset for checking all fields are have name with camelCase example: "camelCase-exampleTwo"

    provide-examples:
        message: Always include examples in request and response bodies
        targetClass: apiContract.Payload
        rego: |
          schema = find with data.link as $node["http://a.ml/vocabularies/shapes#schema"]

          nested_nodes[examples] with data.nodes as object.get(schema, "http://a.ml/vocabularies/apiContract#examples", [])

   

          examples_from_this_payload = { element |
            example = examples[_]
            sourcemap = find with data.link as object.get(example, "http://a.ml/vocabularies/document-source-maps#sources", [])
            tracked_element = find with data.link as object.get(sourcemap, "http://a.ml/vocabularies/document-source-maps#tracked-element", [])
            tracked_element["http://a.ml/vocabularies/document-source-maps#value"] = $node["@id"]
            element := example
          }

          $result := (count(examples_from_this_payload) > 0)
   traits:
     message: common default
     targetClass: apiContract.EndPoint
     propertyConstraints:
        apiContract.ParametrizedTrait:
            core.name:
             pattern: defaultResponses

        camel-case-fields:
     message: Use camelCase.
     targetClass: apiContract.EndPoint
     if:
        propertyConstraints:
          shacl.name:
            in: ['path']
     then:
        propertyConstraints:
            shacl.name:
                pattern: "^[a-z]+([A-Z][a-z]+)*$"

0

There are 0 answers