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

Use sorted properties when saving configuration in NSwagStudio #4575

Closed
wants to merge 1 commit into from

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented Nov 7, 2023

It's quite annoying to see all JSON properties jumping around when saving new version of nswag.json (migrating from v13 to v14). We could introduce a one time breaking change which will make Studio save file following ordered JSON property names so that later VCS diffs etc would look nicer.

Included change for NSwag.Sample.NET80/nswag.json which shows how obsolete properties are removed and they are now sorted correctly after save via NSwagStudio.

@@ -515,12 +525,6 @@ private static string TransformLegacyDocument(string data, out bool saveFile)
saveFile = true;
}

if (data.Contains("\"noBuild\":") && !data.ToLowerInvariant().Contains("UseDocumentProvider".ToLowerInvariant()))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find a property UseDocumentProvider anywhere so this seemed unnecessary

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is gone, correct

@lahma lahma marked this pull request as draft November 8, 2023 03:32
@lahma lahma marked this pull request as ready for review November 8, 2023 08:45
@lahma lahma requested a review from RicoSuter November 8, 2023 08:45
@RicoSuter
Copy link
Owner

Can't you just update the nswag.json with the new version and then the props should be stable as the order in c# stays? Do we really need reorder? I think alpha order is not optimal as the props which belong together are shuffled...

@lahma
Copy link
Collaborator Author

lahma commented Nov 13, 2023

Hmm so this has changed in NET 7 that you could get the properties in same order every time even with reflection, before it was not guaranteed:

https://learn.microsoft.com/en-us/dotnet/api/system.type.getproperties?view=net-7.0

In .NET 6 and earlier versions, the GetProperties method does not return properties in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which properties are returned, because that order varies. However, starting with .NET 7, the ordering is deterministic based upon the metadata ordering in the assembly.

I'm more of a alphabetical guy myself. I like to see all ignoreXXX, includeXXX, excludeXXX kind of properties list together so I can explore all the things I can use to for example include and exclude and then flip the switches which are nicely grouped together. But I do understand the sentiment to have the in some other order too.

@lahma lahma closed this Feb 28, 2024
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

Successfully merging this pull request may close these issues.

2 participants