You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Callback key can be a string with embedded RuntimeExpression #287
Currently we only allow RuntimeExpression in a key in a Callback object.
/// <summary>/// A Path Item Object used to define a callback request and expected responses./// </summary>publicDictionary<RuntimeExpression,OpenApiPathItem>PathItems{get;set;}=newDictionary<RuntimeExpression,OpenApiPathItem>();
myWebhook:
'http://notificationServer.com?transactionId={$request.body#/id}&email={$request.body#/email}':
post:
requestBody:
description: Callback payload
content:
'application/json':
schema:
$ref: '#/components/schemas/SomePayload'
responses:
'200':
description: webhook successfully processed and no retries will be performed
Note that the "expression" key above is a URL with RuntimeExpression embedded in.
Note: I think the spec is a bit ambiguous. The spec states this: "The key that identifies the Path Item Object is a runtime expression that can be evaluated in the context of a runtime HTTP request/response to identify the URL to be used for the callback request."
The runtime expression in the spec is strictly defined. There's a bit of leeway with this sentence "Runtime expressions preserve the type of the referenced value. Expressions can be embedded into string values by surrounding the expression with {} curly braces.", but this sentence is in the Examples section of runtime expression section and it contradicts with the definition of runtime expression directly above: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#examples-1
I would say we are actually faithful to the spec with the current implementation - though probably not aligned with the spirit of the spec.
I've created a CompositeExpression class that will contain the outer template string and then create child RuntimeExpression objects for the parts inside {}. As we don't actually do the runtime resolution yet, this shouldn't be too difficult to complete.
There's a bug in the expression parser. We are checking for {$ to determine if it's a composite expression. If the expression is a simple string like /abcd, then we are not parsing it correctly.
Shweta Patil (@Shwetap05) I have a fix pending for the example that Perth included above. However, it will not handle the case when the callback key does not have any runtime expression. i.e. when it is a string literal. This scenario is not one that is currently supported by the OpenAPI specification. Perhaps it should be, but I will need to bring this up with the Technical Steering Committee to see if we can get the spec updated to add support for this use case.
If the customer could add an issue on the OpenAPI repo that would help me make the case for it.
I would argue that even in the current spec version, there's already a bit of an ambiguity in whether the constant /abcd scenario "is one that is currently supported by the OpenAPI specification."
From the spec:
Expressions can be embedded into string values by surrounding the expression with {} curly braces.
This makes it sound like if we are okay with treating a composite expression as a runtime expression, then we should also be okay with including a literal string as a composite expression too. The word "string values" above do not specify any restrictions on the string.
At the end of the day, it sounds like a string literal is a valid key for the callback - it's just a matter of allowing it in the Callback Object or in the Runtime Expression.
We have to unblock our customers who brought us composite expressions. Last time we talked, we were (or at least I was) unsure whether string literal counts as a composite expression. Do we have clarity on this now?
Based on the literal reading of the script, I still think that literal string should be supported. Also from practicality standpoint, I don't think there's any issue with supporting it.
If you are okay with that approach, I am happy to take on this work next week.
Activity
PerthCharern commentedon Jun 19, 2018
tl;dr;
We will need to modify our RuntimeExpression class to handle cases like:
where there are "expressions" in
{ }in a string.darrelmiller commentedon Jun 26, 2018
I've created a CompositeExpression class that will contain the outer template string and then create child RuntimeExpression objects for the parts inside {}. As we don't actually do the runtime resolution yet, this shouldn't be too difficult to complete.
Added extra test based on issue #287
darrelmiller commentedon Jul 18, 2018
Fixed in v1.1.0-preview.4
Shwetap05 commentedon Aug 16, 2018
Darrel, looks like this issue is still not fixed in 1.1
PerthCharern commentedon Aug 16, 2018
There's a bug in the expression parser. We are checking for
{$to determine if it's a composite expression. If the expression is a simple string like/abcd, then we are not parsing it correctly.darrelmiller commentedon Aug 16, 2018
Yeah. I just fixed it to look for Contains("$")
darrelmiller commentedon Aug 16, 2018
Wait. It's not an issue in the expression parser. It was in the callback deserializer
darrelmiller commentedon Aug 16, 2018
Shweta Patil (@Shwetap05) I have a fix pending for the example that Perth included above. However, it will not handle the case when the callback key does not have any runtime expression. i.e. when it is a string literal. This scenario is not one that is currently supported by the OpenAPI specification. Perhaps it should be, but I will need to bring this up with the Technical Steering Committee to see if we can get the spec updated to add support for this use case.
If the customer could add an issue on the OpenAPI repo that would help me make the case for it.
PerthCharern commentedon Aug 16, 2018
I would argue that even in the current spec version, there's already a bit of an ambiguity in whether the constant
/abcdscenario "is one that is currently supported by the OpenAPI specification."From the spec:
This makes it sound like if we are okay with treating a composite expression as a runtime expression, then we should also be okay with including a literal string as a composite expression too. The word "string values" above do not specify any restrictions on the string.
At the end of the day, it sounds like a string literal is a valid key for the callback - it's just a matter of allowing it in the Callback Object or in the Runtime Expression.
PerthCharern commentedon Sep 21, 2018
Darrel (@darrelmiller) I'm not sure how far you've got.
We have to unblock our customers who brought us composite expressions. Last time we talked, we were (or at least I was) unsure whether string literal counts as a composite expression. Do we have clarity on this now?
Based on the literal reading of the script, I still think that literal string should be supported. Also from practicality standpoint, I don't think there's any issue with supporting it.
If you are okay with that approach, I am happy to take on this work next week.
#287