-
Notifications
You must be signed in to change notification settings - Fork 738
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
Filtering resource models returned only by post #2365
Conversation
|
||
var unfilteredResourceCandidates = resourceModels.Union(modelsAllOfOnXmsAzureResources); | ||
|
||
// Now filter all the resource models that are returned from a POST operation only |
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 don't see the "only" part reflected in the code but maybe I'm missing it.
Also, the indentation is misleading: the .SelectMany
calls are perfectly aligned but are not operating on the same "level". I'd expect the second SelectMany
to be on the same height as the inner Where
, just break pathObj => pathObj<HERE>.Where
and lines won't be that long.
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.
d'oh (I went everywhere looking for a Homer emoji!)
var postOpResourceModels = serviceDefinition.Paths.Values.SelectMany(pathObj => pathObj.Where(opObj => opObj.Key.EqualsIgnoreCase("post")) | ||
.SelectMany(opObj => opObj.Value.Responses?.Select(resp => resp.Value?.Schema?.Reference?.StripDefinitionPath()))) | ||
.Where(model => !string.IsNullOrWhiteSpace(model)) | ||
.Except(putOperationsResponseModels) |
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.
don't implement the "only" by relying on other sets and excepting them.
- you already missed some HTTP methods, what about PATCH?
- it's not obvious that
putOperationsResponseModels
contains all models of PUT methods. Next month, someone applies a fix to something by changing that set, not realizing that it breaks this line. Locality 😉
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.
how about looking into the models returned by operations and selecting the ones that are only returned by posts? then removing those from the previous set? I would probably not call it "unfiltered" set, since it's already quite filtered, maybe "resourceCandidates".
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 literally called it resourceCandidates
before changing my mind 😆
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.
@veronicagg that is what I am precisely trying to do
@olydis from what @ravbhatnagar indicated on the issue, I should really be looking at anything returned by a PUT/GET operation only.
Also, models being populated in the putOperationsResponseModels
are basically resource model candidates and this particular filtering is applicable only to the resource models, would I still miss out on anything here?
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.
sounds good, how does the rule perform on the specs repo?
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.
Well, this is not a rule per se, more like pre cursor step to running any arm related validation rules.
This is a one off operation and the results are stored in the context object passed to every single rule.
This makes me wonder if we should run this logic even if we do not have any arm specific rules to run, given how expensive these operations are its worth a look. what say?
var postOpResourceModels = serviceDefinition.Paths.Values.SelectMany(pathObj => pathObj.Where(opObj => opObj.Key.EqualsIgnoreCase("post")) | ||
.SelectMany(opObj => opObj.Value.Responses?.Select(resp => resp.Value?.Schema?.Reference?.StripDefinitionPath()))) | ||
.Where(model => !string.IsNullOrWhiteSpace(model)) | ||
.Except(putOperationsResponseModels) |
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.
how about looking into the models returned by operations and selecting the ones that are only returned by posts? then removing those from the previous set? I would probably not call it "unfiltered" set, since it's already quite filtered, maybe "resourceCandidates".
I do not have any other comments apart from what's already been commented. Feel free to discuss with them and I'd be fine on the decision. I am not posting "Approve" / "Request Changes" as I'll be OOF tomorrow so if it gets resolved, go ahead :) |
@dsgouda apart from updating the name to "resourceCandidates" which I'm not seeing, rest looks good to me. I'd be good to run some of the resource related rules on the repo and make sure we're accurate. Since the rule won't get released right away (not as "latest"), if you'd done validation already you could run on the repo afterwards with the nightly build. thanks! |
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.
See my prior comment, pending CI results, I'm good with the rest.
Thanks @veronicagg I will run the changes against the rest spec repo |
Ran this against a few specs in the rest spec repo, and I still see the resources being picked as expected, we can investigate this further if required. |
{ | ||
this.Root = root; | ||
this.Value = root; | ||
this.File = file; | ||
PopulateResourceTypes(root); | ||
if (metadata.ServiceDefinitionDocumentType == ServiceDefinitionDocumentType.ARM) |
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 change breaks CI:
https://github.com/Azure/autorest/blob/master/src/modeler/AutoRest.Swagger/Validation/BodyTopLevelProperties.cs#L52 fails because resModels
is null
. Since that didn't happen before, I bet that it is this guard that causes the context.ResourceModels
to not be populated...
Now, I see that both this guard and the rule say that they are ARM
, but still, this is kind of the only potential point of failure I could make out.
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.
further observation: this ==
will fail if metadata.ServiceDefinitionDocumentType
are multiple types at once!
Instead of duplicating the logic for document type filtering, I'd honestly just make ResourceModels
a lazily initialized property! If someone asks for it, populate it, otherwise don't. That way, you automatically inherit the correct behavior from the fact that the rules are classified correctly.
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.
hmm... starting to think if there is any value in adding the check after all.
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.
fair point, don't think anyone severely suffers because of this... main customer is still ARM, for data plane I also assume this goes faster since there is actually not much that looks like a resource. And even then, what's the actual overhead of this? Would be surprised if it took half a second on most Swaggers.
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.
Agreed, even if it does warrant a performance investigation, I think we can revisit this once we move validator to a different repo,
Addressing #2316