gitana / alpaca

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking, dynamic user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.
http://www.alpacajs.org
Other
1.3k stars 368 forks source link

Support "oneOf" validation & form generation #82

Open paul-mcculloch opened 11 years ago

paul-mcculloch commented 11 years ago

The use case I am working with is capturing database details for different database types which have different fields that can be captured.

Alpaca doesn't know how to deal with this scenario, as far as I can see. An ideal (for my use case!) solution would be to offer a select list showing the title of each of the 'oneOf' schemas.

I guess a different (harder?) challenge is to recognise which of the available schemas is matched when loading existing data.

uzquiano commented 11 years ago

Could you provide an example of what you have in mind? Curious to see your sample data and a proposed schema.

On Nov 11, 2013, at 12:15 PM, Paul McCulloch notifications@github.com wrote:

The use case I am working with is capturing database details for different database types which have different fields that can be captured.

Alpaca doesn't know how to deal with this scenario, as far as I can see. An ideal (for my use case!) solution would be to offer a select list showing the title of each of the 'oneOf' schemas.

I guess a different (harder?) challenge is to recognise which of the available schemas is matched when loading existing data.

— Reply to this email directly or view it on GitHub.

paul-mcculloch commented 11 years ago

See below. Oracle & SQLServer require different connection values to be captured. I'd like a UI which prompted for SQLServer or Oracle and rendered appropriate fields for that database type.

var schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "database": {
            "description": "The database that the action processor connects to",
            "type": "object",
            "oneOf":[
                {"$ref": "#/definitions/sql-database"},
                {"$ref": "#/definitions/oracle-database"}
            ]

        }
    },

    "definitions":{
        "sql-database":{
            "title": "SQL Database  Server",
            "type": "object",
             "properties": {
                "type": {
                            "enum": [ "SQLServer"],
                            "description": "RDBMS Type"
                        },
                "server": {"type": "string", "minLength": 1, "description": "Database server hostname"},
                "instance": {"type": "string", "description": "Instance (SQL Server Only)"},
                "name": {"type": "string", "description": "Name (SQL Server Only)"},
                "user": {"type": "string", "minLength": 1, "description": "SQL User"},
                "password": {"type": "string", "minLength": 1, "format": "password", "description": "SQL Password"}
             }
        },

        "oracle-database":{
            "title": "Oracle Database  Server",
            "type": "object",
             "properties": {
                "type": { "enum": [ "Oracle" ] },
                "server": {"type": "string", "minLength": 1, "description": "TNS Instance Name"},
                "user": {"type": "string", "minLength": 1, "description": "SQL User"},
                "password": {"type": "string", "minLength": 1, "format": "password", "description": "SQL Password"}
             }
        }  
    }
}

var sqlDb = {   
    "database": {
        "type": "SQLServer",
        "server": "vm-tst-sql-08r2",
        "instance": "",
        "name": "trunk",
        "user": "sa",
        "password": "8791279879afgafg2323",
    }
}

var oraDb = {   
    "database": {
        "type": "Oracle",
        "server": "TRUNK.LOCAL",
        "user": "paul",
        "password": "password",
    }
}
uzquiano commented 11 years ago

This looks very useful and we'd want to do it along with full support for the latest JSON schema spec.

Thanks for the example. Going to take a closer look at JSON schema v4 differences

rmknightstar commented 10 years ago

I agree that this would be useful

picsoung commented 10 years ago

Hi, I am curious to know if there was any progress made on json-schema v4.

I also want to implement something with "oneOf" relation.

Thanks

shikshik commented 9 years ago

+1

This is the only reason I don't use Alpaca. It must support json-schema v4 features and "oneOf", "anyOf", "noneOf" are very useful in many use cases.

mcmartins commented 9 years ago

+1

This is the reason why I'm quitting Alpaca.

pamfilos commented 8 years ago

+ 1

Any news for the "oneOf", "anyOf", "noneOf" features?

techbrew-mc commented 8 years ago

+1

wendelin commented 8 years ago

+1 I'd like to have an Alpaca query builder like "http://querybuilder.js.org/demo.html" but without support for mixed types this does not seem feasible.

SemiHum commented 8 years ago

+1

AleSanCro commented 8 years ago

+1

hairylime commented 7 years ago

+1000

LegoStormtroopr commented 7 years ago

Nearly 4 years, and no resolution?

LegoStormtroopr commented 7 years ago

After a little googling, it seems that JSON-Editor is a schema based editor that has oneOf - https://github.com/jdorn/json-editor

mcartmel commented 7 years ago

+1 Can't use Alpaca without this feature

dcode-balosh commented 6 years ago

+1 I wanted to use alpaca for binary tree where each node is a form. This is a rather general use case where you need users to create logic tree. Without "oneOf" we need to render each node as individual form, then merge together all nodes, then run schema validation. jdorn/json-editor Do have this feature but is maintained.

FatPanther commented 6 years ago

+1

malikmalhan commented 6 years ago

+1

tolgaparlan commented 5 years ago

+1

khadgarmage commented 4 years ago

Any news for the "oneOf", "anyOf", "noneOf" features?