diff --git a/.chronus/changes/copilot-add-spector-scenario-encode-duration-2025-9-14-14-26-14.md b/.chronus/changes/copilot-add-spector-scenario-encode-duration-2025-9-14-14-26-14.md new file mode 100644 index 00000000000..3d03154d5dc --- /dev/null +++ b/.chronus/changes/copilot-add-spector-scenario-encode-duration-2025-9-14-14-26-14.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/http-specs" +--- + +Add scenario for encode duration with larger units \ No newline at end of file diff --git a/packages/http-specs/spec-summary.md b/packages/http-specs/spec-summary.md index cf8447521e6..5ed1520fc08 100644 --- a/packages/http-specs/spec-summary.md +++ b/packages/http-specs/spec-summary.md @@ -538,6 +538,14 @@ Expected header `duration: 35.625` Test float milliseconds encode for a duration header. Expected header `duration: 35625` +### Encode_Duration_Header_floatMillisecondsLargerUnit + +- Endpoint: `get /encode/duration/header/float-milliseconds-larger-unit` + +Test float milliseconds encode for a duration header where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3.5) in C#. +Expected header `duration: 210000.0` + ### Encode_Duration_Header_floatSeconds - Endpoint: `get /encode/duration/header/float-seconds` @@ -545,6 +553,14 @@ Expected header `duration: 35625` Test float seconds encode for a duration header. Expected header `duration: 35.625` +### Encode_Duration_Header_floatSecondsLargerUnit + +- Endpoint: `get /encode/duration/header/float-seconds-larger-unit` + +Test float seconds encode for a duration header where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2.5) in C#. +Expected header `duration: 150.0` + ### Encode_Duration_Header_int32Milliseconds - Endpoint: `get /encode/duration/header/int32-milliseconds` @@ -559,6 +575,14 @@ Expected header `duration: 36000` Test int32 milliseconds encode for a duration array header. Expected header `duration: [36000,47000]` +### Encode_Duration_Header_int32MillisecondsLargerUnit + +- Endpoint: `get /encode/duration/header/int32-milliseconds-larger-unit` + +Test int32 milliseconds encode for a duration header where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3) in C#. +Expected header `duration: 180000` + ### Encode_Duration_Header_int32Seconds - Endpoint: `get /encode/duration/header/int32-seconds` @@ -566,6 +590,14 @@ Expected header `duration: [36000,47000]` Test int32 seconds encode for a duration header. Expected header `duration: 36` +### Encode_Duration_Header_int32SecondsLargerUnit + +- Endpoint: `get /encode/duration/header/int32-seconds-larger-unit` + +Test int32 seconds encode for a duration header where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2) in C#. +Expected header `duration: 120` + ### Encode_Duration_Header_iso8601 - Endpoint: `get /encode/duration/header/iso8601` @@ -685,6 +717,28 @@ Expected response body: } ``` +### Encode_Duration_Property_floatMillisecondsLargerUnit + +- Endpoint: `get /encode/duration/property/float-milliseconds-larger-unit` + +Test operation with request and response model contains a duration property with float milliseconds encode where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3.5) in C#. +Expected request body: + +```json +{ + "value": 210000.0 +} +``` + +Expected response body: + +```json +{ + "value": 210000.0 +} +``` + ### Encode_Duration_Property_floatSeconds - Endpoint: `get /encode/duration/property/float-seconds` @@ -727,6 +781,28 @@ Expected response body: } ``` +### Encode_Duration_Property_floatSecondsLargerUnit + +- Endpoint: `get /encode/duration/property/float-seconds-larger-unit` + +Test operation with request and response model contains a duration property with float seconds encode where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2.5) in C#. +Expected request body: + +```json +{ + "value": 150.0 +} +``` + +Expected response body: + +```json +{ + "value": 150.0 +} +``` + ### Encode_Duration_Property_int32Milliseconds - Endpoint: `get /encode/duration/property/int32-milliseconds` @@ -748,6 +824,28 @@ Expected response body: } ``` +### Encode_Duration_Property_int32MillisecondsLargerUnit + +- Endpoint: `get /encode/duration/property/int32-milliseconds-larger-unit` + +Test operation with request and response model contains a duration property with int32 milliseconds encode where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3) in C#. +Expected request body: + +```json +{ + "value": 180000 +} +``` + +Expected response body: + +```json +{ + "value": 180000 +} +``` + ### Encode_Duration_Property_int32Seconds - Endpoint: `get /encode/duration/property/int32-seconds` @@ -769,6 +867,28 @@ Expected response body: } ``` +### Encode_Duration_Property_int32SecondsLargerUnit + +- Endpoint: `get /encode/duration/property/int32-seconds-larger-unit` + +Test operation with request and response model contains a duration property with int32 seconds encode where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2) in C#. +Expected request body: + +```json +{ + "value": 120 +} +``` + +Expected response body: + +```json +{ + "value": 120 +} +``` + ### Encode_Duration_Property_iso8601 - Endpoint: `post /encode/duration/property/iso8601` @@ -818,6 +938,14 @@ Expected query parameter `input=35.625` Test float milliseconds encode for a duration parameter. Expected query parameter `input=35625` +### Encode_Duration_Query_floatMillisecondsLargerUnit + +- Endpoint: `get /encode/duration/query/float-milliseconds-larger-unit` + +Test float milliseconds encode for a duration parameter where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3.5) in C#. +Expected query parameter `input=210000.0` + ### Encode_Duration_Query_floatSeconds - Endpoint: `get /encode/duration/query/float-seconds` @@ -825,6 +953,14 @@ Expected query parameter `input=35625` Test float seconds encode for a duration parameter. Expected query parameter `input=35.625` +### Encode_Duration_Query_floatSecondsLargerUnit + +- Endpoint: `get /encode/duration/query/float-seconds-larger-unit` + +Test float seconds encode for a duration parameter where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2.5) in C#. +Expected query parameter `input=150.0` + ### Encode_Duration_Query_int32Milliseconds - Endpoint: `get /encode/duration/query/int32-milliseconds` @@ -839,6 +975,14 @@ Expected query parameter `input=36000` Test int32 milliseconds encode for a duration array parameter. Expected query parameter `input=36000,47000` +### Encode_Duration_Query_int32MillisecondsLargerUnit + +- Endpoint: `get /encode/duration/query/int32-milliseconds-larger-unit` + +Test int32 milliseconds encode for a duration parameter where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3) in C#. +Expected query parameter `input=180000` + ### Encode_Duration_Query_int32Seconds - Endpoint: `get /encode/duration/query/int32-seconds` @@ -853,6 +997,14 @@ Expected query parameter `input=36` Test int32 seconds encode for a duration array parameter. Expected query parameter `input=36,47` +### Encode_Duration_Query_int32SecondsLargerUnit + +- Endpoint: `get /encode/duration/query/int32-seconds-larger-unit` + +Test int32 seconds encode for a duration parameter where the duration is several minutes. +Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2) in C#. +Expected query parameter `input=120` + ### Encode_Duration_Query_iso8601 - Endpoint: `get /encode/duration/query/iso8601` diff --git a/packages/http-specs/specs/encode/duration/main.tsp b/packages/http-specs/specs/encode/duration/main.tsp index ba4d391b96b..cb0cf16aee0 100644 --- a/packages/http-specs/specs/encode/duration/main.tsp +++ b/packages/http-specs/specs/encode/duration/main.tsp @@ -45,6 +45,19 @@ namespace Query { input: duration, ): NoContentResponse; + @route("/int32-seconds-larger-unit") + @scenario + @scenarioDoc(""" + Test int32 seconds encode for a duration parameter where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2) in C#. + Expected query parameter `input=120` + """) + op int32SecondsLargerUnit( + @query + @encode(DurationKnownEncoding.seconds, int32) + input: duration, + ): NoContentResponse; + @route("/float-seconds") @scenario @scenarioDoc(""" @@ -57,6 +70,19 @@ namespace Query { input: duration, ): NoContentResponse; + @route("/float-seconds-larger-unit") + @scenario + @scenarioDoc(""" + Test float seconds encode for a duration parameter where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2.5) in C#. + Expected query parameter `input=150.0` + """) + op floatSecondsLargerUnit( + @query + @encode(DurationKnownEncoding.seconds, float) + input: duration, + ): NoContentResponse; + @route("/float64-seconds") @scenario @scenarioDoc(""" @@ -81,6 +107,19 @@ namespace Query { input: duration, ): NoContentResponse; + @route("/int32-milliseconds-larger-unit") + @scenario + @scenarioDoc(""" + Test int32 milliseconds encode for a duration parameter where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3) in C#. + Expected query parameter `input=180000` + """) + op int32MillisecondsLargerUnit( + @query + @encode(DurationKnownEncoding.milliseconds, int32) + input: duration, + ): NoContentResponse; + @route("/float-milliseconds") @scenario @scenarioDoc(""" @@ -93,6 +132,19 @@ namespace Query { input: duration, ): NoContentResponse; + @route("/float-milliseconds-larger-unit") + @scenario + @scenarioDoc(""" + Test float milliseconds encode for a duration parameter where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3.5) in C#. + Expected query parameter `input=210000.0` + """) + op floatMillisecondsLargerUnit( + @query + @encode(DurationKnownEncoding.milliseconds, float) + input: duration, + ): NoContentResponse; + @route("/float64-milliseconds") @scenario @scenarioDoc(""" @@ -175,6 +227,26 @@ namespace Property { value: duration; } + model Int32SecondsLargerUnitDurationProperty { + @encode(DurationKnownEncoding.seconds, int32) + value: duration; + } + + model FloatSecondsLargerUnitDurationProperty { + @encode(DurationKnownEncoding.seconds, float) + value: duration; + } + + model Int32MillisecondsLargerUnitDurationProperty { + @encode(DurationKnownEncoding.milliseconds, int32) + value: duration; + } + + model FloatMillisecondsLargerUnitDurationProperty { + @encode(DurationKnownEncoding.milliseconds, float) + value: duration; + } + @encode(DurationKnownEncoding.seconds, float32) scalar Float32Duration extends duration; @@ -390,6 +462,94 @@ namespace Property { op floatMillisecondsArray( @body body: FloatMillisecondsDurationArrayProperty, ): FloatMillisecondsDurationArrayProperty; + + @route("/int32-seconds-larger-unit") + @scenario + @scenarioDoc(""" + Test operation with request and response model contains a duration property with int32 seconds encode where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2) in C#. + Expected request body: + ```json + { + "value": 120 + } + ``` + Expected response body: + ```json + { + "value": 120 + } + ``` + """) + op int32SecondsLargerUnit( + @body body: Int32SecondsLargerUnitDurationProperty, + ): Int32SecondsLargerUnitDurationProperty; + + @route("/float-seconds-larger-unit") + @scenario + @scenarioDoc(""" + Test operation with request and response model contains a duration property with float seconds encode where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2.5) in C#. + Expected request body: + ```json + { + "value": 150.0 + } + ``` + Expected response body: + ```json + { + "value": 150.0 + } + ``` + """) + op floatSecondsLargerUnit( + @body body: FloatSecondsLargerUnitDurationProperty, + ): FloatSecondsLargerUnitDurationProperty; + + @route("/int32-milliseconds-larger-unit") + @scenario + @scenarioDoc(""" + Test operation with request and response model contains a duration property with int32 milliseconds encode where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3) in C#. + Expected request body: + ```json + { + "value": 180000 + } + ``` + Expected response body: + ```json + { + "value": 180000 + } + ``` + """) + op int32MillisecondsLargerUnit( + @body body: Int32MillisecondsLargerUnitDurationProperty, + ): Int32MillisecondsLargerUnitDurationProperty; + + @route("/float-milliseconds-larger-unit") + @scenario + @scenarioDoc(""" + Test operation with request and response model contains a duration property with float milliseconds encode where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3.5) in C#. + Expected request body: + ```json + { + "value": 210000.0 + } + ``` + Expected response body: + ```json + { + "value": 210000.0 + } + ``` + """) + op floatMillisecondsLargerUnit( + @body body: FloatMillisecondsLargerUnitDurationProperty, + ): FloatMillisecondsLargerUnitDurationProperty; } @route("/header") @@ -443,6 +603,19 @@ namespace Header { duration: duration, ): NoContentResponse; + @route("/int32-seconds-larger-unit") + @scenario + @scenarioDoc(""" + Test int32 seconds encode for a duration header where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2) in C#. + Expected header `duration: 120` + """) + op int32SecondsLargerUnit( + @header + @encode(DurationKnownEncoding.seconds, int32) + duration: duration, + ): NoContentResponse; + @route("/float-seconds") @scenario @scenarioDoc(""" @@ -455,6 +628,19 @@ namespace Header { duration: duration, ): NoContentResponse; + @route("/float-seconds-larger-unit") + @scenario + @scenarioDoc(""" + Test float seconds encode for a duration header where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2.5) in C#. + Expected header `duration: 150.0` + """) + op floatSecondsLargerUnit( + @header + @encode(DurationKnownEncoding.seconds, float) + duration: duration, + ): NoContentResponse; + @route("/float64-seconds") @scenario @scenarioDoc(""" @@ -479,6 +665,19 @@ namespace Header { duration: duration, ): NoContentResponse; + @route("/int32-milliseconds-larger-unit") + @scenario + @scenarioDoc(""" + Test int32 milliseconds encode for a duration header where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3) in C#. + Expected header `duration: 180000` + """) + op int32MillisecondsLargerUnit( + @header + @encode(DurationKnownEncoding.milliseconds, int32) + duration: duration, + ): NoContentResponse; + @route("/float-milliseconds") @scenario @scenarioDoc(""" @@ -491,6 +690,19 @@ namespace Header { duration: duration, ): NoContentResponse; + @route("/float-milliseconds-larger-unit") + @scenario + @scenarioDoc(""" + Test float milliseconds encode for a duration header where the duration is several minutes. + Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(3.5) in C#. + Expected header `duration: 210000.0` + """) + op floatMillisecondsLargerUnit( + @header + @encode(DurationKnownEncoding.milliseconds, float) + duration: duration, + ): NoContentResponse; + @route("/float64-milliseconds") @scenario @scenarioDoc(""" diff --git a/packages/http-specs/specs/encode/duration/mockapi.ts b/packages/http-specs/specs/encode/duration/mockapi.ts index 0821ea2c79c..157858bc68c 100644 --- a/packages/http-specs/specs/encode/duration/mockapi.ts +++ b/packages/http-specs/specs/encode/duration/mockapi.ts @@ -93,6 +93,34 @@ Scenarios.Encode_Duration_Property_floatMillisecondsArray = createBodyServerTest }, [35625, 46750], ); +Scenarios.Encode_Duration_Property_int32SecondsLargerUnit = createBodyServerTests( + "/encode/duration/property/int32-seconds-larger-unit", + { + value: 120, + }, + 120, +); +Scenarios.Encode_Duration_Property_floatSecondsLargerUnit = createBodyServerTests( + "/encode/duration/property/float-seconds-larger-unit", + { + value: 150.0, + }, + 150.0, +); +Scenarios.Encode_Duration_Property_int32MillisecondsLargerUnit = createBodyServerTests( + "/encode/duration/property/int32-milliseconds-larger-unit", + { + value: 180000, + }, + 180000, +); +Scenarios.Encode_Duration_Property_floatMillisecondsLargerUnit = createBodyServerTests( + "/encode/duration/property/float-milliseconds-larger-unit", + { + value: 210000.0, + }, + 210000.0, +); function createQueryServerTests( uri: string, @@ -191,6 +219,34 @@ Scenarios.Encode_Duration_Query_int32MillisecondsArray = createQueryServerTests( ["36000", "47000"], "csv", ); +Scenarios.Encode_Duration_Query_int32SecondsLargerUnit = createQueryServerTests( + "/encode/duration/query/int32-seconds-larger-unit", + { + input: 120, + }, + "120", +); +Scenarios.Encode_Duration_Query_floatSecondsLargerUnit = createQueryServerTests( + "/encode/duration/query/float-seconds-larger-unit", + { + input: 150.0, + }, + "150.0", +); +Scenarios.Encode_Duration_Query_int32MillisecondsLargerUnit = createQueryServerTests( + "/encode/duration/query/int32-milliseconds-larger-unit", + { + input: 180000, + }, + "180000", +); +Scenarios.Encode_Duration_Query_floatMillisecondsLargerUnit = createQueryServerTests( + "/encode/duration/query/float-milliseconds-larger-unit", + { + input: 210000.0, + }, + "210000.0", +); function createHeaderServerTests(uri: string, headersData: any, value: any) { return passOnSuccess({ @@ -277,3 +333,31 @@ Scenarios.Encode_Duration_Header_int32MillisecondsArray = createHeaderServerTest }, "36000,47000", ); +Scenarios.Encode_Duration_Header_int32SecondsLargerUnit = createHeaderServerTests( + "/encode/duration/header/int32-seconds-larger-unit", + { + duration: "120", + }, + "120", +); +Scenarios.Encode_Duration_Header_floatSecondsLargerUnit = createHeaderServerTests( + "/encode/duration/header/float-seconds-larger-unit", + { + duration: "150.0", + }, + "150.0", +); +Scenarios.Encode_Duration_Header_int32MillisecondsLargerUnit = createHeaderServerTests( + "/encode/duration/header/int32-milliseconds-larger-unit", + { + duration: "180000", + }, + "180000", +); +Scenarios.Encode_Duration_Header_floatMillisecondsLargerUnit = createHeaderServerTests( + "/encode/duration/header/float-milliseconds-larger-unit", + { + duration: "210000.0", + }, + "210000.0", +);