Skip to content
Snippets Groups Projects

Documentation for json schema exporter

Merged Daniel Hornung requested to merge f-doc-jsex into dev
5 files
+ 45
3
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -19,9 +19,39 @@
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Module for converting a data model into a json schema compatible dictionary.
"""Convert a data model into a json schema.
Sometimes you may want to have a `json schema <https://json-schema.org>`_ which describes a
LinkAhead data model, for example for the automatic generation of user interfaces with third-party
tools like `rjsf <https://rjsf-team.github.io/react-jsonschema-form/docs/>`_. Then this is the
right module for you!
The :mod:`json_schema_exporter <caosadvancedtools.json_schema_exporter>` module has one main class,
:class:`JsonSchemaExporter`, and a few utility and wrapper functions.
For easy usage, you may simply import `recordtype_to_json_schema` and use it on a fully referenced
RecordType like this::
import caosadvancedtools.models.parser as parser
import caosadvancedtools.json_schema_exporter as jsex
model = parser.parse_model_from_yaml("my_model.yml")
# get the data model schema for the "Journey" recordtype
schema, ui_schema = recordtype_to_json_schema(
rt=model.get_deep("Journey"),
do_not_create=["Continent"], # only choose from existing Records
multiple_choice=["visited_cities"],
rjsf=True # also create a UI schema
)
For more details on how to use this wrapper, read the `function documentation
<recordtype_to_json_schema>`.
Other useful functions are `make_array`, which creates an array out of a single schema, and
`merge_schemas`, which as the name suggests allows to combine multiple schema definitions into a
single schema.
The scope of this json schema is the automatic generation of user interfaces.
"""
from collections import OrderedDict
Loading