Schema Validation
Last updated
Last updated
As of 3.0.0 Expected JSON response is now Schema Validation using AJV. Please read below how to change the plugin.
What's this about in laymen's terms: We rely on Bubble's own infrastructure and internal functions which turns your Supabase Data into Bubble objects ready to be used. We're doing so by mimicking what the API connector does for us and a bit more.
Some background: When you initialize an API call, Bubble sets up a lot of things in the background. It basically creates a schema of what kind of data it expects (and some other error handling on top of it, but we don't have to worry about that).
So when you initialize a call, Bubble will checks the response and tries to find the values to determine how he can parse the response later. By doing so it can also setup the related points to know when certain fields are empty how to parse them or more like how to essentially skip them.
Let's add the same functionality to the Plugin. All we need to do is head over to the API connector where we've initially setup the Data, and click on Manually enter API response.
If "Schema Validation" has a value, the plugin will first validate the data based on a provided template. Under the hood it uses Ajv JSON schema validator, one of the fastest and most used validation tool. The process is not any different than before 3.0.0. but now you have some more options.
All these three option should be set to true for best result. But make sure that if you add any other columns to the query, which doesn't have a corresponding value in the Schema Validation field while Remove Additional fields is active, it will be removed.
To make this feature as easy and painless to use we've created a little tool: https://json-to-ajv.relevatdigital.com/
This tool is essentially takes your raw Bubble response from the API connector and converts them to a format AJV expects.
Here's any example what you can expect:
{
"type": "object",
"properties": {
"created_at": { "type": "string" },
"created_by": { "type": "string" },
"space_id": { "type": "string" },
"name": { "type": "string" },
"visits": { "type": "integer" },
"welcome_text": { "type": "string", "default": "hi" },
"tags": { "type": "array", "items": { "type": "string" } },
"welcome_show": { "type": "boolean" },
"welcome_button_text": { "type": "string" },
"visible_users": { "type": "array", "items": { "type": "string" }, "default": "[]" },
"required": ["created_at", "created_by", "space_id", "unique_id", "name", "project", "company_id"],
"additionalProperties": false
}
This is an example how the AJV format is expected. If there's any error you'll see that in the console log.
This is optional but Hightly recommended so you have full contol over the response coming from the database, since user-generated content can break things.