-
Notifications
You must be signed in to change notification settings - Fork 287
Open api example comparer #331
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a674f47
Added comparison logic for
Shwetap05 f9bdc15
FIx review comments
Shwetap05 f3efe85
Comparer logic for Example
Shwetap05 f3e778a
merge
Shwetap05 17079ee
Fix merge issues
Shwetap05 9063d2a
Fix review comments
Shwetap05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Microsoft.OpenApi.Any; | ||
| using Microsoft.OpenApi.Writers; | ||
|
|
||
| namespace Microsoft.OpenApi.Services | ||
| { | ||
| /// <summary> | ||
| /// Defines behavior for comparing properties of <see cref="IOpenApiAny"/>. | ||
| /// </summary> | ||
| public class OpenApiAnyComparer : OpenApiComparerBase<IOpenApiAny> | ||
| { | ||
| /// <summary> | ||
| /// Executes comparision against source and target <see cref="IOpenApiAny"/>. | ||
| /// </summary> | ||
| /// <param name="source">The source.</param> | ||
| /// <param name="target">The target.</param> | ||
| /// <param name="comparisonContext">Context under which to compare the source and target.</param> | ||
| public override void Compare( | ||
| IOpenApiAny source, | ||
| IOpenApiAny target, | ||
| ComparisonContext comparisonContext) | ||
| { | ||
| if (source == null && target == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (source == null || target == null) | ||
| { | ||
| comparisonContext.AddOpenApiDifference( | ||
| new OpenApiDifference | ||
| { | ||
| OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, | ||
| SourceValue = source, | ||
| TargetValue = target, | ||
| OpenApiComparedElementType = typeof(IOpenApiAny), | ||
| Pointer = comparisonContext.PathString | ||
| }); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| var sourceStringWriter = new StringWriter(); | ||
| var sourceWriter = new OpenApiJsonWriter(sourceStringWriter); | ||
|
|
||
| source.Write(sourceWriter, OpenApiSpecVersion.OpenApi3_0); | ||
| var sourceValue = sourceStringWriter.GetStringBuilder().ToString(); | ||
|
|
||
| var targetStringWriter = new StringWriter(); | ||
| var targetWriter = new OpenApiJsonWriter(targetStringWriter); | ||
|
|
||
| target.Write(targetWriter, OpenApiSpecVersion.OpenApi3_0); | ||
| var targetValue = targetStringWriter.GetStringBuilder().ToString(); | ||
|
|
||
| if (string.Compare(sourceValue, targetValue, StringComparison.InvariantCulture) != 0) | ||
| { | ||
| comparisonContext.AddOpenApiDifference(new OpenApiDifference | ||
| { | ||
| OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, | ||
| OpenApiComparedElementType = typeof(IOpenApiAny), | ||
| SourceValue = source, | ||
| TargetValue = target, | ||
| Pointer = comparisonContext.PathString | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using Microsoft.OpenApi.Any; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.OpenApi.Services | ||
| { | ||
| /// <summary> | ||
| /// Defines behavior for comparing properties of <see cref="OpenApiExample"/>. | ||
| /// </summary> | ||
| public class OpenApiExampleComparer : OpenApiComparerBase<OpenApiExample> | ||
| { | ||
| /// <summary> | ||
| /// Executes comparision against source and target <see cref="OpenApiExample"/>. | ||
| /// </summary> | ||
| /// <param name="sourceExample">The source.</param> | ||
| /// <param name="targetExample">The target.</param> | ||
| /// <param name="comparisonContext">Context under which to compare the source and target.</param> | ||
| public override void Compare( | ||
| OpenApiExample sourceExample, | ||
| OpenApiExample targetExample, | ||
| ComparisonContext comparisonContext) | ||
| { | ||
| if (sourceExample == null && targetExample == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (sourceExample == null || targetExample == null) | ||
| { | ||
| comparisonContext.AddOpenApiDifference( | ||
| new OpenApiDifference | ||
| { | ||
| OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, | ||
| SourceValue = sourceExample, | ||
| TargetValue = targetExample, | ||
| OpenApiComparedElementType = typeof(OpenApiExample), | ||
| Pointer = comparisonContext.PathString | ||
| }); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| new OpenApiReferenceComparer<OpenApiExample>() | ||
| .Compare(sourceExample.Reference, targetExample.Reference, comparisonContext); | ||
|
|
||
| WalkAndCompare(comparisonContext, OpenApiConstants.Description, | ||
| () => Compare(sourceExample.Description, targetExample.Description, comparisonContext)); | ||
|
|
||
| WalkAndCompare(comparisonContext, OpenApiConstants.Summary, | ||
| () => Compare(sourceExample.Summary, targetExample.Summary, comparisonContext)); | ||
|
|
||
| WalkAndCompare(comparisonContext, OpenApiConstants.ExternalValue, | ||
| () => Compare(sourceExample.ExternalValue, targetExample.ExternalValue, comparisonContext)); | ||
|
|
||
| WalkAndCompare( | ||
| comparisonContext, | ||
| OpenApiConstants.Value, | ||
| () => comparisonContext | ||
| .GetComparer<IOpenApiAny>() | ||
| .Compare(sourceExample.Value, targetExample.Value, comparisonContext)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we removing these "// To Do compare extensions" comments? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will be tracking this work as an issue on github instead of adding these ToDo
In reply to: 225337695 [](ancestors = 225337695)