-
Notifications
You must be signed in to change notification settings - Fork 235
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
Add "constant" to DurationKnownEncoding #5672
Conversation
❌ There is undocummented changes. Run The following packages have changes but are not documented.
Show changes |
You can try these changes here
|
/** | ||
* Encode for duration-constant | ||
*/ | ||
constant: "constant", |
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.
can we get more detail about what this format is, if its not something defined by an rfc it shouldn't be added 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.
In the description of this issue, Azure/typespec-azure#1901, we are converting Compute swagger to TypeSpec. They have defined "x-ms-format": "duration-constant"
, like below:
"maximumDuration": {
"type": "string",
"x-ms-format": "duration-constant"
},
which impacts the deserialization, meaning SDK does different serialization in the payload for this specific property.
In the description of that issue, I have tried two ways to represent it but failed. Therefore, we propose to add a "constant", so that we can do
model Test {
@encode(DurationKnownEncoding.constant)
input: duration;
}
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've no idea whether it is RFC, but we need a solution if we don't add "constant".
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.
X-Ms-format though wasn't an autorest core thing though?
What is the format of serialization where does it come from?
This seems like quite an edge case to consider this level of support
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.
Maybe. Then how about we enable
model Test {
@format("duration-constant")
input: duration;
}
to make it pass compilation.
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.
why not we just simply use
model Test {
@encode("constant") // or duration-constant
input: duration;
}
encode decorator could accept any string as values, and if when you do this, TCGC is not able to handle them properly, this is a bug in TCGC.
We do not really have to introduce such a value into this enum.
And FYI @format
might work fine on swaggers, but the SDK generators now ignore format therefore it will not work for SDKs.
On the other hand, if you could find this format in RFC, we could have it 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.
I updated the description of that issue with trial 3. We need an "x-ms-format": "duration-constant"
, not an "format": "duration-constant"
.
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.
Yeah, @ArcturusZhang is right, encore doesn't require the value to be defined there is is open. You can support whatever additional custom encoding you want without the standard library defining it.
Format is incorrect as you saw for 2 reason it's for format not x-ms-format and it's about giving a known pattern to a string so will never work with anything else
It starts from Azure/typespec-azure#1901. To represent "x-ms-format": "duration-constant", we are expecting something like
What's more, we might need to change in TypeSpec-Azure to emit
"x-ms-format": "duration-constant"
in the swagger.