atviriduomenys / spinta

Spinta is a framework to describe, extract and publish data (a DEP Framework).
MIT License
10 stars 4 forks source link

Generate nested properties when generating DSA from XSD #622

Open sirex opened 1 month ago

sirex commented 1 month ago

When generating DSA from XSD, generate nested structure for the first element in XML tree.

For example, if we have following XML file:

<STREETS>
    <STREET id="1" name="Gedimino g.">
        <CITY id="1" name="Vilnius">
            <COUNTRY id="1" name="Lithuania" />
        </CITY>
        <BUILDINGS>
            <BUILDING id="1" number="10" />
            <BUILDING id="1" number="11" />
            <BUILDING id="1" number="12" />
        </BUILDINGS>
    </STREET>
</STREETS>

Then generated DSA should look like this:

d | r | m | property             | type    | ref        | source
example                          |         |            |
  | resource1                    | xml     |            |
  |   | Country                  |         | id         | /STREETS/STREET/CITY/COUNTRY
  |   |   | id                   | integer |            | @id
  |   |   | name@lt              | string  |            | @name
  |   |   |                      |         |            |
  |   | City                     |         | id         | /STREETS/STREET/CITY
  |   |   | id                   | integer |            | @id
  |   |   | name@lt              | string  |            | @name
  |   |   | country              | ref     | Country    | COUNTRY/@id
  |   |   |                      |         |            |
  |   | Building                 |         | id         | /STREETS/STREET/BUILDINGS/BUILDING
  |   |   | id                   | integer |            | @id
  |   |   | number               | string  |            | @number
  |   |   | street               | ref     |            | ../../@id
  |   |   |                      |         |            |
  |   | Street                   |         | id         | /STREETS/STREET
  |   |   | id                   | integer |            | @id
  |   |   | name@lt              | string  |            | @name
  |   |   | city                 | ref     | City       | CITY/@id
  |   |   | city.id              | integer |            | CITY/@id
  |   |   | city.name@lt         | string  |            | CITY/@name
  |   |   | city.country         | ref     | Country    | CITY/COUNTRY/@id
  |   |   | city.country.id      | integer |            | CITY/COUNTRY/@id
  |   |   | city.country.name@lt | string  |            | CITY/COUNTRY/@name
  |   |   | buildings[]          | backref | Building   |
  |   |   | buildings[].id       | integer |            | BUILDINGS/BUILDING/@id
  |   |   | buildings[].name@lt  | string  |            | BUILDINGS/BUILDING/@name
  |   |   | buildings[].street   | ref     | Street     | @id

STREET is the first element in tree, so it has all the nested elements, like buildings[].name@lt. Other elements in the XML tree have separate models in DSA, just to be able to reference them from the main Street model.