Fix temp parameters duplicate issue + Allow relative URIs where appropriate#197
Fix temp parameters duplicate issue + Allow relative URIs where appropriate#197PerthCharern merged 6 commits intomasterfrom
Conversation
…Ensure that the reader doesn't error out when parsing absolute URI fails. - Validator should take care of validating whether the URI conforms to the spec. XML.Namespace is the only place the spec indicates the the URI must be absolute. This will be a handled in a separate PR. - formParameters temp variable is set to empty at the beginning of each operation processing.
|
cc @sergey-tihon #Resolved |
|
Just a question, should this PR also consider URLs in Sample "enum": {
"type": "array",
"items": {
"$ref": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/apiVersion"
},
"minItems": 1,
"uniqueItems": true
}from https://github.com/Azure/azure-resource-manager-schemas/blob/master/tools/ResourceMetaSchema.json#L160 #Resolved |
|
@darrelmiller is working on the support for external references. That feature will likely come as a separate PR. #Resolved |
| { | ||
| node.Diagnostic.Errors.Add( | ||
| new OpenApiError(node.Context.GetLocation(), $"Scheme {property.Name} is not found")); | ||
| //node.Diagnostic.Errors.Add( |
There was a problem hiding this comment.
What should happen if scheme is null? #Resolved
There was a problem hiding this comment.
The spec says
the name used for each property MUST correspond to a security scheme declared in the Security Schemes under the Components Object.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#security-requirement-object
So I believe we should mark this as an error. Not sure why this has been commented out /cc @PerthCharern #Resolved
There was a problem hiding this comment.
I commented this out so that I could test without running into NRE and forgot to revert back.
In reply to: 165090553 [](ancestors = 165090553)
| new OpenApiXml | ||
| { | ||
| Name = "name1", | ||
| // TODO: Verify that the URL caused a parsing error. |
There was a problem hiding this comment.
Looks like a candidate for one more assertion for diagnostic . #Resolved
There was a problem hiding this comment.
I changed this to a success case since that's what the spec allows (relative url should also work).
In reply to: 164986283 [](ancestors = 164986283)
There was a problem hiding this comment.
I created a new test case with empty URL. The diagnostic should contain an error for empty URL.
In reply to: 168329298 [](ancestors = 168329298,164986283)
|
I do not familiar with codebase yet, but there are 2 comments from me on the diff 😊 #Resolved |
darrelmiller
left a comment
There was a problem hiding this comment.
We should have a conversation about the use of Uri.TryCreate. I'm not sure it is a good idea. And I don't think we can use the static _responseSchema
| if (Uri.TryCreate(n.GetScalarValue(), UriKind.RelativeOrAbsolute, out uri)) | ||
| { | ||
| o.Url = uri; | ||
| } |
There was a problem hiding this comment.
I'm not sure I'm a fan of this approach. We are going to swallow the error and when reporting the problem all we can say is "you are missing a URL". This is going to be confusing to the person who believes they put a URL and it is invalid. I think it is valid to have two distinct sources of errors. One from parsing content, and one from validating the DOM. We can't avoid it anyway because sometimes the YAML/JSON is going to be badly formatted. #Resolved
There was a problem hiding this comment.
We should still produce the document though. If I throw an error here, everything breaks.
We need to have a way to still allow reading to go through and add the errors along the way.
In reply to: 165092404 [](ancestors = 165092404)
There was a problem hiding this comment.
Without that mechanism, what we can do is making the reporting message a bit more generic:
"The string passed in cannot be parsed into a URL."
This should be a very rare case. Almost any string can be a url. Even "abcdef" is allowed to be parsed in as a URL. Cases I suspect will be caught would be something like an empty string or a white space string.
In reply to: 167382549 [](ancestors = 167382549,165092404)
| node.Context.SetTempStorage("bodyParameter", null); | ||
| node.Context.SetTempStorage("formParameters", null); | ||
| node.Context.SetTempStorage("operationProduces", null); | ||
| node.Context.SetTempStorage("operationConsumes", null); |
There was a problem hiding this comment.
I guess we should probably create constants for these. #Resolved
| "schema", (o, n) => | ||
| { | ||
| n.Context.SetTempStorage("operationschema", LoadSchema(n)); | ||
| _responseSchema = LoadSchema(n); |
There was a problem hiding this comment.
Why this change to a static? This is going to make the deserializer not thread safe. That is most likely going to be a problem. #Resolved
There was a problem hiding this comment.
You are right. I wasn't thinking about that issue. I'll revert this back. There are a few instances like this in the code, so I'll fix those separately.
In reply to: 165093793 [](ancestors = 165093793)
| SRResource.JsonPointerCannotBeResolved, | ||
| jsonPointer)); | ||
| } | ||
|
|
There was a problem hiding this comment.
Maybe once we consolidate the error classes we can just throw this exception from inside the Find. Is there somewhere where we need the response to be null on fail? #Resolved
There was a problem hiding this comment.
Throwing the error here allows us to control what to do with json pointers that we cannot resolve. At least, we can leave them as a reference object (and reporting it) rather than always throwing an error and stopping the entire parsing process.
This probably no longer applies with the new reference resolving method.
In reply to: 165094630 [](ancestors = 165094630)
|
Apologies for the delay on this, and thanks for all your comments (@sergey-tihon, @darrelmiller) I'll try to address all the comments by end of this week. #Resolved |
|
Update: I got booked up with other commitments this week, but I'm almost done. I'll update the PR next week. Sorry again for the delay. #Resolved |
|
I've been thinking a bit more about this. Here's what I'll do:
|
…y given that we might want to change the properties to strings. - Allow relative URL where allowed by the spec. - Use constants for temp storage variable name.
|
@darrelmiller This PR has become much smaller and is ready now. I will handle #192 in a separate PR since it turned out to be a bit more involved than I expected. What do you think about my proposal in 1. below? |
| catch (Exception) | ||
| { | ||
| throw new ArgumentException("Failed to dereference pointer", ex); | ||
| return null; |
There was a problem hiding this comment.
I'm still a little nervous about this change, but let's try it and see if it causes any issues.
|
|
Handle URI parsing. Allows relative URI where allowed by the spec. Partially addressed Handle empty URI when reading #192.
Temp variables in Operation deserializer (formParameters, bodyParameter, operationConsumes, operationProduces) are set to null at the beginning of each operation processing. Fix "formparameters" temp variable must be cleared after each operation is processed #191