-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat: keep struct fields order in schema #539
base: master
Are you sure you want to change the base?
feat: keep struct fields order in schema #539
Conversation
Changing the properties type would be a breaking change :( We might need a breaking change for upping the mrsv so maybe it's a good time for it.
Yeah, I guess so
You mean control wether we preserve order or not? |
Hey,
Indeed! My bad, I didn't think about it because it's actually quite hard / I didn't directly see the use case, to directly use the derived Re. why it's hard: see e.g. my test. Since particular schemas are not named (they could be if e.g. In the end: I'm not in a particular hurry, for my use case I'm OK waiting for a
Again you might be right. It will definitely "preserve order" for everything serialized by
I didn't touch them because I dont use
Yes I meant something like /// Order fields like I declare them
#[derive(Apiv2Schema(order = "struct")]
struct Dog {
...
}
/// Or just #[derive(Apiv2Schema)] because retrocompat
#[derive(Apiv2Schema(order = "alphabetical")]
struct Cat {
...
} |
I'm not 100% sure either, but rust features are additive so if someone is using resolver 1 AFAIK then serde_json deps get merged with all combined features added in a single build. But again I'm not certain either.
That looks awesome! Would allow for preserving behaviour in case someone prefers alphabetical for some reason. |
Unfortunately that can't work, or I didn't find a way. At the end of the day, when you're serializing in json with serde, you're going through serde's abstraction of calling I see two approaches to this. Both have as first step: add a Then either: A. activate I personaly have a strong preference for A for the same reason as #540, if you don't already have |
Alright seems like it's a no go then, thanks for trying!
Yeah, I think A is fine. It should be obvious from the feature on the toml that it activates the serde_json's equivalent feature. |
f5b87b9
to
b390150
Compare
b390150
to
621133c
Compare
I added a I didn't change the other Right now my test does not test the |
This may have a potentially nasty side effect. If in a workspace, we have a crate using paperclip and then a new crate starts depending on
All combinations might be tricky, because of actix3 and actix4 already have the issue highlighted above, they're not additive 😞 |
Fixes #538.
A first proposal.
Arguably the other BTreeMap
extra_properties
etc could be changed too?Also with a bit more work, it could be an option of the
Apiv2Schema
derive. Let me know!