datacontract / datacontract-specification

The Data Contract Specification Repository
https://datacontract.com/
MIT License
276 stars 41 forks source link

Fields are unordered #101

Open alanvgreen opened 2 weeks ago

alanvgreen commented 2 weeks ago

I'm writing a web app that shows details from data contracts, and noticed that the fields are displayed in a different order to how they are in the Data Contract. This is a little confusing to users who are trying to understand a data model and find that - for example - the volume and price of an order are separated by eight unrelated columns. There may also be cases, such as CSV files, where the ordering of fields is an important part of the contract between data provider and data user.

In the Data Contract Specification, fields are represented as a YAML Mapping, mapping field names to data about that field. The YAML 1.2 spec, at section 3.2.1.1 explicitly notes that mapping key/value pairs are unordered:

The content of a mapping node is an unordered set of key/value node pairs, with the restriction that each of the keys is unique.

Many tools (e.g modern PyYAML) preserve the order of keys as read from the file, but some others do not.

It would be helpful if a future version of the Data Contract specification had some way to explicitly order fields. A YAML list is a possible solution, but many others exist.