Skip to content

Commit

Permalink
paths should be sorted lexicographically
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Dec 6, 2023
1 parent c0fb037 commit d10c469
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 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

0 comments on commit d10c469

Please sign in to comment.