Skip to content

Commit 500f0c7

Browse files
committed
Override the base GetHashCode() to compute the hash value for an OpenApi document and its property values
1 parent 0636e4a commit 500f0c7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,27 @@ public IOpenApiReferenceable ResolveReference(OpenApiReference reference)
375375
return ResolveReference(reference, false);
376376
}
377377

378+
/// <summary>
379+
/// Computes the hash code for an OpenApiDocument and its property values.
380+
/// </summary>
381+
/// <returns> The hash code.</returns>
382+
public override int GetHashCode()
383+
{
384+
// select two random prime numbers e.g 1 and 3 and use them to compute hash codes
385+
int hash = 1;
386+
hash = hash * 3 + (Workspace == null ? 0 : Workspace.GetHashCode());
387+
hash = hash * 3 + (Info == null ? 0 : Info.GetHashCode());
388+
hash = hash * 3 + (Servers == null ? 0 : Servers.GetHashCode());
389+
hash = hash * 3 + (Paths == null ? 0 : Paths.GetHashCode());
390+
hash = hash * 3 + (Components == null ? 0 : Components.GetHashCode());
391+
hash = hash * 3 + (SecurityRequirements == null ? 0 : SecurityRequirements.GetHashCode());
392+
hash = hash * 3 + (Tags == null ? 0 : Tags.GetHashCode());
393+
hash = hash * 3 + (ExternalDocs == null ? 0 : ExternalDocs.GetHashCode());
394+
hash = hash * 3 + (Extensions == null ? 0 : Extensions.GetHashCode());
395+
396+
return hash;
397+
}
398+
378399
/// <summary>
379400
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
380401
/// </summary>

0 commit comments

Comments
 (0)