raml-php-parser icon indicating copy to clipboard operation
raml-php-parser copied to clipboard

json-schema integration not up to the spec

Open rdohms opened this issue 9 years ago • 3 comments

Scenario:

#%RAML 0.8
title: Sample for Schema Support
version: 1
baseUri: http://some.example.com
protocols: [ HTTPS, HTTP ]
mediaType: application/hal+json
schemas:
  - account: |
      {
        "type": "object",
        "$schema": "http://json-schema.org/draft-03/schema",
        "id": "http://jsonschema.net",
        "required": true,

        "properties": {
          "id": {
            "type": "string",
            "required": false
          },
          "emails": {
              "type": "array",
              "items": { "$ref": "email" }
          }
        }
      }
  - email: |
      {
        "type": "object",
        "$schema": "http://json-schema.org/draft-03/schema",
        "id": "http://jsonschema.net",
        "required": true,
        "properties": {
          "id": {
            "type": "string",
            "required": false
          },
          "address": {
            "type": "string",
            "required": true
          },
          "primary": {
            "type": "boolean",
            "required": true
          },
          "confirmed": {
            "type": "boolean",
            "required": true
          }
        }
      }

/accounts:
  displayName: Accounts
  description: Handles all account operations
  get:
    description: Find and list accounts
    responses:
      200:
        body:
          application/json:
            schema: account

Using the above example i should get a valid result to navigate (raml successfully parsed), and (as a bonus) my json-schema would load the email entity inside the account emails property.

However it tries to load email as if its a remote json-schema file


Fatal error: Uncaught exception 'JsonSchema\Exception\ResourceNotFoundException' with message 'JSON schema not found at file://./email' in vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php on line 38

JsonSchema\Exception\ResourceNotFoundException: JSON schema not found at file://./email in vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php on line 38

I believe this is an issue in how processing is handed over to json-schema but i'm not entirely sure where the blame lies.

I tried other RAML parsers:

  • js: raml was parsed. json-schema $ref was ignored
{ body: { 'application/json': { schema: '{
  "type": "object",
  "$schema": "http://json-schema.org/draft-03/schema",
  "id": "http://jsonschema.net",
  "required": true,

  "properties": {
    "id": {
      "type": "string",
      "required": false
    },
    "emails": {
        "type": "array",
        "items": { "$ref": "email" }
    }
  }
}
' } } }
  • python-raml: raml was parsed, schema not expanded
{'body': OrderedDict([('application/json', {'notNull': None, 'formParameters': None, 'example': None, 'schema': 'account'})]), 'headers': None, 'description': None, 'notNull': None}

in the schemas property $ref was also not expanded.

Is there an option to avoid the complete crash and just keep going with the superficial data from schema?

rdohms avatar May 15 '15 13:05 rdohms

So i dug a little more.

Seems no parser does the full job and this library has a second parameter that avoids parsing the schemas.

Still it would be cool to be the only parser to do this, so it may be a nice new feature.

rdohms avatar May 20 '15 13:05 rdohms

If there's enough demand then we'll implement it, and if you'd like that feature immediately, you can always make a pull request. There's a couple pull requests from my repo waiting incorporation, so to keep things stable, I'd suggest waiting until those are merged.

rickmacgillis avatar May 24 '15 13:05 rickmacgillis

Hi Rafael,

I agree it's a problem, however I'm not currently sure how to fix it.

Either the order in which the schema's were listed would have to become important - which feels like a dodgy thing to do with an unordered array! Or you would have to parse them twice - which feels like it could get pretty complicated.

Not sure what to suggest - but open to ideas

alecsammon avatar May 26 '15 14:05 alecsammon