Skip to content
Snippets Groups Projects

ENH: JsonSchemaExporter accepts do_not_create parameter.

Merged Daniel Hornung requested to merge f-more-jsonschema-export into dev

Summary

  • DataModel.get_deep(name: str)
  • Refactoring of json schema exporter.
  • New parameter for json schema exporter.

Look at the new test function, this should explain the meaning.

Please do not delete the source branch after merging, we will probably still need it.

Focus

Does the get_deep() function look reasonable?

Test Environment

Run the unit tests, especially pytest unittests/test_json_schema_exporter.py -k options

Check List for the Author

Please, prepare your MR for a review. Be sure to write a summary and a focus and create gitlab comments for the reviewer. They should guide the reviewer through the changes, explain your changes and also point out open questions. For further good practices have a look at our review guidelines

  • All automated tests pass
  • Reference related issues caosdb/customers/dimr/management#65
  • Up-to-date CHANGELOG.md (or not necessary)
  • Up-to-date JSON schema (or not necessary)
  • Appropriate user and developer documentation (or not necessary)
    • How do I use the software? Assume "stupid" users.
    • How do I develop or debug the software? Assume novice developers.
  • Annotations in code (Gitlab comments)
    • Intent of new code
    • Problems with old code
    • Why this implementation?

Check List for the Reviewer

  • I understand the intent of this MR
  • All automated tests pass
  • Up-to-date CHANGELOG.md (or not necessary)
  • Appropriate user and developer documentation (or not necessary)
  • The test environment setup works and the intended behavior is reproducible in the test environment
  • In-code documentation and comments are up-to-date.
  • Check: Are there specifications? Are they satisfied?

For further good practices have a look at our review guidelines.

Edited by Florian Spreckelsen

Merge request reports

Pipeline #43065 passed

Pipeline passed for 0af91939 on f-more-jsonschema-export

Approval is optional

Merged by Florian SpreckelsenFlorian Spreckelsen 1 year ago (Nov 1, 2023 1:43pm UTC)

Merge details

  • Changes merged into dev with f5cd9aa6.
  • Did not delete the source branch.

Pipeline #43214 passed

Pipeline passed for f5cd9aa6 on dev

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 49 Whether to include name and description in the `properties` section of
    50 the schema to be exported. Optional, default is False.
    51 additional_options_for_text_props : dict, optional
    52 Dictionary containing additional "pattern" or "format" options for
    53 string-typed properties. Optional, default is empty.
    54 units_in_description : bool, optional
    55 Whether to add the unit of a LinkAhead property (if it has any) to the
    56 description of the corresponding schema entry. If set to false, an
    57 additional `unit` key is added to the schema itself which is purely
    58 annotational and ignored, e.g., in validation. Default is True.
    59 do_not_create : list[str]
    60 A list of RedcordType names, for which there should be no option
    61 to create them. Instead, only the choice of existing elements should
    62 be given.
    63 """
    64 if not additional_options_for_text_props:
  • 78 return [prop.name for prop in rt.properties
    79 if rt.get_importance(prop.name) == db.OBLIGATORY]
    80
    81 def _make_segment_from_prop(self, prop: db.Property):
    82 """Return the JSON Schema segment for the given property
    83
    84 Parameters
    85 ----------
    86 prop : db.Property
    87 The property to be transformed.
    88 """
    89
    90 if prop.datatype == db.TEXT or prop.datatype == db.DATETIME:
    91 text_format = None
    92 text_pattern = None
    93 if prop.name in self._additional_options_for_text_props:
  • 127 list_element_prop = db.Property(
    128 name=prop.name, datatype=get_list_datatype(prop.datatype, strict=True))
    129 json_prop["items"] = self._make_segment_from_prop(list_element_prop)
    130 elif prop.is_reference():
    131 if prop.datatype == db.REFERENCE:
    132 # No Record creation since no RT is specified and we don't know what
    133 # schema to use, so only enum of all Records and all Files.
    134 values = self._retrieve_enum_values("RECORD") + self._retrieve_enum_values("FILE")
    135 json_prop["enum"] = values
    136 elif prop.datatype == db.FILE:
    137 # TODO: different issue
    138 raise NotImplementedError("Files have not been implemented yet.")
    139 else:
    140 prop_name = prop.datatype
    141 if isinstance(prop.datatype, db.Entity):
    142 prop_name = prop.datatype.name
  • 223 "The description of the Record to be created")
    224
    225 for prop in rt.properties:
    226 if prop.name in props:
    227 # Multi property
    228 raise NotImplementedError(
    229 "Creating a schema for multi-properties is not specified. "
    230 f"Property {prop.name} occurs more than once."
    231 )
    232 props[prop.name] = self._make_segment_from_prop(prop)
    233
    234 schema["properties"] = props
    235
    236 return schema
    237
    238 def recordtype_to_json_schema(self, rt: db.RecordType):
  • 248 -------
    249 schema : dict
    250 A dict containing the json schema created from the given RecordType's properties.
    251 """
    252
    253 schema = self._make_segment_from_recordtype(rt)
    254 schema["$schema"] = "https://json-schema.org/draft/2019-09/schema"
    255 if rt.name:
    256 schema["title"] = rt.name
    257 if rt.description:
    258 schema["description"] = rt.description
    259
    260 return schema
    211 261
    212 262
    213 263 def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = True,
  • Daniel Hornung
  • Daniel Hornung
  • Daniel Hornung
  • Daniel Hornung marked the checklist item Annotations in code (Gitlab comments) as completed

    marked the checklist item Annotations in code (Gitlab comments) as completed

  • Daniel Hornung marked the checklist item Reference related issues as completed

    marked the checklist item Reference related issues as completed

  • Daniel Hornung changed the description

    changed the description

  • Daniel Hornung added 1 commit

    added 1 commit

    • d97c5426 - FIX: Fixed get_deep a bit, added more tests.

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading