Skip to content
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 a linter enforcing numeric durations #2265

Open
4 tasks done
tg-msft opened this issue Feb 26, 2025 · 1 comment
Open
4 tasks done

Add a linter enforcing numeric durations #2265

tg-msft opened this issue Feb 26, 2025 · 1 comment
Labels
feature New feature or request lib:azure-core Issues for @azure-tools/typespec-azure-core library
Milestone

Comments

@tg-msft
Copy link
Member

tg-msft commented Feb 26, 2025

Clear and concise description of the problem

duration defaults to a string on the wire, but Azure prohibits ISO8601 durations outside of recurrences. We should have a linting rule that validates anyone using duration is also specifying @encode(DurationKnownEncoding.seconds) for any of the numeric duration types.

Checklist

  • Follow our Code of Conduct
  • Check that this issue is about the Azure libraries for typespec. For feature request in the typespec language or core libraries file it in the TypeSpec repo
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@markcowl markcowl added lib:azure-core Issues for @azure-tools/typespec-azure-core library feature New feature or request labels Feb 26, 2025
@markcowl markcowl added this to the Backlog milestone Feb 26, 2025
@witemple-msft
Copy link
Member

Something that's been bothering me a little bit lately about this is that it seems like the space of values that can exist in a duration changes depending on what the encoding is. If I have a duration of one week (P1W), then I can't actually encode it to an amount of time unless I have a reference instant and a time zone. It's fine as long as your duration value doesn't contain any units of weeks, months, or years, but that we support ISO8601 implies that it can (that also makes it challenging to represent a duration correctly unless you have some type that has the exact semantics of an ISO8601 Duration).

It makes sense that in Azure we would want to use duration for intervals only and numbers for fixed lengths of time, but I have to wonder if it doesn't make more sense to just have the type of the property be an integer and forget about trying to encode through duration if what we're trying to express is always a fixed length of time and not a duration in the strict ISO sense.

CC @bterlson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request lib:azure-core Issues for @azure-tools/typespec-azure-core library
Projects
None yet
Development

No branches or pull requests

3 participants