"Object # has no method 'match'" error when including schema from remote server


#1

I have the following RAML:

#%RAML 0.8
title: Test
baseUri: http://localhost 
version: 1.0
protocols: [HTTPS]
/users:
  get:    
    description: Retrieve all the users or search for users based on the query parameters.
    responses:
      200:
        description: Request was successful 
        body: 
          application/json:
            schema: !include http://127.0.0.1/~sknippenberg/api/users.json
            example: !include http://127.0.0.1/~sknippenberg/api/users-example.json

It is giving me a “Object # has no method ‘match’” error on the first line. When I change the line that starts with schema with this, it works fine:

schema: !include users.json

I can copy/paste the URL in another tab and it returns the users.json file just fine. It is hosted by a local apache server. I can also change the schema line to this and it works as well:

        schema: |
          {
              "$schema": "http://json-schema.org/draft-04/schema",
              "title": "Users",
              "description": "A collection of users",
              "type": "object",    
              "properties": {
                  "users": {
                      "type": "array",
                      "items": {
                          "properties": {
                              "id": {
                                  "description": "The unique identifier for a user",
                                  "type": "string"
                              },
                              "userName": {
                                  "description": "The username of the user",
                                  "type": "string"
                              },
                              "firstName": {
                                  "description": "The first name of the user",
                                  "type": "string"
                              },
                              "lastName": {
                                  "description": "The last name of the user",
                                  "type": "string"
                              },
                              "href": {
                                  "description": "The URI to retrieve more information about the user",
                                  "type": "string"
                              }
                          },
                          "required": ["id", "href"]
                      }
                  }
              }
          } 

Is there something special I need to do to get the schema include to work when it’s referencing a remote server?

The example include works just fine.


#2

Hi! It took a little elbow grease but I found the culprit.

The bug is in the editor, not the parser, by default Angular parses all JSON responses to their js objects, while the parser is expecting a string containing the JSON schema.

I have a fix, I’m working on adding the unit tests for the fix, if you are blocked by this, you can use this branch https://github.com/mulesoft/api-designer/tree/bugs/JSON-remote-includes-parsing-errors


#3

Wow. That was quick. I checked out the branch and it’s working perfectly now. Thanks!


#4

Oh, it had actually been reported before, I just hadn’t got around to fix it for good.