Skip to content

Order of entries in schema translated to the cedar format is not deterministic #1210

@john-h-kastner-aws

Description

@john-h-kastner-aws

Bug Category

Schemas and Validation

Describe the bug

The translate-schema CLI command emits the entries in a JSON schema in a nondeterministic order when converting the schema to the cedar schema format. This is most likely happening because we print entries by iterating over a hashmap/hashset.

Given this schema

{
  "": {
    "entityTypes": {
      "User": {},
      "Group": {}
    },
    "actions": {}
  }
}

We sometimes see User first but other times see Group first.

jkastner@88665a03aa97 cedar % cargo run -q translate-schema --direction json-to-cedar -s test.cedarschema.json
entity User;
entity Group;

jkastner@88665a03aa97 cedar % cargo run -q translate-schema --direction json-to-cedar -s test.cedarschema.json
entity Group;
entity User;

We should probably sort the entries (i.e., store in a btreemap) and print in that order. More ambitiously, we could try to maintain the order from the JSON, but serde might not make this easy.

This issue applies also to the order of namespaces and actions, not just the order of entity types. I haven't checked, but it might also apply to the order of entries when converting in the other direction.

Expected behavior

.

Reproduction steps

.

Code Snippet

// Put your code below this line.

Log output

// Put your output below this line

Additional configuration

No response

Operating System

No response

Additional information and screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    papercutSmall annoyances in the Cedar SDK. Lower priority fixes than bugs. Smaller than a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions