RAML file is throwing invalid Json schema response in Anypoint Studio

1.2k views Asked by At

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

There are 2 answers

4
Brad Cooper On BEST ANSWER

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
Brad Cooper On

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"
        }
    }
}