diff --git a/src/caosadvancedtools/json_schema_exporter.py b/src/caosadvancedtools/json_schema_exporter.py index c36c9d0b1676b2486a44cad12fdcdcf03a24e806..c4c6de164aede0ce2e35b2f47fc30275552066b5 100644 --- a/src/caosadvancedtools/json_schema_exporter.py +++ b/src/caosadvancedtools/json_schema_exporter.py @@ -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 diff --git a/src/doc/conf.py b/src/doc/conf.py index db77cd7134d6eb1480da7f4b0674026c6255ed17..f4954a5921b7edaacf41497863892afb5715fca5 100644 --- a/src/doc/conf.py +++ b/src/doc/conf.py @@ -74,6 +74,7 @@ exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = None +default_role = "py:obj" # -- Options for HTML output ------------------------------------------------- diff --git a/src/doc/index.rst b/src/doc/index.rst index aa5cedca8b8528c94abe183378f44369dea495fb..7fa017ec4202f25fe9f94a154ed8762c4581eebc 100644 --- a/src/doc/index.rst +++ b/src/doc/index.rst @@ -16,6 +16,7 @@ This documentation helps you to :doc:`get started<README_SETUP>`, explains the m The Caosdb Crawler <crawler> YAML data model specification <yaml_interface> Specifying a datamodel with JSON schema <json_schema_interface> + Convert a data model into a json schema <json_schema_exporter> Conversion between XLSX, JSON and LinkAhead Entities <table-json-conversion/specs> _apidoc/modules Related Projects <related_projects/index> diff --git a/src/doc/json_schema_exporter.rst b/src/doc/json_schema_exporter.rst new file mode 100644 index 0000000000000000000000000000000000000000..da4fa9d273f7cb9295974e9632e8eb1730bd47a3 --- /dev/null +++ b/src/doc/json_schema_exporter.rst @@ -0,0 +1,8 @@ +JSON schema from data model +=========================== + +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/>`_. + +For this use case, look at the documentation of the `caosadvancedtools.json_schema_exporter` module.