From b654807b2c25da7c9d2f95bcad0553dae9463fb1 Mon Sep 17 00:00:00 2001 From: mcgallan <88413158+mcgallan@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:37:25 +0800 Subject: [PATCH] [http-spec] Update Versioning/Removed Project And Removed Type/Model/Templated (#5217) Fixed the two issues mentioned in [Issue5216](https://github.com/microsoft/typespec/issues/5216), upgraded the code for Versioning/Removed, and removed the Type/Model/Templated code that has already been reverted in Cadl Ranch. Fix https://github.com/microsoft/typespec/issues/5216 --- ...moved-in-cadl-ranch-2024-10-28-15-49-29.md | 7 + packages/http-specs/spec-summary.md | 114 ++++++--------- .../specs/type/model/templated/main.tsp | 130 ------------------ .../specs/type/model/templated/mockapi.ts | 66 --------- .../specs/versioning/removed/main.tsp | 64 ++++++++- .../specs/versioning/removed/mockapi.ts | 47 +++++++ 6 files changed, 160 insertions(+), 268 deletions(-) create mode 100644 .chronus/changes/synced-with-versioning-removed-in-cadl-ranch-2024-10-28-15-49-29.md delete mode 100644 packages/http-specs/specs/type/model/templated/main.tsp delete mode 100644 packages/http-specs/specs/type/model/templated/mockapi.ts diff --git a/.chronus/changes/synced-with-versioning-removed-in-cadl-ranch-2024-10-28-15-49-29.md b/.chronus/changes/synced-with-versioning-removed-in-cadl-ranch-2024-10-28-15-49-29.md new file mode 100644 index 0000000000..3704e00677 --- /dev/null +++ b/.chronus/changes/synced-with-versioning-removed-in-cadl-ranch-2024-10-28-15-49-29.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-specs" +--- + +update code in versioning/removed and removed type/model/templated. diff --git a/packages/http-specs/spec-summary.md b/packages/http-specs/spec-summary.md index 9fbaa6e661..ff4a3ec4d5 100644 --- a/packages/http-specs/spec-summary.md +++ b/packages/http-specs/spec-summary.md @@ -4360,77 +4360,6 @@ Expected input body: } ``` -### Type_Model_Templated_float32Type - -- Endpoint: `put /type/model/templated/float32ValuesType` - -Expected input body: - -```json -{ - "kind": "Float32Values", - "values": [0.5], - "value": 0.5 -} -``` - -Expected response body: - -```json -{ - "kind": "Float32Values", - "values": [0.5], - "value": 0.5 -} -``` - -### Type_Model_Templated_int32Type - -- Endpoint: `put /type/model/templated/int32ValuesType` - -Expected input body: - -```json -{ - "kind": "Int32Values", - "values": [1234], - "value": 1234 -} -``` - -Expected response body: - -```json -{ - "kind": "Int32Values", - "values": [1234], - "value": 1234 -} -``` - -### Type_Model_Templated_numericType - -- Endpoint: `put /type/model/templated/numericType` - -Expected input body: - -```json -{ - "kind": "Int32Values", - "values": [1234], - "value": 1234 -} -``` - -Expected response body: - -```json -{ - "values": [1234], - "value": 1234 -} -``` - ### Type_Model_Usage_input - Endpoint: `get /type/model/usage/input` @@ -7436,6 +7365,49 @@ Expected request body: { "prop": "foo" } ``` +### Versioning_Removed_modelV3 + +- Endpoint: `post /versioning/removed/api-version:{version}/v3` + +path: "/versioning/removed/api-version[:]v1/v3" +Expected request body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + +Expected response body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + +path: "/versioning/removed/api-version[:]v2preview/v3" +Expected request body: + +```json +{ "id": "123" } +``` + +Expected response body: + +```json +{ "id": "123" } +``` + +path: "/versioning/removed/api-version[:]v2/v3" +Expected request body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + +Expected response body: + +```json +{ "id": "123", "enumProp": "enumMemberV1" } +``` + ### Versioning_Removed_v2 - Endpoint: `post /versioning/removed/api-version:{version}/v2` diff --git a/packages/http-specs/specs/type/model/templated/main.tsp b/packages/http-specs/specs/type/model/templated/main.tsp deleted file mode 100644 index 3d9bc1d92e..0000000000 --- a/packages/http-specs/specs/type/model/templated/main.tsp +++ /dev/null @@ -1,130 +0,0 @@ -import "@typespec/http"; -import "@typespec/spector"; - -using Http; -using Spector; - -/** - * Illustrates the model templated cases. There is a base templated type and an instantiated type extending from it. - */ -@scenarioService("/type/model/templated") -namespace Type.Model.Templated; - -@friendlyName("{name}Type", T) -model NumericType { - /** - * An array of numeric values. - */ - values: T[]; - - value: T; -} - -/** - * An instantiated type representing int32 values type. - */ -model Int32ValuesType extends NumericType { - /** - * The Kind of the Int32ValuesType. - */ - kind: "Int32Values"; -} - -/** - * An instantiated type representing float32 values type. - */ -model Float32ValuesType extends NumericType { - /** - * The Kind of the Float32ValuesType. - */ - kind: "Float32Values"; -} - -@scenario -@scenarioDoc(""" - Expected input body: - ```json - { - "kind": "Int32Values", - "values": - [ - 1234 - ], - "value": 1234 - } - ``` - - Expected response body: - ```json - { - "values": - [ - 1234 - ], - "value": 1234 - } - ``` - """) -@route("/numericType") -@put -op numericType(@body input: NumericType): NumericType; - -@scenario -@scenarioDoc(""" - Expected input body: - ```json - { - "kind": "Float32Values", - "values": - [ - 0.5 - ], - "value": 0.5 - } - ``` - - Expected response body: - ```json - { - "kind": "Float32Values", - "values": - [ - 0.5 - ], - "value": 0.5 - } - ``` - """) -@route("/float32ValuesType") -@put -op float32Type(@body input: Float32ValuesType): Float32ValuesType; - -@scenario -@scenarioDoc(""" - Expected input body: - ```json - { - "kind": "Int32Values", - "values": - [ - 1234 - ], - "value": 1234 - } - ``` - - Expected response body: - ```json - { - "kind": "Int32Values", - "values": - [ - 1234 - ], - "value": 1234 - } - ``` - """) -@route("/int32ValuesType") -@put -op int32Type(@body input: Int32ValuesType): Int32ValuesType; diff --git a/packages/http-specs/specs/type/model/templated/mockapi.ts b/packages/http-specs/specs/type/model/templated/mockapi.ts deleted file mode 100644 index cd69b9bfa8..0000000000 --- a/packages/http-specs/specs/type/model/templated/mockapi.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; - -export const Scenarios: Record = {}; - -Scenarios.Type_Model_Templated_numericType = passOnSuccess({ - uri: "/type/model/templated/numericType", - method: "put", - request: { - body: { - kind: "Int32Values", - values: [1234], - value: 1234, - }, - }, - response: { - status: 200, - body: json({ - kind: "Int32Values", - values: [1234], - value: 1234, - }), - }, - kind: "MockApiDefinition", -}); - -Scenarios.Type_Model_Templated_float32Type = passOnSuccess({ - uri: "/type/model/templated/float32ValuesType", - method: "put", - request: { - body: { - kind: "Float32Values", - values: [0.5], - value: 0.5, - }, - }, - response: { - status: 200, - body: json({ - kind: "Float32Values", - values: [0.5], - value: 0.5, - }), - }, - kind: "MockApiDefinition", -}); - -Scenarios.Type_Model_Templated_int32Type = passOnSuccess({ - uri: "/type/model/templated/int32ValuesType", - method: "put", - request: { - body: { - kind: "Int32Values", - values: [1234], - value: 1234, - }, - }, - response: { - status: 200, - body: json({ - kind: "Int32Values", - values: [1234], - value: 1234, - }), - }, - kind: "MockApiDefinition", -}); diff --git a/packages/http-specs/specs/versioning/removed/main.tsp b/packages/http-specs/specs/versioning/removed/main.tsp index 609df7c6d3..17bb7b0be2 100644 --- a/packages/http-specs/specs/versioning/removed/main.tsp +++ b/packages/http-specs/specs/versioning/removed/main.tsp @@ -21,7 +21,7 @@ using TypeSpec.Versioning; endpoint: url, /** - * Need to be set as 'v1' or 'v2' in client. + * Need to be set as 'v1', 'v2preview' or 'v2' in client. */ version: Versions, } @@ -37,6 +37,11 @@ enum Versions { */ v1: "v1", + /** + * The V2 Preview version. + */ + v2preview: "v2preview", + /** * The version v2. */ @@ -67,6 +72,14 @@ model ModelV2 { unionProp: UnionV2; } +model ModelV3 { + id: string; + + @removed(Versions.v2preview) + @added(Versions.v2) + enumProp: EnumV3; +} + enum EnumV2 { @removed(Versions.v2) enumMemberV1, @@ -74,6 +87,14 @@ enum EnumV2 { enumMemberV2, } +enum EnumV3 { + @removed(Versions.v2preview) + @added(Versions.v2) + enumMemberV1, + + enumMemberV2Preview, +} + @removed(Versions.v2) union UnionV1 { string, @@ -124,3 +145,44 @@ interface InterfaceV1 { @route("/v1") v1InInterface(@body body: ModelV1): ModelV1; } + +/** This operation will pass different paths and different request bodies based on different versions. */ +@scenario +@scenarioDoc(""" + path: "/versioning/removed/api-version[:]v1/v3" + Expected request body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + Expected response body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + path: "/versioning/removed/api-version[:]v2preview/v3" + Expected request body: + ```json + { "id": "123"} + ``` + + Expected response body: + ```json + { "id": "123"} + ``` + + path: "/versioning/removed/api-version[:]v2/v3" + Expected request body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + Expected response body: + ```json + { "id": "123", "enumProp": "enumMemberV1" } + ``` + + """) +@post +@route("/v3") +op modelV3(@body body: ModelV3): ModelV3; diff --git a/packages/http-specs/specs/versioning/removed/mockapi.ts b/packages/http-specs/specs/versioning/removed/mockapi.ts index 7f4e2534cf..c197f161d0 100644 --- a/packages/http-specs/specs/versioning/removed/mockapi.ts +++ b/packages/http-specs/specs/versioning/removed/mockapi.ts @@ -18,3 +18,50 @@ Scenarios.Versioning_Removed_v2 = passOnSuccess({ }, kind: "MockApiDefinition", }); + +Scenarios.Versioning_Removed_modelV3 = passOnSuccess({ + uri: `/versioning/removed/api-version[:]v1/v3`, + method: "post", + request: { + body: { + id: "123", + enumProp: "enumMemberV1", + }, + }, + response: { + status: 200, + body: json({ id: "123", enumProp: "enumMemberV1" }), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Versioning_Removed_modelV3_V2 = passOnSuccess({ + uri: `/versioning/removed/api-version[:]v2/v3`, + method: "post", + request: { + body: { + id: "123", + enumProp: "enumMemberV1", + }, + }, + response: { + status: 200, + body: json({ id: "123", enumProp: "enumMemberV1" }), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Versioning_Removed_modelV3_V2preview = passOnSuccess({ + uri: `/versioning/removed/api-version[:]v2preview/v3`, + method: "post", + request: { + body: { + id: "123", + }, + }, + response: { + status: 200, + body: json({ id: "123" }), + }, + kind: "MockApiDefinition", +});