-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fixes #358 MockGeneratorPlugin errors if the response headers have a duplicate #372
Conversation
…duplicate header Resolved by only including distinct headers in the response list.
@microsoft-github-policy-service agree |
Thanks for the PR @mosoftwareenterprises! I'm curious what are the headers that are present twice? |
I have just spent the last 20mins trying to replicate the issue, and could only do so via browsing in google, |
Some scenarios will need multiple headers (on Graph, for instance with Prefer). I'm wondering if our data structure here is the right one. @waldekmastykarz or @gavinbarron would you mind chiming in? |
oof. yeah, multiple headers with the same name are allowed, and is some cases required. Using a dictionary here is not really the right data structure. |
Good point @gavinbarron. We should definitely change how we store headers to |
Yes @waldekmastykarz I will attempt an update to the PR. Question though, as the changes are going to be further reaching than before, how do I regression test? I dont see any automated tests in the repo? |
At this stage we'll have to test it manually. Sorry we don't have a better answer at this moment |
Hey @mosoftwareenterprises, are you still working on this? Anything that we could help with? |
…duplicate header Headers are now List of Dictionaries
Hey @waldekmastykarz . Sorry I have been so busy, I have not had time to finish it. I will commit the latest changes here, but I have not checked it through yet. |
@@ -4,6 +4,8 @@ | |||
using System.Net; | |||
using System.Text.Json; | |||
using System.Text.RegularExpressions; | |||
using Microsoft.EntityFrameworkCore.Metadata; |
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.
Are we using EntityFrmeworkCore for something or is this a leftover?
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.
Must be a leftover. Removed
@@ -18,7 +18,7 @@ public class GraphBatchResponsePayloadResponse { | |||
[JsonPropertyName("body")] | |||
public dynamic? Body { get; set; } | |||
[JsonPropertyName("headers")] | |||
public Dictionary<string, string>? Headers { get; set; } | |||
public List<Dictionary<string, string>>? Headers { get; set; } |
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.
It seems odd to define headers as a list of dictionaries. Shouldn't it be a list of key-value pairs instead?
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.
Using a Dictionary (which is in effect the same thing AFAIK), means we can use Linq to do "ToDictionary()"
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.
This has now changed to a List<KeyValuePair<string,string>> due to the dictionary complicating some other areas.
Hey @mosoftwareenterprises, are you still working on this? |
Hey @waldekmastykarz, I will be picking this up again this week. So hopefully I will have something for you soon. |
Awesome! Looking forward to it! We've done some changes in the meantime, so please don't forget to pull the latest changes to avoid conflicts 😊 |
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.
Hey @mosoftwareenterprises, it seems like your PR includes some additional commits that aren't a part of your change. Could you please clean it up so that we can review it more easily? We appreciate your help
…s have a duplicate. Remove code that is not specific to this fix.
@waldekmastykarz I assume you are referring to the change to correct the CONTRIBUTING.md file which is incorrect, and the changes to add the serializer options in to ignore comments etc. |
Correct, I meant those files. I'll have another look just to double check we're not including anything else that shouldn't be there. Looking forward to checking out your work! |
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.
Nice! Let's do a few changes before we continue
@@ -20,7 +20,7 @@ public class GraphBatchResponsePayloadResponse | |||
[JsonPropertyName("body")] | |||
public dynamic? Body { get; set; } | |||
[JsonPropertyName("headers")] | |||
public Dictionary<string, string>? Headers { get; set; } | |||
public List<Dictionary<string, string>>? Headers { get; set; } |
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.
Instead of creating a separate Dictionary for each key-value pair, let's use a List<Tuple<string, string>>
which seems like a less overhead. Alternatively, we could use List<HttpHeader>
, assuming we can serialize them easily.
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.
Looking at HttpHeader, it is not very nice to serialise, so opting for the Tuple
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.
Changed this to a List<KeyValuePair<string,string>> instead of Tuple. Made it more readable.
…s have a duplicate. Changes following code review.
…s have a duplicate. Changes following code review and further testing
I have tested this again, using a Confluence page (private) and found it was not always working, so additional changes made to cope with that. Ready for review again. |
Thanks @mosoftwareenterprises! We'll do some further adjustments to streamline it across all plugins. We appreciate your help ❤️ |
If a response is recorded and contains the same header key value pair more than once, then an exception is thrown.
This change removes it by only allowing distinct values of the keys.
While I was working with the mock responses file, I noticed you could not comment them out, so a small tweak to allow that too.
This can be tested by hitting the https://graph.microsoft.com/v1.0/users endpoint, and paginating through the list of users you find e.g.