Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let user extend SmithyIdlComponentOrder with custom Comparator #2564

Open
combinatorist opened this issue Mar 18, 2025 · 0 comments
Open

Let user extend SmithyIdlComponentOrder with custom Comparator #2564

combinatorist opened this issue Mar 18, 2025 · 0 comments

Comments

@combinatorist
Copy link
Contributor

Currently, SmithyIdlComponentOrder only takes 3 values:

  • ALPHA_NUMERIC
  • SOURCE_LOCATION
  • PREFERRED

However, users sometimes have valid reasons for wanting their own sort order.

Our use case: as an example

Background: a table registry in smithy

We manage database tables via a registry of smithy IDL files (in a git repo). Users sometimes write their IDL from scratch, but usually they start by making a table in a sandbox area of the database. When they are done developing the table, they want to bring it into the registry, so our tooling includes the ability to translate the table into a smithy IDL file on demand.

The problem: readable smithy IDL

For style and readability reasons, we want to put the table's Struct at the end of the file after all the shapes (column data types, etc) that build up to it. We can't sort the model since it's intrinsically unsorted (a good thing) and sorting the output would be too finicky. If there were an AST between the model and the text output, we could sort that very fluently, but the only options we've found render text directly from the model.

Workaround: faking source location

Long story short, we're faking source location for each shape to get the desired output. It works, but obviously it's very ugly and wouldn't work for anyone who really needs the source location and control of the component order.

Proposal: let user bring their own comparator

A Comparator might not always be the easiest way to specify a sort. For example, in our case, we mostly just want the table's shape to show up last and there are many easier ways to express that. But any sorting logic can ultimately be specified with a comparator and most logics will be better or best expressed that way anyway.

So, adding this one feature would allow all possible sorts (but IDK how hard it is to add).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant