brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
607 stars 168 forks source link

label form if objects are in array #55

Closed estradamarkie closed 7 years ago

estradamarkie commented 7 years ago

Hi,

Is there a way to show labels if the object is an array? Also doesn't render this array as well, this array is coming from a GET request.

{
[
   {
      "name":"id",
      "in":"query",
      "required":false,
      "type":"array",
      "items":{
         "type":"integer",
         "format":"int32"
      },
      "collectionFormat":"multi"
   },
   {
      "name":"sku",
      "in":"query",
      "required":false,
      "type":"array",
      "items":{
         "type":"string"
      },
      "collectionFormat":"multi"
   },
   {
      "name":"code",
      "in":"query",
      "required":false,
      "type":"array",
      "items":{
         "type":"string"
      },
      "collectionFormat":"multi"
   }
]
}
idelvall commented 7 years ago

This is not a valid JSON Schema try something like this

{
  "$schema": "http://json-schema.org/draft-03/schema#",
  "type": "object",
  "properties": {
     "id": {
      "name":"id",
      "in":"query",
      "required":false,
      "type":"array",
      "items":{
         "type":"integer",
         "format":"int32"
      },
      "collectionFormat":"multi"
   },
   "sku":{
      "name":"sku",
      "in":"query",
      "required":false,
      "type":"array",
      "items":{
         "type":"string"
      },
      "collectionFormat":"multi"
   },
   "code":{
      "name":"code",
      "in":"query",
      "required":false,
      "type":"array",
      "items":{
         "type":"string"
      },
      "collectionFormat":"multi"
   }
  }
}
estradamarkie commented 7 years ago

@idelvall unfortunately I can't change how the JSON is being output therefore in this case its returning an array obj. Is there a way to render a form if the objects are in array[]?

idelvall commented 7 years ago

You can easily construct a valid schema from the object you already have and then pass this new instance to the form

estradamarkie commented 7 years ago

@idelvall yeah thanks, managed to make it work with title property as well as a label.