Limenius / Liform

PHP library to render Symfony Forms to JSON Schema
MIT License
138 stars 75 forks source link

any specification about the form JSON schema? #36

Closed videni closed 4 years ago

videni commented 5 years ago

1. Why not return the default values with form schema together?

You use a dedicated normalizer InitialValuesNormalizer to extract default values from the FormView class. then, I guess the frontend web developer will fill these default values to the form later. it may be a lot easier if the default value is in the form schema. I can see that the ChoiceTransformer saves choices data into schema, is it proper to do the same with the default value like following JSON object?

{
   "title":null,
   "properties":{
      "name":{
         "type":"string",
         "title":"Name",
         "propertyOrder":1,
         "defaultValue": "john"
      }
   }
}

2. Where can I find the document about the JSON schema about the form?

There is a snipped code in ChoiceTransformer class, do you define these structure by specification or just make up by yourself? In my case, I need to write a AutocompleteType which has serval configurations, such as route, route parameters, autocomplete_alias, etc, these information is delivered to client side, I am wondering the proper place they should be.

 $schema = [
            'items' => [
                'type' => 'string',
                'enum' => $choices,
                'enum_titles' => $titles,
                'minItems' => $this->isRequired($form) ? 1 : 0,
            ],
            'uniqueItems' => true,
            'type' => 'array',
        ];
nacmartin commented 4 years ago

About 1: It would be possible to do that with a custom transformer as default value, but it is better to decouple the form spec with the actual data. For instance, in my own use of this bundle I can reload the values of the form, and I do that, without reloading the form. About 2: https://json-schema.org/ by the standard you can define optional fields, so some of the options we have are custom