Export: XML Schema
Converts the data contract to an XML Schema (XSD) with one global element per schema.
datacontract export xsd orders.odcs.yaml --output orders.xsd
Running this against the example orders contract produces (excerpt):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="orders">
<xs:annotation>
<xs:documentation>One row per customer order.</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="order_id" type="xs:string">
<xs:annotation>
<xs:documentation>Unique identifier of the order.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="order_timestamp" type="xs:dateTime">
<xs:annotation>
<xs:documentation>Timestamp when the order was placed.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="customer_id" type="xs:string">
<xs:annotation>
<xs:documentation>Reference to the customer who placed the order.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="order_total" type="xs:integer">
<xs:annotation>
<xs:documentation>Total amount of the order in cents.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="status" type="xs:string">
<xs:annotation>
<xs:documentation>Current fulfilment status of the order.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="line_items">
<xs:annotation>
<xs:documentation>One row per line item within an order.</xs:documentation>
</xs:annotation>
…
- Objects become nested complex types, arrays become elements that repeat (
minItems/maxItemssetminOccurs/maxOccurs), and a property that is notrequiredgetsminOccurs="0". - The
logicalTypesets the XSD type (timestamp→xs:dateTime,number→xs:decimal, …), unless thephysicalTypenames a built-in XSD type of the same logical type, such aspositiveIntegerortoken, or the ODCSformatgives a size:i8→xs:byte,i16→xs:short,i32→xs:int,i64→xs:long,u8tou64→xs:unsignedBytetoxs:unsignedLong,f32→xs:float,f64→xs:double. enum,pattern,minLength/maxLength,minimum/maximum(and their exclusive forms), and theprecision/scaleof decimals become facets. A bound that only repeats the range of the XSD type, such asminimum: 0on anunsignedInt, is left out. XSD patterns always match the whole value, contract patterns anywhere unless anchored:^ORD$exports asORD,ORDas.*(ORD).*.- A property with the custom property
xmlNode: attributebecomes an attribute, without the@prefix the import gives an attribute named like another property, and one withxmlNode: textthe text of an element with attributes. A schema'sxmlNamespacecustom property becomes the target namespace; a property'sxmlNamespace: ""makes the element unqualified (form="unqualified"). An element in yet another namespace would need a schema of its own, so it stays in the target namespace, with a warning.datacontract import xsdsets all three, so an imported XML Schema exports back to an equivalent one. - An object without properties accepts any content (
xs:anyType). Amapbecomes repeatedentryelements with akeyand avalue. - A
stringwithphysicalType: listexports as anxs:list, and one with a union of built-in XSD types inphysicalType(integer|date) as anxs:union, the way the import writes them. - XSD allows one lower and one upper bound per type, so when a property has both
minimumandexclusiveMinimum(or both maximums), the tighter one is exported. - Every schema becomes a global element of the same XML Schema, which has one target namespace: when schemas declare different
xmlNamespaces, the first one is used, with a warning.--schema-nameexports a single schema. - Names that are not valid XML names are changed to valid ones, with a warning.
XML Schema has nothing for primaryKey, unique, string formats, examples, and quality rules, so they are not exported. The digits of a decimal come from the precision and scale custom properties; a physicalType such as NUMERIC(12,2) is not read.
All options: datacontract export xsd.