Azure / Azure/typespec-azure

[typespec-ts] Lossy duration values are not converted to their integer wire encoding

Open
#5,297 0 comments 0 reactions 0 assignees View on GitHub
emitter:typescript
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

## Description

For durations whose public value contains more precision than an integer wire encoding can represent, the generated TypeScript client sends the original fractional value. The target wire types are integer seconds or milliseconds, so the Spector service rejects the request.

## Spector service

- Spec: https://github.com/microsoft/typespec/tree/main/packages/http-specs/specs/encode/duration
- Scenarios:
- `Encode_Duration_Lossy_intSeconds`
- `Encode_Duration_Lossy_intMilliseconds`

## Reproduction

```ts
const client = new DurationClient({
endpoint: "http://localhost:3002",
allowInsecureConnection: true,
});

await client.lossy.intSeconds(36.25);
await client.lossy.intMilliseconds(36250.25);
```

## Actual behavior

```text
Expected query param input to be serialized as an integer but got 36.25
GET /encode/duration/lossy/int32-seconds?input=36.25
```

```text
Expected query param input to be serialized as an integer but got 36250.25
GET /encode/duration/lossy/int32-milliseconds?input=36250.25
```

The generated query serializer performs the duration unit conversion but does not apply the integer wire-type conversion afterward. Fractional public values therefore remain fractional in an `int32`-encoded query parameter.

## Expected behavior

The generated serializer should convert lossy duration values to an integer before placing them on the wire. The Spector scenarios accept floor, round, or ceil, so this issue does not require a specific rounding policy; it only requires a valid integer representation.

Contributor guide

Open the contributing guide

Research direction

Start with the generated query serializer used by the lossy duration client methods, focusing on the intSeconds and intMilliseconds entry points. Run the Spector scenarios Encode_Duration_Lossy_intSeconds and Encode_Duration_Lossy_intMilliseconds; done means fractional public values are sent as valid integer wire values accepted by the service.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.