Open sirex opened 2 months ago
Papildymas:
Jei modelis nėra referuojamas iš kitų modelių, jis yra šakninis. Toks modelis turi turėti jungtinius (nested) elementus (arba include
) jei jis turi savybių, kurios yra ref
arba backref
į kitus modelius.
Pavyzdys:
XSD schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Define the President element with name and surname attributes -->
<xs:element name="President">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="surname" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<!-- Define the Cities element with its own attributes -->
<xs:element name="Cities">
<xs:complexType>
<xs:attribute name="population" type="xs:integer" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<!-- Define the Country element with attributes and references to Cities and President -->
<xs:element name="Country">
<xs:complexType>
<xs:sequence>
<!-- Reference to Cities element -->
<xs:element ref="Cities" maxOccurs="unbounded" />
<!-- Reference to President element -->
<xs:element ref="President"/>
</xs:sequence>
<xs:attribute name="size" type="xs:string" use="required"/>
<xs:attribute name="population" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
DSA rezultatas:
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description
| example_nested | | | | | | | | |
| | resource1 | xml | | | | | | | |
| | | | | | | | | |
| | | | Cities | | | | | | | | |
| | | | | country | ref | Country | | | | | | |
| | | | | name | string required | | @name | | | | | |
| | | | | population | integer required | | @population | | | | | |
| | | | | | | | | |
| | | | Country | | | /Country | | | | | |
| | | | | cities[] | backref required | Cities | Cities | | | | | |
| | | | | cities[].name | string required | | @name | | | | | |
| | | | | cities[].population | integer required | | @population | | | | | |
| | | | | population | integer required | | @population | | | | | |
| | | | | president | ref required | President | President | | | | | |
| | | | | president.name | string required | | President/@name | | | | | |
| | | | | president.surname | string required | | President/@surname | | | | | |
| | | | | size | string required | | @size | | | | | |
| | | | | | | | | |
| | | | President | | | | | | | | |
| | | | | name | string required | | @name | | | | | |
| | | | | surname | string required | | @surname | | | | | |
Papildymas:
ref
kai maxOccurs="unbounded"
-> dsa: array backref
Pavyzdys, kaip trimis skirtingais XSD variantais gaunamas tas pats DSA:
ref
.<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Define the President element with name and surname attributes -->
<xs:element name="President">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="surname" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<!-- Define the Cities element with its own attributes -->
<xs:element name="Cities">
<xs:complexType>
<xs:attribute name="population" type="xs:integer" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<!-- Define the Country element with attributes and references to Cities and President -->
<xs:element name="Country">
<xs:complexType>
<xs:sequence>
<!-- Reference to Cities element -->
<xs:element ref="Cities" maxOccurs="unbounded" />
<!-- Reference to President element -->
<xs:element ref="President"/>
</xs:sequence>
<xs:attribute name="size" type="xs:string" use="required"/>
<xs:attribute name="population" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
type
:<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Define complexType for President -->
<xs:complexType name="PresidentType">
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="surname" type="xs:string" use="required"/>
</xs:complexType>
<!-- Define complexType for Cities -->
<xs:complexType name="CityType">
<xs:attribute name="population" type="xs:integer" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<!-- Define the Country element with elements using the defined complexTypes -->
<xs:element name="Country">
<xs:complexType>
<xs:sequence>
<!-- Cities element using CityType -->
<xs:element name="Cities" type="CityType" maxOccurs="unbounded" />
<!-- President element using PresidentType -->
<xs:element name="President" type="PresidentType"/>
</xs:sequence>
<xs:attribute name="size" type="xs:string" use="required"/>
<xs:attribute name="population" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Define the Country element -->
<xs:element name="Country">
<xs:complexType>
<xs:sequence>
<!-- Cities element defined as a complex type inside Country -->
<xs:element name="Cities" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="population" type="xs:integer" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<!-- President element defined as a complex type inside Country -->
<xs:element name="President">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="surname" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<!-- Country attributes -->
<xs:attribute name="size" type="xs:string" use="required"/>
<xs:attribute name="population" type="xs:integer" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Visais šiais atvejais DSA gaunamas toks:
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description
| example_nested3 | | | | | | | | |
| | resource1 | xml | | | | | | | |
| | | | | | | | | |
| | | | Cities | | | | | | | | |
| | | | | country | ref | Country | | | | | | |
| | | | | name | string required | | @name | | | | | |
| | | | | population | integer required | | @population | | | | | |
| | | | | | | | | |
| | | | Country | | | /Country | | | | | |
| | | | | cities[] | backref required | Cities | Cities | | | | | |
| | | | | cities[].name | string required | | @name | | | | | |
| | | | | cities[].population | integer required | | @population | | | | | |
| | | | | population | integer required | | @population | | | | | |
| | | | | president | ref required | President | President | | | | | |
| | | | | president.name | string required | | President/@name | | | | | |
| | | | | president.surname | string required | | President/@surname | | | | | |
| | | | | size | string required | | @size | | | | | |
| | | | | | | | | |
| | | | President | | | | | | | | |
| | | | | name | string required | | @name | | | | | |
| | | | | surname | string required | | @surname | | | | | |
Atributas gali turėti tokį:
use="required"
Tada DSA irgi required.
Elementas tokio neturi, tada jei yra minOccurs="1"
reiškia, kad required
Some examples are in the description of this task: https://github.com/atviriduomenys/spinta/issues/861
Examples here are about situations when a model from an element (and corresponding complexType
) shouldn't be created, but instead it's source should be added to a property of another model.
❓
jei mes turim tokį XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country">
<xs:complexType>
<xs:sequence>
<xs:element name="county" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="city" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
jis mums generuoja tokį DSA:
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description
| example4 | | | | | | | | |
| | resource1 | xml | | | | | | | |
| | | | | | | | | |
| | | | City | | | /country/county/city | | | | | |
| | | | | name | string required | | name/text() | | | | | |
| | | | | population | integer required | | population/text() | | | | | |
Ar čia gerai? Mes taip pametam informaciją, kad country gali turėti daug county ir dar county savo viduje gali turėti daug city
❓
extension
pavyzdys:
https://github.com/atviriduomenys/spinta/issues/872
ar gerai taip, kaip yra generuojama senojoje versijoje, ar reikėtų kurti atskirą modelį ir naudoti jį kaip base
?
❓
Kaip veiktų expand
šiuo atveju?
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description | example4 | | | | | | | | | | | resource1 | xml | | | | | | | | | | | | | | | | | | | | | | City | | | | | | | | | | | | | | country | ref | Country | | | | | | | | | | | | county | ref | County | | | | | | | | | | | | name | string required | | name/text() | | | | | | | | | | | population | integer required | | population/text() | | | | | | | | | | | | | | | | | | | | Country | | | /country | | | | | | | | | | | county[] | backref required | County | county | | | | | | | | | | | county[].city[] | backref required | City | city | | | | | | | | | | | county[].city[].name | string required | | name/text() | | | | | | | | | | | county[].city[].population | integer required | | population/text() | | | | | | | | | | | county[].name | string required | | name/text() | | | | | | | | | | | name | string required | | name/text() | | | | | | | | | | | | | | | | | | | | County | | | | | | | | | | | | | | city[] | backref required | City | city | | | | | | | | | | | country | ref | Country | | | | | | | | | | | | name | string required | | name/text() | | | | | |
❓
jei mes turim tokį XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="country"> <xs:complexType> <xs:sequence> <xs:element name="county" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="city" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="population" type="xs:int"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
jis mums generuoja tokį DSA:
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description | example4 | | | | | | | | | | | resource1 | xml | | | | | | | | | | | | | | | | | | | | | | City | | | /country/county/city | | | | | | | | | | | name | string required | | name/text() | | | | | | | | | | | population | integer required | | population/text() | | | | | |
Ar čia gerai? Mes taip pametam informaciją, kad country gali turėti daug county ir dar county savo viduje gali turėti daug city
Gerai, kadangi /country/county
neturi savo savybių ir yra naudojamas tik XML elementų katalogavimui, todėl nesvarbu ar /country/county
yra daugiareikšmis ar ne.
Tačiau, tai pasidarytų svarbu, jei /country/county
turėtu savo savybių, tada jam būtų reikalingas atskiras modelis.
choice
užduotis su pavyzdžiais: https://github.com/atviriduomenys/spinta/issues/869
ir sequence
pavyzdžiai su choice
viduje: https://github.com/atviriduomenys/spinta/issues/868
❓
Ar gerai čia sumapinta?
DATATYPES_MAPPING = {
"string": "string",
"boolean": "boolean",
"decimal": "number",
"float": "number",
"double": "number",
# duration has to be mapped to integer. In addition to this, we need a prepare function.
# This prepare function takes in given duration and turns it into integer (timedelta).
# More about time entities here:
# https://atviriduomenys.readthedocs.io/dsa/vienetai.html#laiko-vienetai
# TODO: add prepare function for duration
# https://github.com/atviriduomenys/spinta/issues/594
"duration": "string",
"dateTime": "datetime",
"time": "time",
"date": "date",
# format: target type, target column, value in the column
"gYearMonth": "date;enum;M",
"gYear": "date;enum;Y",
"gMonthDay": "string",
"gDay": "string",
"gMonth": "string",
"hexBinary": "string",
"base64Binary": "binary;prepare;base64",
"anyURI": "uri",
"QName": "string",
"NOTATION": "string",
"normalizedString": "string",
"token": "string",
"language": "string",
"NMTOKEN": "string",
"NMTOKENS": "string",
"Name": "string",
"NCName": "string",
"ID": "string",
"IDREF": "string",
"IDREFS": "string",
"ENTITY": "string",
"ENTITIES": "string",
"integer": "integer",
"nonPositiveInteger": "integer",
"negativeInteger": "integer",
"long": "integer",
"int": "integer",
"short": "integer",
"byte": "integer",
"nonNegativeInteger": "integer",
"unsignedLong": "integer",
"unsignedInt": "integer",
"unsignedShort": "integer",
"unsignedByte": "integer",
"positiveInteger": "integer",
"yearMonthDuration": "integer",
"dayTimeDuration": "integer",
"dateTimeStamp": "datetime",
"": "string",
}
simpleContent
pavyzdys:
https://github.com/atviriduomenys/spinta/issues/870
❓
union
- nelabai aktualus atvejis, nes tik 1 per visus RC dokumentus, bet vis tiek gal verta aprašyti? Bet ne iki galo aišku, kaip aprašyti. https://github.com/atviriduomenys/spinta/issues/875
There are some examples in subtasks of this issue: https://github.com/atviriduomenys/spinta/issues/842
❓
Kaip elgtis su nillable
?
Pavyzdys:
if nillable is true, property is not required. (actually, ask Mantas, if that's true, as this is possible:
Ar tai reiškia, kad ne required
, ar yra ir DSA atitikmuo?
Bet jei ne required
, tai kaip dėl minOccurs="1"
, kas reiškia, kad ji privaloma?
paprastas choice
pavyzdys:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Root element representing a country -->
<xs:element name="Country">
<xs:complexType>
<xs:sequence>
<!-- First element: Country name -->
<xs:element name="CountryName" type="xs:string"/>
<!-- Second element: Population of the country -->
<xs:element name="Population" type="xs:int"/>
<!-- Choice between two simple elements: CityName or StreetName -->
<xs:choice>
<!-- Simple element: City name -->
<xs:element name="CityName" type="xs:string"/>
<xs:element name="CityCode" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
DSA:
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description
| example14 | | | | | | | | |
| | resource1 | xml | | | | | | | |
| | | | | | | | | |
| | | | Country1 | | | /Country | | | | | |
| | | | | country_name | string required | | CountryName/text() | | | | | |
| | | | | population | integer required | | Population/text() | | | | | |
| | | | | | | | | |
| | | | Country2 | | | /Country | | | | | |
| | | | | city_name | string required | | CityName/text() | | | | | |
| | | | | country_name | string required | | CountryName/text() | | | | | |
| | | | | population | integer required | | Population/text() | | | | | |
| | | | | | | | | |
| | | | Country3 | | | /Country | | | | | |
| | | | | city_code | string required | | CityCode/text() | | | | | |
| | | | | country_name | string required | | CountryName/text() | | | | | |
| | | | | population | integer required | | Population/text() | | | | | |
❓
Tarkim, turim tokį XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- External type definition for Person -->
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<!-- External type definition for Governance -->
<xs:complexType name="GovernanceType">
<xs:sequence>
<xs:element name="Mayor" type="PersonType"/> <!-- Mayor as a type of Person -->
<xs:element name="Council" type="PersonType" maxOccurs="unbounded"/> <!-- Council as a type of Person, unbounded -->
</xs:sequence>
</xs:complexType>
<!-- External type definition for City -->
<xs:complexType name="CityType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="Governance" type="GovernanceType"/> <!-- Reference to GovernanceType -->
</xs:sequence>
</xs:complexType>
<!-- Definition of Country -->
<xs:complexType name="CountryType">
<xs:sequence>
<xs:element name="Capital" type="CityType"/> <!-- Capital as a type of City -->
<xs:element name="Cities" type="CityType" maxOccurs="unbounded"/> <!-- Cities as a type of City, unbounded -->
</xs:sequence>
</xs:complexType>
<!-- Root element of Country -->
<xs:element name="Country" type="CountryType"/>
</xs:schema>
Ar Governance
modelis turi būti kuriamas, ar neturi? Šiuo atveju jis yra kuriamas:
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description
| example15 | | | | | | | | |
| | resource1 | xml | | | | | | | |
| | | | | | | | | |
| | | | Capital | | | | | | | | |
| | | | | country | ref | Country | | | | | | |
| | | | | governance | ref required | Governance | Governance | | | | | |
| | | | | name | string required | | name/text() | | | | | |
| | | | | | | | | |
| | | | Council | | | | | | | | |
| | | | | country | ref | Country | | | | | | |
| | | | | first_name | string required | | FirstName/text() | | | | | |
| | | | | governance | ref | Governance | | | | | | |
| | | | | last_name | string required | | LastName/text() | | | | | |
| | | | | | | | | |
| | | | Country | | | /Country | | | | | |
| | | | | capital | ref required | Capital | Capital | | | | | |
| | | | | capital.governance | ref required | Governance | Capital/Governance | | | | | |
| | | | | capital.governance.council[] | backref required | Council | Capital/Governance/Council | | | | | |
| | | | | capital.governance.council[].first_name | string required | | FirstName/text() | | | | | |
| | | | | capital.governance.council[].last_name | string required | | LastName/text() | | | | | |
| | | | | capital.governance.mayor | ref required | Council | Capital/Governance/Mayor | | | | | |
| | | | | capital.governance.mayor.first_name | string required | | Capital/Governance/Council/FirstName/text() | | | | | |
| | | | | capital.governance.mayor.last_name | string required | | Capital/Governance/Council/LastName/text() | | | | | |
| | | | | capital.name | string required | | Capital/name/text() | | | | | |
| | | | | cities[] | backref required | Capital | Cities | | | | | |
| | | | | cities[].governance | ref required | Governance | Governance | | | | | |
| | | | | cities[].governance.council[] | backref required | Council | Governance/Council | | | | | |
| | | | | cities[].governance.council[].first_name | string required | | FirstName/text() | | | | | |
| | | | | cities[].governance.council[].last_name | string required | | LastName/text() | | | | | |
| | | | | cities[].governance.mayor | ref required | Council | Governance/Mayor | | | | | |
| | | | | cities[].governance.mayor.first_name | string required | | Governance/Council/FirstName/text() | | | | | |
| | | | | cities[].governance.mayor.last_name | string required | | Governance/Council/LastName/text() | | | | | |
| | | | | cities[].name | string required | | name/text() | | | | | |
| | | | | | | | | |
| | | | Governance | | | | | | | | |
| | | | | council[] | backref required | Council | Council | | | | | |
| | | | | mayor | ref required | Council | Mayor | | | | | |
Man atrodo, kad gerai, kad jis yra kuriamas, nes jei jis toks yra XSD, reiškia, kad jis neša tam tikrą informaciją, kaip atskira esybė, net jei neturi savo atskirų savybių.
Čia netinkamai generuojami pavadinimai, bet naujojoje versijoje tas turėtų susitvarkyti.
❓
id | d | r | b | m | property | type | ref | source | prepare | level | access | uri | title | description
| example15 | | | | | | | | |
| | resource1 | xml | | | | | | | |
| | | | | | | | | |
| | | | Capital | | | | | | | | |
| | | | | country | ref | Country | | | | | | |
| | | | | governance | ref required | Governance | Governance | | | | | |
| | | | | name | string required | | name/text() | | | | | |
| | | | | | | | | |
| | | | Council | | | | | | | | |
| | | | | country | ref | Country | | | | | | |
| | | | | first_name | string required | | FirstName/text() | | | | | |
| | | | | governance | ref | Governance | | | | | | |
| | | | | last_name | string required | | LastName/text() | | | | | |
| | | | | | | | | |
| | | | Country | | | /Country | | | | | |
| | | | | capital | ref required | Capital | Capital | | | | | |
| | | | | capital.governance | ref required | Governance | Capital/Governance | | | | | |
| | | | | capital.governance.council[] | backref required | Council | Capital/Governance/Council | | | | | |
| | | | | capital.governance.council[].first_name | string required | | FirstName/text() | | | | | |
| | | | | capital.governance.council[].last_name | string required | | LastName/text() | | | | | |
| | | | | capital.governance.mayor | ref required | Council | Capital/Governance/Mayor | | | | | |
| | | | | capital.governance.mayor.first_name | string required | | Capital/Governance/Council/FirstName/text() | | | | | |
| | | | | capital.governance.mayor.last_name | string required | | Capital/Governance/Council/LastName/text() | | | | | |
| | | | | capital.name | string required | | Capital/name/text() | | | | | |
| | | | | cities[] | backref required | Capital | Cities | | | | | |
| | | | | cities[].governance | ref required | Governance | Governance | | | | | |
| | | | | cities[].governance.council[] | backref required | Council | Governance/Council | | | | | |
| | | | | cities[].governance.council[].first_name | string required | | FirstName/text() | | | | | |
| | | | | cities[].governance.council[].last_name | string required | | LastName/text() | | | | | |
| | | | | cities[].governance.mayor | ref required | Council | Governance/Mayor | | | | | |
| | | | | cities[].governance.mayor.first_name | string required | | Governance/Council/FirstName/text() | | | | | |
| | | | | cities[].governance.mayor.last_name | string required | | Governance/Council/LastName/text() | | | | | |
| | | | | cities[].name | string required | | name/text() | | | | | |
| | | | | | | | | |
| | | | Governance | | | | | | | | |
| | | | | council[] | backref required | Council | Council | | | | | |
| | | | | mayor | ref required | Council | Mayor | | | | | |
Kaip tokiu atveju naudoti expand
anūkams?
Pateikti pavyzdžius, kaip kiekviena XSD konstrukcija turėtu būti konvertuojama į DSA analogą. Įtraukiant atskirą skyrių išorinėm schemom.
xs:element
-> dsa:modelxs:element
-> dsa:propertyxs:attribute
-> dsa:propertyxs:enumeration
-> dsa:enumxs:simpleType
inline -> dsa:property typexs:simpleType
ref -> dsa:property typexs:type
-> dsa:property type mappingxs:choice
maxOccurs=unbounded -> arraysxs:choice
maxOccurs=1 -> multiple modelsxs:choice
maxOccurs= -> optional propertiesxs:base
-> dsa:basexs:complexType
ref - model + include()xs:complexType
inline - modelxs:annotation
/xs:documentaton
- dsa:descriptionxs:sequence
xs:unique
xs:nillable
-> dsa:optionalxs:minOccurs=1
-> dsa:requiredResources
Pull request