apischema icon indicating copy to clipboard operation
apischema copied to clipboard

Order fields alphabetically in serialization

Open wyfo opened this issue 2 years ago • 1 comments

See https://github.com/wyfo/apischema/discussions/226#discussioncomment-1540839 (a workaround is given).

Such ordering should be handled by order decorator.

My first idea is to pass a function parameter to order, which would be applied to the list of aliases and return them ordered. Alphabetical ordering would then just be @order(sorted)

However, it would maybe not be very intuitive that the function operates on aliases while only field names are allowed in the list arguments. Should this restriction be released before? IMO this is find.

By the way, dynamic ordering should be settable globally through a settings key. (maybe settings.serialization?)

wyfo avatar Oct 26 '21 19:10 wyfo

I think it would be awesome to be able to pass in a function to order, however would resolving against the aliased field names be the optimal approach? I think it would be best to be consistent with either taking a list of aliased field names (since the aliased fields names is what the function that would be passed in would be operating against), or having the passed in function operate against the field names instead of the aliases.

Also, what if instead of using the field names as the value to sort against, what if one wanted to use the field values instead when performing any kind of ordering? Could that be possible, and if so, what would that look like?

CaptainDriftwood avatar Oct 27 '21 03:10 CaptainDriftwood