Skip to content

Commit

Permalink
Merge pull request #155 from exoego/sort-paths
Browse files Browse the repository at this point in the history
Sort paths lexicographically so the order of paths is more stable and predictable
  • Loading branch information
exoego committed Dec 6, 2023
2 parents 7ea88d2 + d10c469 commit de5106c
Show file tree
Hide file tree
Showing 4 changed files with 748 additions and 740 deletions.
1 change: 1 addition & 0 deletions lib/rspec/openapi/result_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def record_results!
RSpec::OpenAPI::SchemaCleaner.cleanup!(spec, new_from_zero)
RSpec::OpenAPI::ComponentsUpdater.update!(spec, new_from_zero)
RSpec::OpenAPI::SchemaCleaner.cleanup_empty_required_array!(spec)
RSpec::OpenAPI::SchemaCleaner.sort_paths!(spec)
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/rspec/openapi/schema_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def cleanup_empty_required_array!(base)
end
end

# Sort "paths" lexicographically to make the order more predictable
#
# @param [Hash] #
def sort_paths!(spec)
spec['paths'] = spec['paths']&.entries&.sort_by! { |path, _| path }.to_h
end

private

def cleanup_array!(base, spec, selector, fields_for_identity = [])
Expand Down
Loading

0 comments on commit de5106c

Please sign in to comment.