-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Provide datastructures that retain the original order of items in the document #119
Comments
This is a good idea; it's a heavy lift, however. A good |
Seeing how we want to preserve API backwards compatibility, is there a chance that such a feature would be merged in, or would we have to wait until at least v0.2? |
I was half way through implementing this when I noticed that I don't really need any of this to preserve object property order. All I needed to do was use the propertyLines := make(map[string]int, len(propertyNames))
for _, name := range propertyNames {
lowProperty := schema.GoLow().FindProperty(name)
propertyLines[name] = lowProperty.ValueNode.Line
}
sort.Slice(propertyNames, func(i, j int) bool {
return propertyLines[propertyNames[i]] < propertyLines[propertyNames[j]]
}) Update: this works better: propertyLines := make(map[string]int, len(propertyNames))
for _, name := range propertyNames {
lowProperty := schema.Properties[name].GoLow()
propKeyNode := darkfuckingmagic.UnexportedField[*yaml.Node](lowProperty, "kn")
propertyLines[name] = propKeyNode.Line
}
sort.Slice(propertyNames, func(i, j int) bool {
return propertyLines[propertyNames[i]] < propertyLines[propertyNames[j]]
}) |
We solved this in the interim with:
and
@daveshanley might be worth providing helper methods that do this as part of libopenapi until those other changes are ready? as the code to call these is not great:
would be much nicer to call Though would only be worth doing if those other fixes are still a ways out? |
Resolved in |
Ideally we would be able to iterate through a document in the order of items (think paths, operations etc, etc) but due to the use of go native maps this isn't possible with the high level API.
I would recommended switching to using https://github.com/wk8/go-ordered-map or similar to provide this functionality which might also help with this other issue I opened #109 to ensure rendering new items out can retain an order.
The text was updated successfully, but these errors were encountered: