Generate xdf messages
Related to #726
Notable Changes
New endpoints
-
/v1/schemas/<fim_id>/<fim_version>/xdf
to export a fresh xdf representation of a schema -
/v1/document-profiles/<fim_id>/<fim-version>/xdf
- copied from `/v0/document-profiles/<fim_id>/<fim_version>/xdf - Deprecated
/v0/document-profiles/<fim-id>/<fim_version>/xdf
- We only added this to v0, since we were initially unsure whether or not we will also use immutable downloads. Since this is not the case, the route can be moved tov1
tests
- I wrote new tests in
test_api_get_schema_xml.py
to test the new export route. Other than that, I mostly just updated existing tests to use the new xdf2 factories.
xdf2
Messages
Up to now, we only supported generating the SchemaMessage
, both xdf2 and xdf3 however also define messages for all other resources. I added the logic to generate DatenfeldMessage
and DatenfeldgruppeMessage
, so that we can easily support those exports directly via the API. I used this opportunity to also re-arrange the code in xdatenfelder/xdf2/
a little. There is now one top-level file per message, i.e. schema_message.py
, steckbrief_message.py
, datenfeld_message.py
and datenfeldgruppe_message.py
. Both the code for parsing and serializing a message is now in this file. Since most of the content ist shared between the messages, I moved more classes into common.py
.
xdf2
Factories
I re-structured the xdf2 factories to avoid the annoying problem to explicitly register
deeply nested elements on the top-level schema. Instead, I created a top-level factory, which internally saves references to all created elements, and can resolve all references automatically when actually building the message:
factory = Xdf2Factory()
rule = factory.rule().build()
field = factory.field().with_rule(rule).build()
group = factory.group().with_field(field).build()
# Building the schema message now automatically resolves all references
# to groups, fields and rules, no need to register them manually anymore.
schema_message = factory.schema().with_group(group).message()