Skip to content

Conversation

@Shwetap05
Copy link
Member

Added comparison logic for

  • OpenApiInfo
  • OpenApiExternalDocs
  • OpenApiSecurityRequirements

- OpenApiInfo
- OpenApiContact
- OpenApiLicense
- OpenApiExternalDocs
- OpenApiSecurityRequirements
- OpenApiTag
@Shwetap05 Shwetap05 requested a review from PerthCharern October 5, 2018 23:37
Style = ParameterStyle.Form,
Explode = false,
AllowReserved = false
},
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right. Copy-paste error? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry what doesn't seem right?


In reply to: 223510742 [](ancestors = 223510742)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh got it yes copy paste error for sure


In reply to: 223851085 [](ancestors = 223851085,223510742)

comparisonContext
.GetComparer<TReference>()
.Compare(source, target, comparisonContext);
}
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something that should be in its own class OpenApiReferenceComparer rather than the base class #Closed

Copy link
Member Author

@Shwetap05 Shwetap05 Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but didn't implement it b/c even if i add as separate comparer class like below

public class OpenApiReferenceComparer : OpenApiComparerBase where T : IOpenApiReferenceable

It can't be registered under OpenApiComparerFactory, b/c the type of reference is an enum and can't register various reference comparer based on the value of enum,

That said i will still add the comparer class and reference it directly in the comparers where we diff reference.


In reply to: 223511051 [](ancestors = 223511051)

newKeyInTarget,
target[newKeyInTarget]),
OpenApiComparedElementType = typeof(KeyValuePair<string, string>)
});
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this http://jsonpatch.com/, this should be

            WalkAndAddOpenApiDifference(
                comparisonContext,
                newKeyInTarget,
                new OpenApiDifference
                {
                    OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add,
                    TargetValue = target[newKeyInTarget],
                    OpenApiComparedElementType = typeof(string)
                }); #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see a dictionary example for json patch , so i am not sure if this is correct, can you point me to a dictionary example that you might have found?


In reply to: 223511856 [](ancestors = 223511856)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C# Dictionary should be treated as a JSON object.

The first example on http://jsonpatch.com/
See the second line:

{ "op": "add", "path": "/hello", "value": ["world"] }

and the third line:

{ "op": "remove", "path": "/foo" }


In reply to: 223857178 [](ancestors = 223857178,223511856)

removedKeyFromSource,
source[removedKeyFromSource]),
OpenApiComparedElementType = typeof(KeyValuePair<string, string>)
});
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            WalkAndAddOpenApiDifference(
                comparisonContext,
                removedKeyFromSource,
                new OpenApiDifference
                {
                    OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove,
                    SourceValue = source[removedKeyFromSource],
                    OpenApiComparedElementType = typeof(string)
                }); #Closed


comparisonContext
.GetComparer<TReference>()
.Compare(source, target, comparisonContext);
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the example case of this? If the references are indeed pointing to the same object, wouldn't these two objects always be the same? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Id are same we can't assume that the referenced object will be same too.


In reply to: 223515635 [](ancestors = 223515635)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be true in the C# sense, but from the way we use the Reference object, how would that be possible? If the ID is the same, doesn't that mean this refers to exactly the same object. In fact, the reference object will only be serialized as $ref (or plain string in case of tag) with id only.


In reply to: 223858079 [](ancestors = 223858079,223515635)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted with Shweta. We will do a deep comparison here, so that it's useful for API consumer to see what exactly has changed to an API. Same principle applies to the Security Scheme in Security Requirement.


In reply to: 223899238 [](ancestors = 223899238,223858079,223515635)

OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add,
TargetValue = new KeyValuePair<OpenApiSecurityScheme, IList<string>>(
newSecuritySchemeInTarget,
targetSecurityRequirement[newSecuritySchemeInTarget]),
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be a key-value pair. We are already pointing the the value itself - just use the IList. #Closed

{
WalkAndAddOpenApiDifference(
comparisonContext,
newSecuritySchemeInTarget.Reference.Id,
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newSecuritySchemeInTarget.Reference.Id, [](start = 19, length = 40)

Does this yield the right string (i.e. just the security scheme name, not the entire json pointer)? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i have test for it in OpenApiComparerTests


In reply to: 223516346 [](ancestors = 223516346)

OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove,
SourceValue = new KeyValuePair<OpenApiSecurityScheme, IList<string>>(
sourceSecurityScheme,
sourceSecurityRequirement[sourceSecurityScheme]),
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to above. This should not be a Key Value Pair #Closed

sourceSecurityScheme.Reference.Id,
() => comparisonContext
.GetComparer<OpenApiSecurityScheme>()
.Compare(sourceSecurityScheme, targetSecurityScheme, comparisonContext));
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be comparing the OpenApiSecurityScheme. Shouldn't we be comparing the list of strings in the value side? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not compare Security scheme? if source and target reference two different types of security schemes there should be a diff for it.


In reply to: 223516846 [](ancestors = 223516846)

Copy link
Member Author

@Shwetap05 Shwetap05 Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said i was thinking whether to compare scope list or not, and if i do compare how the pointer should be ?

e.g. if source is

new OpenApiSecurityRequirement
{
[
new OpenApiSecurityScheme
{
Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme1"}
}
] = new List
{
"scope1",
"scope2",
"scope3"
}
}

and Target is

new OpenApiSecurityRequirement
{
[
new OpenApiSecurityScheme
{
Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme1"}
}
] = new List
{
"scope2",
"scope3"
}
}

Then should diff be #/0 --> remove?


In reply to: 223852204 [](ancestors = 223852204,223516846)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We should not compare SecurityScheme here because we only use its name as a key. From the OpenAPI document standpoint, only the key (id of the ref) will show up. Even if we manually craft the DOM to actually be different (say, add some random other things into the Security Scheme), the resulting serialized document will be exactly the same for this SecurityRequirement object.

  • Ideally, diff in the above case should be Remove /scheme1/0. However, from the way you handle the Ordered List (in OpenApiOrderedListComparer), this can be

    • Update /scheme1/0 from scope1 to scope2
    • Update /scheme1/1 from scope2 to scope3
    • Remove /scheme1/2

    which is also okay (and correct).


In reply to: 223852979 [](ancestors = 223852979,223852204,223516846)

Copy link
Contributor

@PerthCharern PerthCharern Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to be really fancy, we can use an algo for "minimum edit distance" to find the best list of update/add/remove (think about one scope being one letter in the original problem). I'd strongly suggest we don't do it in this PR though :)


In reply to: 223900360 [](ancestors = 223900360,223852979,223852204,223516846)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a separate PR to compare scopes


In reply to: 224182344 [](ancestors = 224182344,223900360,223852979,223852204,223516846)

] = new List<string>
{
"scope4",
"scope5"
Copy link
Contributor

@PerthCharern PerthCharern Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try add test cases with two different scope lists #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently not comparing scope lists, have replied on other thread on question i have on diff of it


In reply to: 223517115 [](ancestors = 223517115)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will cover in another PR


In reply to: 223853512 [](ancestors = 223853512,223517115)

Copy link
Contributor

@PerthCharern PerthCharern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

@PerthCharern
Copy link
Contributor

PerthCharern commented Oct 9, 2018 via email

@PerthCharern PerthCharern added the type:feature New experience request label Oct 10, 2018
Copy link
Contributor

@PerthCharern PerthCharern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@Shwetap05 Shwetap05 merged commit 59260d3 into vnext Oct 11, 2018
@darrelmiller darrelmiller deleted the Comparer-2 branch February 28, 2021 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New experience request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants