Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

json-schema integration not up to the spec #76

Open
rdohms opened this issue May 15, 2015 · 3 comments
Open

json-schema integration not up to the spec #76

rdohms opened this issue May 15, 2015 · 3 comments

Comments

@rdohms
Copy link

rdohms commented May 15, 2015

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
Copy link
Author

rdohms commented May 20, 2015

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.

@rickmacgillis
Copy link
Contributor

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.

@alecsammon
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants