0
votes

I am using Anypoint Studio 6.2 with Mule 3.8.1 and I have added a raml and JSON schema which shows no errors in api-workbench but show Json schema invalid errors in Anypoint Studio.

I have found that if I remove the required field from all of my Json schemas linked to the raml (i.e. raml, traits and types) then everything works. Is there a way to fix this?

The required syntax I am using is:

"required": [
    "Organisation",
    "Address"
  ],

Updated

and I am also seeing a org.mule.common.metadata.parser.json.SchemaException: java.net.MalformedURLException: no protocol: where the $ref cannot be resolved when using the JSON schema to create a metadata type to use in Dataweave:

{
    "id": "http://localhost:8000/schemas/products.json#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Products",
    "type": "object",
    "properties": {
        "Products": {
            "$ref": "common/text.json"
        }
    },
    "additionalProperties": false
}

Thanks

2
Maybe it only supports v3 schema. Try using put "required": "true" in each field (which is v3 schema format)Pedro

2 Answers

1
votes

I do the same, so it is definitely supported in Studio. Without seeing your entire JSON schema file I have to guess at the cause, and my assumption is that you either don't specify a JSON schema version or you are specifying the wrong one (should be at least v4, not v3 for this to work). The following works for me:

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "type": "object",
  "properties": {
    "Organisation": { "type": "string" },
    "Address": { "type": "string" }
  },
  "required": [ "Organisation", "Address" ]
}
0
votes

With regards to the new addition - $ref - we also use this, and it seems to be resolved correctly by APIKit (i.e. messages are correctly validated) however I don't use these schemas to create Dataweave metadata so I cannot guarantee that it will behave the same (I would hope it uses the same parser, but cannot say for sure).

Common.json:

{
    "$schema": "http://json-schema.org/draft-04/schema",
    "definitions": {
        "emailAddress": {
            "description": "Basic RegEx for an email address",
            "type": ["string","null"],
            "pattern": "^[a-zA-Z0-9'._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
        }
    }   
}

Sample.json:

{
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "object",
    "properties": {
        "email": {
            "$ref": "common.json#/definitions/emailAddress"
        }
    }
}