Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/OpenAPIRuntime/Base/OpenAPIValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
case let value as [(any Sendable)?]:
for item in value { hasher.combine(OpenAPIValueContainer(validatedValue: item)) }
case let value as [String: (any Sendable)?]:
for (key, itemValue) in value {
for key in value.keys.sorted() {
hasher.combine(key)
hasher.combine(OpenAPIValueContainer(validatedValue: itemValue))
hasher.combine(OpenAPIValueContainer(validatedValue: value[key]))
}
default: break
}
Expand Down Expand Up @@ -421,9 +421,9 @@ public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public func hash(into hasher: inout Hasher) {
for (key, itemValue) in value {
for key in value.keys.sorted() {
hasher.combine(key)
hasher.combine(OpenAPIValueContainer(validatedValue: itemValue))
hasher.combine(OpenAPIValueContainer(validatedValue: value[key]))
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/OpenAPIRuntimeTests/Base/Test_OpenAPIValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@ final class Test_OpenAPIValue: Test_Runtime {
encodedData
)
}

func testHashing_objectOrderIndependence_success() throws {
let container1 = try OpenAPIObjectContainer(unvalidatedValue: ["foo": 0, "bar": 1])
let container2 = try OpenAPIObjectContainer(unvalidatedValue: ["bar": 1, "foo": 0])
XCTAssertEqual(container1, container2)
XCTAssertEqual(container1.hashValue, container2.hashValue)
}

func testHashing_containerOrderIndependence_success() throws {
let container1 = try OpenAPIValueContainer(unvalidatedValue: ["foo": 0, "bar": 1])
let container2 = try OpenAPIValueContainer(unvalidatedValue: ["bar": 1, "foo": 0])
XCTAssertEqual(container1, container2)
XCTAssertEqual(container1.hashValue, container2.hashValue)
}
}

struct MyAnyOf2<Value1: Codable & Hashable & Sendable, Value2: Codable & Hashable & Sendable>: Codable, Hashable,
Expand Down