stable order for property names in generated structs

This commit is contained in:
Joshua M. Clulow 2021-07-02 00:54:42 +00:00
parent c8027ac760
commit f1d477390c
1 changed files with 6 additions and 2 deletions

View File

@ -345,7 +345,11 @@ enum TypeDetails {
Basic,
Array(TypeId),
Optional(TypeId),
Object(HashMap<String, TypeId>),
/*
* Object property names are sorted lexicographically to ensure a stable
* order in the generated code.
*/
Object(BTreeMap<String, TypeId>),
}
#[derive(Debug)]
@ -603,7 +607,7 @@ impl TypeSpace {
(None, None) => bail!("types need a name? {:?}", s),
};
let mut omap = HashMap::new();
let mut omap = BTreeMap::new();
for (n, rb) in o.properties.iter() {
let itid = self.select_box(None, &rb)?;
if o.required.contains(n) {