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

Feature Request: JSON Schema to Field Type JSON #1154

Open
pranjaldugar opened this issue Dec 1, 2022 · 5 comments
Open

Feature Request: JSON Schema to Field Type JSON #1154

pranjaldugar opened this issue Dec 1, 2022 · 5 comments

Comments

@pranjaldugar
Copy link

Hi, Thanks for such a wonderful software.
It would be nice to have ability to either
a) add link to JSON schema URL
or
b) paste the schema directly in database
or
c) upload json schema file
while adding/editing collection

we can then use schema to
primarily: send schema with api requests
optionally: validate json entry with schema in PB itself.

Thanks!

@ganigeorgiev
Copy link
Member

This is not planned because it duplicates to some extend the existing collections functionality.

If you need schema and data validations, my recommendation would be to use a relation field to another collection.

@Lex-2008
Copy link

@ganigeorgiev : Please forgive me if I'm wrong, but I'm not sure you're talking about the same thing. I believe you're talking about database schema, but @pranjaldugar is talking about JSON schema, I think. I'm not sure about "sending schema with api requests", but I really like the second part - to validate json entries. As I understand it, JSON schema can be used to verify that JSON like this:

{
    "a": 1,
    "b": [
        true,
        false
    ]
}

conforms to schema like this (also expressed as JSON):

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "properties": {
    "a": {
      "type": "integer"
    },
    "b": {
      "type": "array",
      "items": {
        "type": "boolean"
      }
    }
  }
}

It would be useful to specify what kind of JSON users can set here, without extra coding.

While yes, it is indeed possible to split this into separate collections, and add relations between them - but it sounds like an overkill if you're not planning to use other database features.

It is also might be possible to implement while using pocketbase as framework, or with an external application (for those who are not very familiar with Go), but I think it would be nice to have this in "core" pocketbase.

Thanks for consideration and sorry for the noise if I didn't convince you that it's a good feature to add! :)

@ganigeorgiev
Copy link
Member

ganigeorgiev commented Mar 28, 2023

@Lex-2008 I understood what the author of the requested suggested. We can add a JSON schema validator as a json field option but I think it will add unnecessary complication.

I'll reopen the issue since this was requested several times before, but for now I'll consider it a low priority.

If someone wants to work on it, feel free to pick it and I'll review it. The suggested implementation is to store the JSON schema as another optional string field in schema.JsonOptions and to perform the validations in the validators.checkJsonValue check (I haven't investigated in details how complex the JSON schema validations could be but it might make sense to use an external helper library).

@ganigeorgiev ganigeorgiev reopened this Mar 28, 2023
@Lex-2008
Copy link

thanks!

@stamler
Copy link

stamler commented Apr 7, 2024

A somewhat related concept would be to automatically generate a JSONSchema file for each collection similar to the types file. It could be used for client side validation and could incorporate things like regex, min and max already stored in the database. I feel like this would be fairly straightforward to implement.

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

Successfully merging a pull request may close this issue.

4 participants