Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema.switch support in version 0.7.0-rc.3 #299

Closed
kapouer opened this issue Feb 8, 2017 · 7 comments
Closed

schema.switch support in version 0.7.0-rc.3 #299

kapouer opened this issue Feb 8, 2017 · 7 comments

Comments

@kapouer
Copy link
Contributor

kapouer commented Feb 8, 2017

Here's the schema i'm using:

{
 "type": "object",
 "required": [
  "type"
 ],
 "properties": {
  "id": {
   "type": "integer"
  },
  "type": {
   "type": "string"
  }
 },
 "switch": [
  {
   "if": {
    "properties": {
     "type": {
      "constant": "site"
     }
    }
   },
   "then": {
    "properties": {
     "data": {
      "type": "object",
      "default": {},
      "properties": {
       "name": {
        "type": "string"
       }
      },
      "required": [
       "name"
      ]
     }
    }
   }
  },
  {
   "if": {
    "properties": {
     "type": {
      "constant": "page"
     }
    }
   },
   "then": {
    "properties": {
     "data": {
      "type": "object",
      "default": {},
      "properties": {
       "title": {
        "type": [
         "string",
         "null"
        ]
       },
       "template": {
        "type": "string"
       }
      },
      "required": [
       "template"
      ]
     }
    }
   }
  }
 ]
}

It validates all right with ajv and that kind of data:

{
 "type": "page",
 "data": {
  "title": "Home",
  "template": "templates/home.html"
 }
}

$afterValidate receives that json all right.
However, when inserting it using insertGraph method, it strips the data property.

I have to modify the schema and declare "properties.data" to keep objection from pruning that column.
I suppose the problem comes from the "switch" clause, while objection only checks what's in the schema "properties".
Isn't there any way to abstract that second-guessing from objection and let all knowledge about schema be given by ajv ?

@koskimas
Copy link
Collaborator

koskimas commented Feb 8, 2017

Yes

@kapouer
Copy link
Contributor Author

kapouer commented Feb 8, 2017

Ha, that explains a lot of confusion i had. IMO pickJsonSchemaProperties should be false by default, but i won't complain.

@kapouer kapouer closed this as completed Feb 8, 2017
@koskimas
Copy link
Collaborator

koskimas commented Feb 8, 2017

I agree. The feature is just a historical remnant. I'll probably set the default to false or remove the feature alltogether at some point.

@kapouer
Copy link
Contributor Author

kapouer commented Feb 8, 2017

Well, actually, before changing anything, i think something's wrong with ajv or with json-schema spec about additionalProperties and switch keywords.

@koskimas
Copy link
Collaborator

koskimas commented Feb 9, 2017

Did you reopen this by accident? Or is there something you wish to be changed in objection?

@kapouer
Copy link
Contributor Author

kapouer commented Feb 9, 2017

I'll probably set the default to false or remove the feature alltogether at some point.

so i thought this issue should stay open until that point ? Or not !

@koskimas
Copy link
Collaborator

We should open a separate issue for that. This isn't very descriptive.

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

No branches or pull requests

2 participants