From caa22906ae9f9dc3031384b7a6b90857a52fbd15 Mon Sep 17 00:00:00 2001 From: Sarangan Rajamanickam Date: Thu, 17 Oct 2024 22:34:06 -0700 Subject: [PATCH] [@azure-tools/cadl-ranch-specs] - Handle PassOnCode, Remove Handler & Remove commonapi.ts file (#755) * Initial Commit * Remove unused commonapi file * Remove handler code * Added Changeset * Fix generated handler for handling params vs query params * Add Handler to Traits * Modify expectedUpdateBody in json-merge-patch * Add body to encode bytes * Added XML Condition check in app.ts * One more change for json-merge-patch * Add code to check for body object * nit * xml request body fix * Add handler for xml case * Remove xml(data) * Modify spec summary --------- Co-authored-by: tadelesh --- .changeset/poor-deers-happen.md | 6 + .../cadl-ranch-specs/cadl-ranch-summary.md | 12 +- .../http/authentication/api-key/mockapi.ts | 14 +- .../http/authentication/commonapi.ts | 43 --- .../authentication/http/custom/mockapi.ts | 14 +- .../http/authentication/oauth2/mockapi.ts | 14 +- .../http/authentication/union/mockapi.ts | 10 +- .../client-generator-core/access/main.tsp | 22 +- .../client-generator-core/access/mockapi.ts | 29 +- .../flatten-property/mockapi.ts | 9 +- .../client-generator-core/usage/main.tsp | 6 +- .../client-generator-core/usage/mockapi.ts | 19 +- .../http/azure/core/basic/mockapi.ts | 65 +--- .../http/azure/core/lro/standard/mockapi.ts | 3 - .../http/azure/core/model/mockapi.ts | 14 - .../http/azure/core/page/mockapi.ts | 37 +-- .../http/azure/core/scalar/mockapi.ts | 24 +- .../http/azure/core/traits/mockapi.ts | 2 +- .../http/azure/example/basic/mockapi.ts | 26 +- .../common-properties/mockapi.ts | 64 +--- .../resource-manager/resources/mockapi.ts | 284 +----------------- .../http/client/naming/mockapi.ts | 69 +---- .../http/client/structure/common/service.ts | 5 +- .../http/encode/bytes/mockapi.ts | 16 +- .../http/encode/duration/mockapi.ts | 13 - .../http/encode/numeric/mockapi.ts | 9 +- .../http/parameters/basic/mockapi.ts | 6 +- .../parameters/body-optionality/mockapi.ts | 8 - .../parameters/collection-format/mockapi.ts | 30 -- .../http/parameters/spread/mockapi.ts | 53 +--- .../http/payload/json-merge-patch/mockapi.ts | 55 +--- .../http/payload/media-type/mockapi.ts | 27 +- .../http/payload/xml/mockapi.ts | 14 +- .../http/resiliency/srv-driven/mockapi.ts | 64 ---- .../encoded-name/json/mockapi.ts | 14 +- .../server/endpoint/not-defined/mockapi.ts | 5 +- .../http/server/path/multiple/mockapi.ts | 8 +- .../http/server/path/single/mockapi.ts | 5 +- .../server/versions/not-versioned/mockapi.ts | 4 - .../http/server/versions/versioned/mockapi.ts | 4 - .../conditional-request/mockapi.ts | 26 +- .../http/special-words/mockapi.ts | 25 +- .../http/type/array/mockapi.ts | 14 +- .../http/type/dictionary/mockapi.ts | 14 +- .../http/type/enum/extensible/mockapi.ts | 9 +- .../http/type/enum/fixed/mockapi.ts | 15 +- .../http/type/model/empty/mockapi.ts | 13 +- .../inheritance/enum-discriminator/mockapi.ts | 12 +- .../nested-discriminator/mockapi.ts | 22 +- .../inheritance/not-discriminated/mockapi.ts | 12 +- .../model/inheritance/recursive/mockapi.ts | 9 +- .../single-discriminator/mockapi.ts | 25 +- .../http/type/model/usage/mockapi.ts | 13 +- .../http/type/model/visibility/mockapi.ts | 33 +- .../property/additional-properties/mockapi.ts | 15 +- .../http/type/property/nullable/mockapi.ts | 17 +- .../http/type/property/optionality/mockapi.ts | 14 +- .../http/type/property/value-types/mockapi.ts | 47 +-- .../http/type/scalar/mockapi.ts | 83 +---- .../http/type/union/mockapi.ts | 9 +- .../http/versioning/added/mockapi.ts | 24 +- .../http/versioning/madeOptional/mockapi.ts | 9 +- .../http/versioning/removed/mockapi.ts | 9 +- .../http/versioning/renamedFrom/mockapi.ts | 17 +- .../returnTypeChangedFrom/mockapi.ts | 9 +- .../versioning/typeChangedFrom/mockapi.ts | 10 +- packages/cadl-ranch/src/app/app.ts | 68 ++++- 67 files changed, 176 insertions(+), 1523 deletions(-) create mode 100644 .changeset/poor-deers-happen.md delete mode 100644 packages/cadl-ranch-specs/http/authentication/commonapi.ts diff --git a/.changeset/poor-deers-happen.md b/.changeset/poor-deers-happen.md new file mode 100644 index 000000000..6f9764737 --- /dev/null +++ b/.changeset/poor-deers-happen.md @@ -0,0 +1,6 @@ +--- +"@azure-tools/cadl-ranch-specs": minor +"@azure-tools/cadl-ranch": minor +--- + +Remove handler code and commonapi file diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index 6e479e2c8..d613aa830 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -79,12 +79,12 @@ Expects header 'authorization': 'Bearer https://security.microsoft.com/.default' - `get /azure/client-generator-core/access/internalOperation/publicDecoratorInInternal` This scenario contains internal operations. All should be generated but not exposed. -Expected query parameter: name= +Expected query parameter: name= "sample" Expected response body: ```json { - "name": + "name": "sample" } ``` @@ -95,12 +95,12 @@ Expected response body: - `get /azure/client-generator-core/access/publicOperation/publicDecoratorInPublic` This scenario contains public operations. It should be generated and exported. -Expected query parameter: name= +Expected query parameter: name="sample" Expected response body: ```json { - "name": + "name": "sample" } ``` @@ -119,12 +119,12 @@ This scenario contains internal operations. All should be generated but not expo - `get /azure/client-generator-core/access/sharedModelInOperation/internal` This scenario contains two operations, one public, another internal. The public one should be generated and exported while the internal one should be generated but not exposed. -Expected query parameter: name= +Expected query parameter: name= "sample" Expected response body: ```json { - "name": + "name": "sample" } ``` diff --git a/packages/cadl-ranch-specs/http/authentication/api-key/mockapi.ts b/packages/cadl-ranch-specs/http/authentication/api-key/mockapi.ts index 78a254f69..ec7d4344b 100644 --- a/packages/cadl-ranch-specs/http/authentication/api-key/mockapi.ts +++ b/packages/cadl-ranch-specs/http/authentication/api-key/mockapi.ts @@ -1,4 +1,4 @@ -import { json, MockRequest, passOnCode, passOnSuccess } from "@azure-tools/cadl-ranch-api"; +import { json, passOnCode, passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,10 +14,6 @@ Scenarios.Authentication_ApiKey_valid = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("x-ms-api-key", "valid-key"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -36,13 +32,5 @@ Scenarios.Authentication_ApiKey_invalid = passOnCode(403, { error: "invalid-api-key", }), }, - handler: (req: MockRequest) => { - return { - status: 403, - body: json({ - error: "invalid-api-key", - }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/authentication/commonapi.ts b/packages/cadl-ranch-specs/http/authentication/commonapi.ts deleted file mode 100644 index 018cf7b4b..000000000 --- a/packages/cadl-ranch-specs/http/authentication/commonapi.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { - passOnSuccess, - passOnCode, - mockapi, - json, - PassOnSuccessScenario, - PassOnCodeScenario, - MockRequest, -} from "@azure-tools/cadl-ranch-api"; -import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; - -export const Scenarios: Record = {}; - -interface ValidAndInvalidCodeScenarios { - valid: PassOnSuccessScenario; - invalid: PassOnCodeScenario; -} - -export function getValidAndInvalidScenarios( - scenarioFolder: string, - errorCode: string, - authenticationValidation: (req: MockRequest) => void, -): ValidAndInvalidCodeScenarios { - return { - valid: passOnSuccess( - mockapi.get(`/authentication/${scenarioFolder}/valid`, (req) => { - authenticationValidation(req); - return { status: 204 }; - }), - ), - invalid: passOnCode( - 403, - mockapi.get(`/authentication/${scenarioFolder}/invalid`, (req) => { - return { - status: 403, - body: json({ - error: errorCode, - }), - }; - }), - ), - }; -} diff --git a/packages/cadl-ranch-specs/http/authentication/http/custom/mockapi.ts b/packages/cadl-ranch-specs/http/authentication/http/custom/mockapi.ts index a90b7122b..22ca12bde 100644 --- a/packages/cadl-ranch-specs/http/authentication/http/custom/mockapi.ts +++ b/packages/cadl-ranch-specs/http/authentication/http/custom/mockapi.ts @@ -1,4 +1,4 @@ -import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api"; +import { json, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,10 +14,6 @@ Scenarios.Authentication_Http_Custom_valid = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("authorization", "SharedAccessKey valid-key"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -36,13 +32,5 @@ Scenarios.Authentication_Http_Custom_invalid = passOnCode(403, { error: "invalid-api-key", }), }, - handler: (req: MockRequest) => { - return { - status: 403, - body: json({ - error: "invalid-api-key", - }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/authentication/oauth2/mockapi.ts b/packages/cadl-ranch-specs/http/authentication/oauth2/mockapi.ts index f9a86d2d6..f37a9901d 100644 --- a/packages/cadl-ranch-specs/http/authentication/oauth2/mockapi.ts +++ b/packages/cadl-ranch-specs/http/authentication/oauth2/mockapi.ts @@ -1,4 +1,4 @@ -import { json, MockRequest, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api"; +import { json, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,10 +14,6 @@ Scenarios.Authentication_OAuth2_valid = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("authorization", "Bearer https://security.microsoft.com/.default"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -33,13 +29,5 @@ Scenarios.Authentication_OAuth2_invalid = passOnCode(403, { error: "invalid-grant", }), }, - handler: (req: MockRequest) => { - return { - status: 403, - body: json({ - error: "invalid-grant", - }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/authentication/union/mockapi.ts b/packages/cadl-ranch-specs/http/authentication/union/mockapi.ts index 48a62f661..885086c0b 100644 --- a/packages/cadl-ranch-specs/http/authentication/union/mockapi.ts +++ b/packages/cadl-ranch-specs/http/authentication/union/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,10 +14,6 @@ Scenarios.Authentication_Union_validKey = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("x-ms-api-key", "valid-key"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -32,9 +28,5 @@ Scenarios.Authentication_Union_validToken = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("authorization", "Bearer https://security.microsoft.com/.default"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/access/main.tsp b/packages/cadl-ranch-specs/http/azure/client-generator-core/access/main.tsp index bd0b5d922..6f7e390da 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/access/main.tsp +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/access/main.tsp @@ -15,11 +15,11 @@ namespace _Specs_.Azure.ClientGenerator.Core.Access; @scenario @scenarioDoc(""" This scenario contains public operations. It should be generated and exported. - Expected query parameter: name= + Expected query parameter: name="sample" Expected response body: ```json { - "name": + "name": "sample" } ``` """) @@ -51,11 +51,11 @@ namespace PublicOperation { @scenario @scenarioDoc(""" This scenario contains internal operations. All should be generated but not exposed. - Expected query parameter: name= + Expected query parameter: name= "sample" Expected response body: ```json { - "name": + "name": "sample" } ``` """) @@ -98,11 +98,11 @@ namespace InternalOperation { @scenario @scenarioDoc(""" This scenario contains two operations, one public, another internal. The public one should be generated and exported while the internal one should be generated but not exposed. - Expected query parameter: name= + Expected query parameter: name= "sample" Expected response body: ```json { - "name": + "name": "sample" } ``` """) @@ -157,14 +157,14 @@ namespace RelativeModelInOperation { } @doc(""" - Expected query parameter: name= + Expected query parameter: name="Madge" Expected response body: ```json { - "name": , + "name": "Madge", "inner": { - "name": + "name": "Madge" } } ``` @@ -175,11 +175,11 @@ namespace RelativeModelInOperation { op operation(@query name: string): OuterModel; @doc(""" - Expected query parameter: kind= + Expected query parameter: kind= "real" Expected response body: ```json { - "name": , + "name": "Madge", "kind": "real" } ``` diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/access/mockapi.ts b/packages/cadl-ranch-specs/http/azure/client-generator-core/access/mockapi.ts index 41feac784..51d507ec7 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/access/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/access/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ValidationError, json, MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json, MockApiDefinition } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -16,15 +16,6 @@ function createMockApiDefinitions(route: string): MockApiDefinition { status: 200, body: json({ name: "sample" }), }, - handler: (req: MockRequest) => { - if (!("name" in req.query)) { - throw new ValidationError("Should submit name query", "any string", undefined); - } - return { - status: 200, - body: json({ name: req.query["name"] }), - }; - }, kind: "MockApiDefinition", }; } @@ -58,15 +49,6 @@ Scenarios.Azure_ClientGenerator_Core_Access_RelativeModelInOperation = passOnSuc status: 200, body: json({ name: "Madge", inner: { name: "Madge" } }), }, - handler: (req: MockRequest) => { - if (!("name" in req.query)) { - throw new ValidationError("Should submit name query", "any string", undefined); - } - return { - status: 200, - body: json({ name: "Madge", inner: { name: "Madge" } }), - }; - }, kind: "MockApiDefinition", }, { @@ -81,15 +63,6 @@ Scenarios.Azure_ClientGenerator_Core_Access_RelativeModelInOperation = passOnSuc status: 200, body: json({ name: "Madge", kind: "real" }), }, - handler: (req: MockRequest) => { - if (!("kind" in req.query)) { - throw new ValidationError("Should submit name query", "any string", undefined); - } - return { - status: 200, - body: json({ name: "Madge", kind: "real" }), - }; - }, kind: "MockApiDefinition", }, ]); diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/flatten-property/mockapi.ts b/packages/cadl-ranch-specs/http/azure/client-generator-core/flatten-property/mockapi.ts index 5991341e7..7a2d08ab1 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/flatten-property/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/flatten-property/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json, MockApiDefinition } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -13,13 +13,6 @@ function createMockApiDefinitions(route: string, request: any, response: any): M status: 200, body: json(response), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(request); - return { - status: 200, - body: json(response), - }; - }, kind: "MockApiDefinition", }; } diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/main.tsp b/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/main.tsp index ac50a7ae0..c203d0b05 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/main.tsp +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/main.tsp @@ -28,7 +28,7 @@ namespace ModelInOperation { Expected body parameter: ```json { - "name": + "name": "Madge" } ``` """) @@ -48,7 +48,7 @@ namespace ModelInOperation { Expected response body: ```json { - "name": + "name": "Madge" } ``` """) @@ -78,7 +78,7 @@ namespace ModelInOperation { ```json { "result": { - "name": + "name": "Madge" } } ``` diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/mockapi.ts b/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/mockapi.ts index 2c07c89f0..b25d073b2 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/usage/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -15,11 +15,6 @@ Scenarios.Azure_ClientGenerator_Core_Usage_ModelInOperation = passOnSuccess([ response: { status: 204, }, - handler: (req: MockRequest) => { - const validBody = { name: "Madge" }; - req.expect.bodyEquals(validBody); - return { status: 204 }; - }, kind: "MockApiDefinition", }, { @@ -30,12 +25,6 @@ Scenarios.Azure_ClientGenerator_Core_Usage_ModelInOperation = passOnSuccess([ status: 200, body: json({ name: "Madge" }), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json({ name: "Madge" }), - }; - }, kind: "MockApiDefinition", }, { @@ -46,12 +35,6 @@ Scenarios.Azure_ClientGenerator_Core_Usage_ModelInOperation = passOnSuccess([ status: 200, body: json({ result: { name: "Madge" } }), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json({ result: { name: "Madge" } }), - }; - }, kind: "MockApiDefinition", }, ]); diff --git a/packages/cadl-ranch-specs/http/azure/core/basic/mockapi.ts b/packages/cadl-ranch-specs/http/azure/core/basic/mockapi.ts index 984bf92b4..21f9c92df 100644 --- a/packages/cadl-ranch-specs/http/azure/core/basic/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/core/basic/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, ValidationError, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -18,16 +18,6 @@ Scenarios.Azure_Core_Basic_createOrUpdate = passOnSuccess({ body: { name: "Madge" }, }, response: { status: 200, body: json(validUser) }, - handler: (req: MockRequest) => { - if (req.params.id !== "1") { - throw new ValidationError("Expected path param id=1", "1", req.params.id); - } - req.expect.containsHeader("content-type", "application/merge-patch+json"); - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - const validBody = { name: "Madge" }; - req.expect.bodyEquals(validBody); - return { status: 200, body: json(validUser) }; - }, kind: "MockApiDefinition", }); @@ -42,16 +32,6 @@ Scenarios.Azure_Core_Basic_createOrReplace = passOnSuccess({ body: { name: "Madge" }, }, response: { status: 200, body: json(validUser) }, - handler: (req: MockRequest) => { - if (req.params.id !== "1") { - throw new ValidationError("Expected path param id=1", "1", req.params.id); - } - req.expect.containsHeader("content-type", "application/json"); - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - const validBody = { name: "Madge" }; - req.expect.bodyEquals(validBody); - return { status: 200, body: json(validUser) }; - }, kind: "MockApiDefinition", }); @@ -65,13 +45,6 @@ Scenarios.Azure_Core_Basic_get = passOnSuccess({ }, }, response: { status: 200, body: json(validUser) }, - handler: (req: MockRequest) => { - if (req.params.id !== "1") { - throw new ValidationError("Expected path param id=1", "1", req.params.id); - } - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - return { status: 200, body: json(validUser) }; - }, kind: "MockApiDefinition", }); const responseBody = { @@ -105,22 +78,6 @@ Scenarios.Azure_Core_Basic_list = passOnSuccess({ }, }, response: { status: 200, body: json(responseBody) }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - req.expect.containsQueryParam("top", "5"); - req.expect.containsQueryParam("skip", "10"); - req.expect.containsQueryParam("orderby", "id"); - req.expect.containsQueryParam("filter", "id lt 10"); - if (!req.originalRequest.originalUrl.includes("select=id&select=orders&select=etag")) { - throw new ValidationError( - "Expected query param select=id&select=orders&select=etag ", - "select=id&select=orders&select=etag", - req.originalRequest.originalUrl, - ); - } - req.expect.containsQueryParam("expand", "orders"); - return { status: 200, body: json(responseBody) }; - }, kind: "MockApiDefinition", }); @@ -136,13 +93,6 @@ Scenarios.Azure_Core_Basic_delete = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - if (req.params.id !== "1") { - throw new ValidationError("Expected path param id=1", "1", req.params.id); - } - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -160,14 +110,6 @@ Scenarios.Azure_Core_Basic_export = passOnSuccess({ status: 200, body: json(validUser), }, - handler: (req: MockRequest) => { - if (req.params.id !== "1") { - throw new ValidationError("Expected path param id=1", "1", req.params.id); - } - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - req.expect.containsQueryParam("format", "json"); - return { status: 200, body: json(validUser) }; - }, kind: "MockApiDefinition", }); @@ -182,10 +124,5 @@ Scenarios.Azure_Core_Basic_exportAllUsers = passOnSuccess({ }, }, response: { status: 200, body: json(expectBody) }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - req.expect.containsQueryParam("format", "json"); - return { status: 200, body: json(expectBody) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/azure/core/lro/standard/mockapi.ts b/packages/cadl-ranch-specs/http/azure/core/lro/standard/mockapi.ts index a379b7820..792256dc4 100644 --- a/packages/cadl-ranch-specs/http/azure/core/lro/standard/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/core/lro/standard/mockapi.ts @@ -105,9 +105,6 @@ Scenarios.Azure_Core_Lro_Standard_createOrReplace = passOnSuccess([ status: 200, body: json(validUser), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(validUser) }; - }, kind: "MockApiDefinition", }, ]); diff --git a/packages/cadl-ranch-specs/http/azure/core/model/mockapi.ts b/packages/cadl-ranch-specs/http/azure/core/model/mockapi.ts index 47b121823..b4f14a72e 100644 --- a/packages/cadl-ranch-specs/http/azure/core/model/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/core/model/mockapi.ts @@ -8,9 +8,6 @@ Scenarios.Azure_Core_Model_AzureCoreEmbeddingVector_get = passOnSuccess({ method: "get", request: {}, response: { status: 200, body: json([0, 1, 2, 3, 4]) }, - handler: (req) => { - return { status: 200, body: json([0, 1, 2, 3, 4]) }; - }, kind: "MockApiDefinition", }); @@ -21,10 +18,6 @@ Scenarios.Azure_Core_Model_AzureCoreEmbeddingVector_put = passOnSuccess({ body: [0, 1, 2, 3, 4], }, response: { status: 204 }, - handler: (req) => { - req.expect.bodyEquals([0, 1, 2, 3, 4]); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -34,12 +27,5 @@ Scenarios.Azure_Core_Model_AzureCoreEmbeddingVector_post = passOnSuccess({ method: "post", request: { body: { embedding: [0, 1, 2, 3, 4] } }, response: { status: 200, body: json(responseBody) }, - handler: (req) => { - req.expect.bodyEquals({ embedding: [0, 1, 2, 3, 4] }); - return { - status: 200, - body: json(responseBody), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/azure/core/page/mockapi.ts b/packages/cadl-ranch-specs/http/azure/core/page/mockapi.ts index 18883d2a9..a0d66e307 100644 --- a/packages/cadl-ranch-specs/http/azure/core/page/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/core/page/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -9,12 +9,6 @@ Scenarios.Azure_Core_Page_listWithPage = passOnSuccess({ method: "get", request: {}, response: { status: 200, body: json({ value: [validUser] }) }, - handler: (req: MockRequest) => { - const responseBody = { - value: [validUser], - }; - return { status: 200, body: json(responseBody) }; - }, kind: "MockApiDefinition", }); @@ -28,17 +22,6 @@ Scenarios.Azure_Core_Page_listWithParameters = passOnSuccess({ body: { inputName: "Madge" }, }, response: { status: 200, body: json({ value: [validUser] }) }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("another", "Second"); - - const validBody = { inputName: "Madge" }; - req.expect.bodyEquals(validBody); - - const responseBody = { - value: [validUser], - }; - return { status: 200, body: json(responseBody) }; - }, kind: "MockApiDefinition", }); @@ -48,12 +31,6 @@ Scenarios.Azure_Core_Page_TwoModelsAsPageItem = passOnSuccess([ method: "get", request: {}, response: { status: 200, body: json({ value: [{ id: 1 }] }) }, - handler: (req: MockRequest) => { - const responseBody = { - value: [{ id: 1 }], - }; - return { status: 200, body: json(responseBody) }; - }, kind: "MockApiDefinition", }, { @@ -61,12 +38,6 @@ Scenarios.Azure_Core_Page_TwoModelsAsPageItem = passOnSuccess([ method: "get", request: {}, response: { status: 200, body: json({ value: [{ name: "Madge" }] }) }, - handler: (req: MockRequest) => { - const responseBody = { - value: [{ name: "Madge" }], - }; - return { status: 200, body: json(responseBody) }; - }, kind: "MockApiDefinition", }, ]); @@ -76,11 +47,5 @@ Scenarios.Azure_Core_Page_listWithCustomPageModel = passOnSuccess({ method: "get", request: {}, response: { status: 200, body: json({ items: [validUser] }) }, - handler: (req: MockRequest) => { - const responseBody = { - items: [validUser], - }; - return { status: 200, body: json(responseBody) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/azure/core/scalar/mockapi.ts b/packages/cadl-ranch-specs/http/azure/core/scalar/mockapi.ts index a7a265cb7..3fba19942 100644 --- a/packages/cadl-ranch-specs/http/azure/core/scalar/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/core/scalar/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -9,9 +9,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_get = passOnSuccess({ method: "get", request: {}, response: { status: 200, body: json("eastus") }, - handler: (req: MockRequest) => { - return { status: 200, body: json("eastus") }; - }, kind: "MockApiDefinition", }); @@ -25,10 +22,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_put = passOnSuccess({ }, }, response: { status: 204 }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("eastus"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -38,13 +31,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_post = passOnSuccess({ method: "post", request: { body: azureLocation }, response: { status: 200, body: json(azureLocation) }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ location: "eastus" }); - return { - status: 200, - body: json(azureLocation), - }; - }, kind: "MockApiDefinition", }); @@ -57,10 +43,6 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_header = passOnSuccess({ }, }, response: { status: 204 }, - handler: (req: MockRequest) => { - req.expect.containsHeader("region", "eastus"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -73,9 +55,5 @@ Scenarios.Azure_Core_Scalar_AzureLocationScalar_query = passOnSuccess({ }, }, response: { status: 204 }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("region", "eastus"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/azure/core/traits/mockapi.ts b/packages/cadl-ranch-specs/http/azure/core/traits/mockapi.ts index acd888910..9dc8f95a1 100644 --- a/packages/cadl-ranch-specs/http/azure/core/traits/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/core/traits/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, ValidationError, validateValueFormat, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json, validateValueFormat, ValidationError, MockRequest } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; diff --git a/packages/cadl-ranch-specs/http/azure/example/basic/mockapi.ts b/packages/cadl-ranch-specs/http/azure/example/basic/mockapi.ts index bcfc69538..a0e5cf3db 100644 --- a/packages/cadl-ranch-specs/http/azure/example/basic/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/example/basic/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -33,29 +33,5 @@ Scenarios.Client_AzureExampleClient_basicAction = passOnSuccess({ stringProperty: "text", }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2022-12-01-preview"); - req.expect.containsQueryParam("query-param", "query"); - req.expect.containsHeader("header-param", "header"); - const validBody = { - stringProperty: "text", - modelProperty: { - int32Property: 1, - float32Property: 1.5, - enumProperty: "EnumValue1", - }, - arrayProperty: ["item"], - recordProperty: { - record: "value", - }, - }; - req.expect.bodyEquals(validBody); - return { - status: 200, - body: json({ - stringProperty: "text", - }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/azure/resource-manager/common-properties/mockapi.ts b/packages/cadl-ranch-specs/http/azure/resource-manager/common-properties/mockapi.ts index 6b1f18e7a..90f87066b 100644 --- a/packages/cadl-ranch-specs/http/azure/resource-manager/common-properties/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/resource-manager/common-properties/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, ValidationError, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -78,26 +78,6 @@ Scenarios.Azure_ResourceManager_CommonProperties_ManagedIdentity_get = passOnSuc status: 200, body: json(validSystemAssignedManagedIdentityResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.managedIdentityResourceName.toLowerCase() !== "identity") { - throw new ValidationError( - "Unexpected managed identity resource name", - "identity", - req.params.managedIdentityResourceName, - ); - } - return { - status: 200, - body: json(validSystemAssignedManagedIdentityResource), - }; - }, kind: "MockApiDefinition", }); @@ -119,27 +99,6 @@ Scenarios.Azure_ResourceManager_CommonProperties_ManagedIdentity_createWithSyste status: 200, body: json(validSystemAssignedManagedIdentityResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.managedIdentityResourceName.toLowerCase() !== "identity") { - throw new ValidationError( - "Unexpected managed identity resource name", - "identity", - req.params.managedIdentityResourceName, - ); - } - req.expect.deepEqual(req.body["identity"], createExpectedIdentity); - return { - status: 200, - body: json(validSystemAssignedManagedIdentityResource), - }; - }, kind: "MockApiDefinition", }); @@ -165,26 +124,5 @@ Scenarios.Azure_ResourceManager_CommonProperties_ManagedIdentity_updateWithUserA status: 200, body: json(validUserAssignedAndSystemAssignedManagedIdentityResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.managedIdentityResourceName.toLowerCase() !== "identity") { - throw new ValidationError( - "Unexpected managed identity resource name", - "identity", - req.params.managedIdentityResourceName, - ); - } - req.expect.deepEqual(req.body["identity"], updateExpectedIdentity); - return { - status: 200, - body: json(validUserAssignedAndSystemAssignedManagedIdentityResource), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/azure/resource-manager/resources/mockapi.ts b/packages/cadl-ranch-specs/http/azure/resource-manager/resources/mockapi.ts index b7ebb2cff..841be820d 100644 --- a/packages/cadl-ranch-specs/http/azure/resource-manager/resources/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/resource-manager/resources/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, ValidationError, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -76,19 +76,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_getByResourceGroup = passOnS status: 200, body: json(validSingletonResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - return { - status: 200, - body: json(validSingletonResource), - }; - }, kind: "MockApiDefinition", }); @@ -112,25 +99,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_createOrUpdate = passOnSucce status: 200, body: json(validSingletonResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - req.expect.bodyEquals({ - location: "eastus", - properties: { - description: "valid", - }, - }); - return { - status: 200, - body: json(validSingletonResource), - }; - }, kind: "MockApiDefinition", }); @@ -164,28 +132,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_update = passOnSuccess({ }, }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - req.expect.bodyEquals({ - location: "eastus2", - properties: { - description: "valid2", - }, - }); - const resource = JSON.parse(JSON.stringify(validSingletonResource)); - resource.location = "eastus2"; - resource.properties.description = "valid2"; - return { - status: 200, - body: json(resource), - }; - }, kind: "MockApiDefinition", }); @@ -205,21 +151,6 @@ Scenarios.Azure_ResourceManager_Resources_Singleton_listByResourceGroup = passOn value: [validSingletonResource], }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - return { - status: 200, - body: json({ - value: [validSingletonResource], - }), - }; - }, kind: "MockApiDefinition", }); @@ -241,25 +172,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_actionSync = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - req.expect.bodyEquals({ - message: "Resource action at top level.", - urgent: true, - }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -279,22 +191,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_get = passOnSuccess({ status: 200, body: json(validTopLevelResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - return { - status: 200, - body: json(validTopLevelResource), - }; - }, kind: "MockApiDefinition", }); @@ -319,28 +215,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_createOrReplace = passOnSucce status: 200, body: json(validTopLevelResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - req.expect.bodyEquals({ - location: "eastus", - properties: { - description: "valid", - }, - }); - return { - status: 200, - body: json(validTopLevelResource), - }; - }, kind: "MockApiDefinition", }); @@ -373,27 +247,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_update = passOnSuccess({ }, }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - req.expect.deepEqual(req.body.properties, { - description: "valid2", - }); - const resource = JSON.parse(JSON.stringify(validTopLevelResource)); - resource.properties.description = "valid2"; - return { - status: 200, - body: json(resource), - }; - }, kind: "MockApiDefinition", }); @@ -411,21 +264,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_delete = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -445,21 +283,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_listByResourceGroup = passOnS value: [validTopLevelResource], }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - return { - status: 200, - body: json({ - value: [validTopLevelResource], - }), - }; - }, kind: "MockApiDefinition", }); @@ -478,18 +301,6 @@ Scenarios.Azure_ResourceManager_Resources_TopLevel_listBySubscription = passOnSu value: [validTopLevelResource], }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - return { - status: 200, - body: json({ - value: [validTopLevelResource], - }), - }; - }, kind: "MockApiDefinition", }); @@ -510,25 +321,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_get = passOnSuccess({ status: 200, body: json(validNestedResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - if (req.params.nestedResourceName.toLowerCase() !== "nested") { - throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName); - } - return { - status: 200, - body: json(validNestedResource), - }; - }, kind: "MockApiDefinition", }); @@ -553,30 +345,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_createOrReplace = passOnSuccess status: 200, body: json(validNestedResource), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - if (req.params.nestedResourceName.toLowerCase() !== "nested") { - throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName); - } - req.expect.bodyEquals({ - properties: { - description: "valid", - }, - }); - return { - status: 200, - body: json(validNestedResource), - }; - }, kind: "MockApiDefinition", }); @@ -610,32 +378,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_update = passOnSuccess({ }, }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - if (req.params.nestedResourceName.toLowerCase() !== "nested") { - throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName); - } - req.expect.bodyEquals({ - properties: { - description: "valid2", - }, - }); - const resource = JSON.parse(JSON.stringify(validNestedResource)); - resource.properties.description = "valid2"; - return { - status: 200, - body: json(resource), - }; - }, kind: "MockApiDefinition", }); @@ -654,12 +396,6 @@ Scenarios.Azure_ResourceManager_Resources_Nested_delete = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -680,23 +416,5 @@ Scenarios.Azure_ResourceManager_Resources_Nested_listByTopLevelTrackedResource = value: [validNestedResource], }), }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "2023-12-01-preview"); - if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { - throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); - } - if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { - throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); - } - if (req.params.topLevelResourceName.toLowerCase() !== "top") { - throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); - } - return { - status: 200, - body: json({ - value: [validNestedResource], - }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/client/naming/mockapi.ts b/packages/cadl-ranch-specs/http/client/naming/mockapi.ts index c4acd1f3f..6d1e05769 100644 --- a/packages/cadl-ranch-specs/http/client/naming/mockapi.ts +++ b/packages/cadl-ranch-specs/http/client/naming/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -12,12 +12,6 @@ Scenarios.Client_Naming_Property_client = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ defaultName: true }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -30,12 +24,6 @@ Scenarios.Client_Naming_Property_language = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ defaultName: true }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -48,12 +36,6 @@ Scenarios.Client_Naming_Property_compatibleWithEncodedName = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ wireName: true }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -64,11 +46,6 @@ Scenarios.Client_Naming_operation = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -81,12 +58,6 @@ Scenarios.Client_Naming_parameter = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("defaultName", "true"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -99,12 +70,6 @@ Scenarios.Client_Naming_Header_request = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("default-name", "true"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -118,14 +83,6 @@ Scenarios.Client_Naming_Header_response = passOnSuccess({ "default-name": "true", }, }, - handler: (req: MockRequest) => { - return { - status: 204, - headers: { - "default-name": "true", - }, - }; - }, kind: "MockApiDefinition", }); @@ -138,12 +95,6 @@ Scenarios.Client_Naming_Model_client = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ defaultName: true }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -156,12 +107,6 @@ Scenarios.Client_Naming_Model_language = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ defaultName: true }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -177,12 +122,6 @@ Scenarios.Client_Naming_UnionEnum_unionEnumName = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("value1"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -198,11 +137,5 @@ Scenarios.Client_Naming_UnionEnum_unionEnumMemberName = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("value1"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/client/structure/common/service.ts b/packages/cadl-ranch-specs/http/client/structure/common/service.ts index 9d98eb0d1..719aab811 100644 --- a/packages/cadl-ranch-specs/http/client/structure/common/service.ts +++ b/packages/cadl-ranch-specs/http/client/structure/common/service.ts @@ -1,4 +1,4 @@ -import { MockApiDefinition, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { MockApiDefinition } from "@azure-tools/cadl-ranch-api"; export function createServerTests(uri: string): MockApiDefinition { return { @@ -6,9 +6,6 @@ export function createServerTests(uri: string): MockApiDefinition { method: "post", request: {}, response: { status: 204 }, - handler: (req: MockRequest) => { - return { status: 204 }; - }, kind: "MockApiDefinition", }; } diff --git a/packages/cadl-ranch-specs/http/encode/bytes/mockapi.ts b/packages/cadl-ranch-specs/http/encode/bytes/mockapi.ts index 79764c0fc..b630472fa 100644 --- a/packages/cadl-ranch-specs/http/encode/bytes/mockapi.ts +++ b/packages/cadl-ranch-specs/http/encode/bytes/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, CollectionFormat, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, CollectionFormat, MockRequest, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; import { resolvePath } from "@typespec/compiler"; import { readFileSync } from "fs"; @@ -67,13 +67,7 @@ function createPropertyServerTests(uri: string, data: any, value: any) { }, response: { status: 200, - }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals({ value: value }); - return { - status: 200, - body: json({ value: value }), - }; + body: json({ value: value }), }, kind: "MockApiDefinition", }); @@ -116,12 +110,6 @@ function createHeaderServerTests(uri: string, data: any, value: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("value", value); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); } diff --git a/packages/cadl-ranch-specs/http/encode/duration/mockapi.ts b/packages/cadl-ranch-specs/http/encode/duration/mockapi.ts index f3090e1d9..aae0796f8 100644 --- a/packages/cadl-ranch-specs/http/encode/duration/mockapi.ts +++ b/packages/cadl-ranch-specs/http/encode/duration/mockapi.ts @@ -76,13 +76,6 @@ function createBodyServerTests(uri: string, data: any, value: any) { status: 200, body: json(data), }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals({ value: value }); - return { - status: 200, - body: json({ value: value }), - }; - }, kind: "MockApiDefinition", }); } @@ -138,12 +131,6 @@ function createHeaderServerTests(uri: string, headersData: any, value: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("duration", value); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); } diff --git a/packages/cadl-ranch-specs/http/encode/numeric/mockapi.ts b/packages/cadl-ranch-specs/http/encode/numeric/mockapi.ts index ea588c265..54010e4e4 100644 --- a/packages/cadl-ranch-specs/http/encode/numeric/mockapi.ts +++ b/packages/cadl-ranch-specs/http/encode/numeric/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -16,13 +16,6 @@ function createTests(uri: string, value: any) { status: 200, body: json({ value }), }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals({ value }); - return { - status: 200, - body: json({ value }), - }; - }, kind: "MockApiDefinition", }); } diff --git a/packages/cadl-ranch-specs/http/parameters/basic/mockapi.ts b/packages/cadl-ranch-specs/http/parameters/basic/mockapi.ts index 9f3f4d32f..7dd4ec1b6 100644 --- a/packages/cadl-ranch-specs/http/parameters/basic/mockapi.ts +++ b/packages/cadl-ranch-specs/http/parameters/basic/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -15,10 +15,6 @@ function createServerTests(uri: string) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); } diff --git a/packages/cadl-ranch-specs/http/parameters/body-optionality/mockapi.ts b/packages/cadl-ranch-specs/http/parameters/body-optionality/mockapi.ts index 2ced2512a..6709a0799 100644 --- a/packages/cadl-ranch-specs/http/parameters/body-optionality/mockapi.ts +++ b/packages/cadl-ranch-specs/http/parameters/body-optionality/mockapi.ts @@ -12,10 +12,6 @@ function createServerTests(uri: string, data: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); } @@ -39,10 +35,6 @@ Scenarios.Parameters_BodyOptionality_OptionalExplicit = passOnSuccess([ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }, { diff --git a/packages/cadl-ranch-specs/http/parameters/collection-format/mockapi.ts b/packages/cadl-ranch-specs/http/parameters/collection-format/mockapi.ts index 888d86e15..f635ebe03 100644 --- a/packages/cadl-ranch-specs/http/parameters/collection-format/mockapi.ts +++ b/packages/cadl-ranch-specs/http/parameters/collection-format/mockapi.ts @@ -32,12 +32,6 @@ Scenarios.Parameters_CollectionFormat_Query_csv = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("colors", ["blue", "red", "green"], "csv"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -50,12 +44,6 @@ Scenarios.Parameters_CollectionFormat_Query_ssv = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("colors", ["blue", "red", "green"], "ssv"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -68,12 +56,6 @@ Scenarios.Parameters_CollectionFormat_Query_tsv = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("colors", ["blue", "red", "green"], "tsv"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -86,12 +68,6 @@ Scenarios.Parameters_CollectionFormat_Query_pipes = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("colors", ["blue", "red", "green"], "pipes"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -104,11 +80,5 @@ Scenarios.Parameters_CollectionFormat_Header_csv = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("colors", "blue,red,green"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/parameters/spread/mockapi.ts b/packages/cadl-ranch-specs/http/parameters/spread/mockapi.ts index 23851adaf..ed2b02530 100644 --- a/packages/cadl-ranch-specs/http/parameters/spread/mockapi.ts +++ b/packages/cadl-ranch-specs/http/parameters/spread/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,10 +14,6 @@ Scenarios.Parameters_Spread_Model_spreadAsRequestBody = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -32,10 +28,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequestOnlyWithBody = passOnSuc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -50,10 +42,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequestWithoutBody = passOnSucc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("test-header", "bar"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -71,11 +59,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequest = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("test-header", "bar"); - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -93,11 +76,6 @@ Scenarios.Parameters_Spread_Model_spreadCompositeRequestMix = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("test-header", "bar"); - req.expect.bodyEquals({ prop: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -112,10 +90,6 @@ Scenarios.Parameters_Spread_Alias_spreadAsRequestBody = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -133,11 +107,6 @@ Scenarios.Parameters_Spread_Alias_spreadAsRequestParameter = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("x-ms-test-header", "bar"); - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -158,16 +127,6 @@ Scenarios.Parameters_Spread_Alias_spreadWithMultipleParameters = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("x-ms-test-header", "bar"); - req.expect.bodyEquals({ - requiredString: "foo", - optionalInt: 1, - requiredIntList: [1, 2], - optionalStringList: ["foo", "bar"], - }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -185,11 +144,6 @@ Scenarios.Parameters_Spread_Alias_spreadParameterWithInnerModel = passOnSuccess( response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("x-ms-test-header", "bar"); - req.expect.bodyEquals({ name: "foo" }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -208,10 +162,5 @@ Scenarios.Parameters_Spread_Alias_spreadParameterWithInnerAlias = passOnSuccess( response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("x-ms-test-header", "bar"); - req.expect.bodyEquals({ name: "foo", age: 1 }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/payload/json-merge-patch/mockapi.ts b/packages/cadl-ranch-specs/http/payload/json-merge-patch/mockapi.ts index 00d233b12..e4e10aae5 100644 --- a/packages/cadl-ranch-specs/http/payload/json-merge-patch/mockapi.ts +++ b/packages/cadl-ranch-specs/http/payload/json-merge-patch/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -27,11 +27,11 @@ export const expectedCreateBody = { }; export const expectedUpdateBody = { - name: "Madge", + // name: "Madge", description: null, map: { key: { - name: "InnerMadge", + // name: "InnerMadge", description: null, }, key2: null, @@ -53,13 +53,6 @@ Scenarios.Payload_JsonMergePatch_createResource = passOnSuccess({ status: 200, body: json(expectedCreateBody), }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals(expectedCreateBody); - return { - status: 200, - body: json(expectedCreateBody), - }; - }, kind: "MockApiDefinition", }); Scenarios.Payload_JsonMergePatch_updateResource = passOnSuccess({ @@ -79,27 +72,6 @@ Scenarios.Payload_JsonMergePatch_updateResource = passOnSuccess({ }, }), }, - handler: (req: MockRequest) => { - req.expect.deepEqual(req.body.description, expectedUpdateBody.description); - req.expect.deepEqual(req.body.map.key.description, expectedUpdateBody.map.key.description); - req.expect.deepEqual(req.body.map.key2, expectedUpdateBody.map.key2); - req.expect.deepEqual(req.body.array, expectedUpdateBody.array); - req.expect.deepEqual(req.body.intValue, expectedUpdateBody.intValue); - req.expect.deepEqual(req.body.floatValue, expectedUpdateBody.floatValue); - req.expect.deepEqual(req.body.innerModel, expectedUpdateBody.innerModel); - req.expect.deepEqual(req.body.intArray, expectedUpdateBody.intArray); - return { - status: 200, - body: json({ - name: "Madge", - map: { - key: { - name: "InnerMadge", - }, - }, - }), - }; - }, kind: "MockApiDefinition", }); Scenarios.Payload_JsonMergePatch_updateOptionalResource = passOnSuccess({ @@ -119,26 +91,5 @@ Scenarios.Payload_JsonMergePatch_updateOptionalResource = passOnSuccess({ }, }), }, - handler: (req: MockRequest) => { - req.expect.deepEqual(req.body.description, expectedUpdateBody.description); - req.expect.deepEqual(req.body.map.key.description, expectedUpdateBody.map.key.description); - req.expect.deepEqual(req.body.map.key2, expectedUpdateBody.map.key2); - req.expect.deepEqual(req.body.array, expectedUpdateBody.array); - req.expect.deepEqual(req.body.intValue, expectedUpdateBody.intValue); - req.expect.deepEqual(req.body.floatValue, expectedUpdateBody.floatValue); - req.expect.deepEqual(req.body.innerModel, expectedUpdateBody.innerModel); - req.expect.deepEqual(req.body.intArray, expectedUpdateBody.intArray); - return { - status: 200, - body: json({ - name: "Madge", - map: { - key: { - name: "InnerMadge", - }, - }, - }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/payload/media-type/mockapi.ts b/packages/cadl-ranch-specs/http/payload/media-type/mockapi.ts index 43decd951..036da09ba 100644 --- a/packages/cadl-ranch-specs/http/payload/media-type/mockapi.ts +++ b/packages/cadl-ranch-specs/http/payload/media-type/mockapi.ts @@ -1,4 +1,4 @@ -import { json, MockRequest, passOnSuccess } from "@azure-tools/cadl-ranch-api"; +import { json, passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -15,11 +15,6 @@ Scenarios.Payload_MediaType_StringBody_sendAsText = passOnSuccess({ response: { status: 200, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("content-type", "text/plain"); - req.expect.bodyEquals("{cat}"); - return { status: 200 }; - }, kind: "MockApiDefinition", }); @@ -35,13 +30,6 @@ Scenarios.Payload_MediaType_StringBody_getAsText = passOnSuccess({ status: 200, body: { rawContent: "{cat}", contentType: "text/plain" }, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("accept", "text/plain"); - return { - status: 200, - body: { rawContent: "{cat}", contentType: "text/plain" }, - }; - }, kind: "MockApiDefinition", }); @@ -57,11 +45,6 @@ Scenarios.Payload_MediaType_StringBody_sendAsJson = passOnSuccess({ response: { status: 200, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("content-type", "application/json"); - req.expect.bodyEquals("foo"); - return { status: 200 }; - }, kind: "MockApiDefinition", }); @@ -77,13 +60,5 @@ Scenarios.Payload_MediaType_StringBody_getAsJson = passOnSuccess({ status: 200, body: json("foo"), }, - handler: (req: MockRequest) => { - req.expect.containsHeader("accept", "application/json"); - return { - status: 200, - body: json("foo"), - contentType: "application/json", - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/payload/xml/mockapi.ts b/packages/cadl-ranch-specs/http/payload/xml/mockapi.ts index fb0cadaca..f8014e249 100644 --- a/packages/cadl-ranch-specs/http/payload/xml/mockapi.ts +++ b/packages/cadl-ranch-specs/http/payload/xml/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, xml, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { MockRequest, passOnSuccess, xml } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -134,12 +134,6 @@ function createServerTests(uri: string, data?: any) { status: 200, body: xml(data), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: xml(data), - }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ @@ -151,9 +145,6 @@ function createServerTests(uri: string, data?: any) { "content-type": "application/xml", }, }, - response: { - status: 204, - }, handler: (req: MockRequest) => { req.expect.containsHeader("content-type", "application/xml"); req.expect.xmlBodyEquals(data); @@ -161,6 +152,9 @@ function createServerTests(uri: string, data?: any) { status: 204, }; }, + response: { + status: 204, + }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/resiliency/srv-driven/mockapi.ts b/packages/cadl-ranch-specs/http/resiliency/srv-driven/mockapi.ts index df132f047..5bf98d18e 100644 --- a/packages/cadl-ranch-specs/http/resiliency/srv-driven/mockapi.ts +++ b/packages/cadl-ranch-specs/http/resiliency/srv-driven/mockapi.ts @@ -12,11 +12,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromNone = passOnSuccess([ response: { status: 204, }, - handler: (req: MockRequest) => { - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, { @@ -26,11 +21,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromNone = passOnSuccess([ response: { status: 204, }, - handler: (req: MockRequest) => { - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, { @@ -61,12 +51,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromNone = passOnSuccess([ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("new-parameter", "new"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, ]); @@ -83,12 +67,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneRequired = passOnSucc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("parameter", "required"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, { @@ -102,12 +80,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneRequired = passOnSucc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("parameter", "required"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, { @@ -144,13 +116,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneRequired = passOnSucc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("parameter", "required"); - req.expect.containsQueryParam("new-parameter", "new"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, ]); @@ -167,12 +132,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneOptional = passOnSucc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("parameter", "optional"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, { @@ -186,12 +145,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneOptional = passOnSucc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("parameter", "optional"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, { @@ -228,13 +181,6 @@ Scenarios.Resiliency_ServiceDriven_AddOptionalParam_fromOneOptional = passOnSucc response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("parameter", "optional"); - req.expect.containsQueryParam("new-parameter", "new"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }, ]); @@ -246,11 +192,6 @@ Scenarios.Resiliency_ServiceDriven_breakTheGlass = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -261,10 +202,5 @@ Scenarios.Resiliency_ServiceDriven_addOperation = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/serialization/encoded-name/json/mockapi.ts b/packages/cadl-ranch-specs/http/serialization/encoded-name/json/mockapi.ts index 61dbe6050..64be9c301 100644 --- a/packages/cadl-ranch-specs/http/serialization/encoded-name/json/mockapi.ts +++ b/packages/cadl-ranch-specs/http/serialization/encoded-name/json/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -8,12 +8,6 @@ Scenarios.Serialization_EncodedName_Json_Property_send = passOnSuccess({ method: "post", request: { body: { wireName: true } }, response: { status: 204 }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ wireName: true }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); Scenarios.Serialization_EncodedName_Json_Property_get = passOnSuccess({ @@ -24,11 +18,5 @@ Scenarios.Serialization_EncodedName_Json_Property_get = passOnSuccess({ status: 200, body: json({ wireName: true }), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json({ wireName: true }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/server/endpoint/not-defined/mockapi.ts b/packages/cadl-ranch-specs/http/server/endpoint/not-defined/mockapi.ts index 8a4d25102..5d1b632da 100644 --- a/packages/cadl-ranch-specs/http/server/endpoint/not-defined/mockapi.ts +++ b/packages/cadl-ranch-specs/http/server/endpoint/not-defined/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -10,8 +10,5 @@ Scenarios.Server_Endpoint_NotDefined_valid = passOnSuccess({ response: { status: 200, }, - handler: (req: MockRequest) => { - return { status: 200 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/server/path/multiple/mockapi.ts b/packages/cadl-ranch-specs/http/server/path/multiple/mockapi.ts index 53b9207e2..0f734bca8 100644 --- a/packages/cadl-ranch-specs/http/server/path/multiple/mockapi.ts +++ b/packages/cadl-ranch-specs/http/server/path/multiple/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -9,9 +9,6 @@ Scenarios.Server_Path_Multiple_noOperationParams = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -22,8 +19,5 @@ Scenarios.Server_Path_Multiple_withOperationPathParam = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - return { status: 204 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/server/path/single/mockapi.ts b/packages/cadl-ranch-specs/http/server/path/single/mockapi.ts index f7082a929..fe33c2a28 100644 --- a/packages/cadl-ranch-specs/http/server/path/single/mockapi.ts +++ b/packages/cadl-ranch-specs/http/server/path/single/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -10,8 +10,5 @@ Scenarios.Server_Path_Single_myOp = passOnSuccess({ response: { status: 200, }, - handler: (req: MockRequest) => { - return { status: 200 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/server/versions/not-versioned/mockapi.ts b/packages/cadl-ranch-specs/http/server/versions/not-versioned/mockapi.ts index 06e9fa3b0..29a7b305a 100644 --- a/packages/cadl-ranch-specs/http/server/versions/not-versioned/mockapi.ts +++ b/packages/cadl-ranch-specs/http/server/versions/not-versioned/mockapi.ts @@ -50,9 +50,5 @@ Scenarios.Server_Versions_NotVersioned_withQueryApiVersion = passOnSuccess({ response: { status: 200, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", "v1.0"); - return { status: 200 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/server/versions/versioned/mockapi.ts b/packages/cadl-ranch-specs/http/server/versions/versioned/mockapi.ts index be37b7772..d7fce743c 100644 --- a/packages/cadl-ranch-specs/http/server/versions/versioned/mockapi.ts +++ b/packages/cadl-ranch-specs/http/server/versions/versioned/mockapi.ts @@ -33,10 +33,6 @@ function createAPIVersionTests(uri: string, requestData: any, serverData: string response: { status: 200, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("api-version", serverData); - return { status: 200 }; - }, kind: "MockApiDefinition", }); } diff --git a/packages/cadl-ranch-specs/http/special-headers/conditional-request/mockapi.ts b/packages/cadl-ranch-specs/http/special-headers/conditional-request/mockapi.ts index 865243d96..79dc2b4a4 100644 --- a/packages/cadl-ranch-specs/http/special-headers/conditional-request/mockapi.ts +++ b/packages/cadl-ranch-specs/http/special-headers/conditional-request/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,12 +14,6 @@ Scenarios.SpecialHeaders_ConditionalRequest_postIfMatch = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("if-match", '"valid"'); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -34,12 +28,6 @@ Scenarios.SpecialHeaders_ConditionalRequest_postIfNoneMatch = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("if-none-match", '"invalid"'); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -54,12 +42,6 @@ Scenarios.SpecialHeaders_ConditionalRequest_headIfModifiedSince = passOnSuccess( response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("if-modified-since", "Fri, 26 Aug 2022 14:38:00 GMT"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); @@ -74,11 +56,5 @@ Scenarios.SpecialHeaders_ConditionalRequest_postIfUnmodifiedSince = passOnSucces response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsHeader("if-unmodified-since", "Fri, 26 Aug 2022 14:38:00 GMT"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/special-words/mockapi.ts b/packages/cadl-ranch-specs/http/special-words/mockapi.ts index 1c7ccf58a..648412733 100644 --- a/packages/cadl-ranch-specs/http/special-words/mockapi.ts +++ b/packages/cadl-ranch-specs/http/special-words/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -13,11 +13,6 @@ function createOperationsTests(uri: string) { response: { status: 204, }, - handler: (req: MockRequest) => { - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); } @@ -69,12 +64,6 @@ function createParametersTests(uri: string, data: any, paramName: string) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam(paramName, "ok"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); } @@ -334,12 +323,6 @@ function createModelsTests(uri: string) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ name: "ok" }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); } @@ -391,11 +374,5 @@ Scenarios.SpecialWords_ModelProperties_sameAsModel = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ ["SameAsModel"]: "ok" }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/array/mockapi.ts b/packages/cadl-ranch-specs/http/type/array/mockapi.ts index 959e6d5f8..91f56dbc2 100644 --- a/packages/cadl-ranch-specs/http/type/array/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/array/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -12,12 +12,6 @@ function createServerTests(uri: string, data: any) { status: 200, body: json(data), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(data), - }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ @@ -29,12 +23,6 @@ function createServerTests(uri: string, data: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals(data); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/type/dictionary/mockapi.ts b/packages/cadl-ranch-specs/http/type/dictionary/mockapi.ts index 3be5009ee..15637cb15 100644 --- a/packages/cadl-ranch-specs/http/type/dictionary/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/dictionary/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -12,12 +12,6 @@ function createServerTests(uri: string, data: any) { status: 200, body: json(data), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(data), - }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ @@ -29,12 +23,6 @@ function createServerTests(uri: string, data: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals(data); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/type/enum/extensible/mockapi.ts b/packages/cadl-ranch-specs/http/type/enum/extensible/mockapi.ts index 59aa28c78..66915ee61 100644 --- a/packages/cadl-ranch-specs/http/type/enum/extensible/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/enum/extensible/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -13,9 +13,6 @@ function createMockServerTests(uri: string, data: any) { status: 200, body: json(data), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(data) }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ @@ -30,10 +27,6 @@ function createMockServerTests(uri: string, data: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(data); - return { status: 204 }; - }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/type/enum/fixed/mockapi.ts b/packages/cadl-ranch-specs/http/type/enum/fixed/mockapi.ts index 16c385916..4d85677d3 100644 --- a/packages/cadl-ranch-specs/http/type/enum/fixed/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/enum/fixed/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json, passOnCode } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -12,9 +12,6 @@ Scenarios.Type_Enum_Fixed_String_getKnownValue = passOnSuccess({ status: 200, body: json("Monday"), }, - handler: (req: MockRequest) => { - return { status: 200, body: json("Monday") }; - }, kind: "MockApiDefinition", }); @@ -30,15 +27,11 @@ Scenarios.Type_Enum_Fixed_String_putKnownValue = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("Monday"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); // Unknown values -Scenarios.Type_Enum_Fixed_String_putUnknownValue = passOnSuccess({ +Scenarios.Type_Enum_Fixed_String_putUnknownValue = passOnCode(500, { uri: "/type/enum/fixed/string/unknown-value", method: "put", request: { @@ -51,9 +44,5 @@ Scenarios.Type_Enum_Fixed_String_putUnknownValue = passOnSuccess({ response: { status: 500, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("Weekend"); - return { status: 500 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/model/empty/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/empty/mockapi.ts index 2a70a5aee..0740862b3 100644 --- a/packages/cadl-ranch-specs/http/type/model/empty/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/empty/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,10 +14,6 @@ Scenarios.Type_Model_Empty_putEmpty = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(body); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -29,9 +25,6 @@ Scenarios.Type_Model_Empty_getEmpty = passOnSuccess({ status: 200, body: json(body), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(body) }; - }, kind: "MockApiDefinition", }); @@ -45,9 +38,5 @@ Scenarios.Type_Model_Empty_postRoundTripEmpty = passOnSuccess({ status: 200, body: json(body), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(body); - return { status: 200, body: json(body) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/model/inheritance/enum-discriminator/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/inheritance/enum-discriminator/mockapi.ts index 2c57a7a28..1ee753cb9 100644 --- a/packages/cadl-ranch-specs/http/type/model/inheritance/enum-discriminator/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/inheritance/enum-discriminator/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -20,9 +20,6 @@ function createGetServerTests(uri: string, data: any) { status: 200, body: json(data), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(data) }; - }, kind: "MockApiDefinition", }); } @@ -37,9 +34,6 @@ function createGetPutServerTests(uri: string, data: any) { status: 200, body: json(data), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(data) }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ @@ -51,10 +45,6 @@ function createGetPutServerTests(uri: string, data: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(data); - return { status: 204 }; - }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/type/model/inheritance/nested-discriminator/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/inheritance/nested-discriminator/mockapi.ts index 69f6bc35f..d68bdc684 100644 --- a/packages/cadl-ranch-specs/http/type/model/inheritance/nested-discriminator/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/inheritance/nested-discriminator/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -73,9 +73,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getModel = passOnSuccess({ status: 200, body: json(validPolymorphicBody), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(validPolymorphicBody) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_NestedDiscriminator_putModel = passOnSuccess({ @@ -87,10 +84,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_putModel = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(validPolymorphicBody); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -102,9 +95,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getRecursiveModel = passOnS status: 200, body: json(validRecursiveBody), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(validRecursiveBody) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_NestedDiscriminator_putRecursiveModel = passOnSuccess({ @@ -116,10 +106,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_putRecursiveModel = passOnS response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(validRecursiveBody); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -131,9 +117,6 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getMissingDiscriminator = p status: 200, body: json({ age: 1 }), }, - handler: (req: MockRequest) => { - return { status: 200, body: json({ age: 1 }) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_NestedDiscriminator_getWrongDiscriminator = passOnSuccess({ @@ -144,8 +127,5 @@ Scenarios.Type_Model_Inheritance_NestedDiscriminator_getWrongDiscriminator = pas status: 200, body: json({ age: 1, kind: "wrongKind" }), }, - handler: (req: MockRequest) => { - return { status: 200, body: json({ age: 1, kind: "wrongKind" }) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/model/inheritance/not-discriminated/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/inheritance/not-discriminated/mockapi.ts index ec992949b..87448f2da 100644 --- a/packages/cadl-ranch-specs/http/type/model/inheritance/not-discriminated/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/inheritance/not-discriminated/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -14,10 +14,6 @@ Scenarios.Type_Model_Inheritance_NotDiscriminated_postValid = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(inheritanceValidBody); - return { status: 204 }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_NotDiscriminated_getValid = passOnSuccess({ @@ -28,9 +24,6 @@ Scenarios.Type_Model_Inheritance_NotDiscriminated_getValid = passOnSuccess({ status: 200, body: json(inheritanceValidBody), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(inheritanceValidBody) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_NotDiscriminated_putValid = passOnSuccess({ @@ -43,8 +36,5 @@ Scenarios.Type_Model_Inheritance_NotDiscriminated_putValid = passOnSuccess({ status: 200, body: json(inheritanceValidBody), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(req.body) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/model/inheritance/recursive/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/inheritance/recursive/mockapi.ts index 4d95475f9..b5eeed091 100644 --- a/packages/cadl-ranch-specs/http/type/model/inheritance/recursive/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/inheritance/recursive/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -28,10 +28,6 @@ Scenarios.Type_Model_Inheritance_Recursive_put = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(body); - return { status: 204 }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_Recursive_get = passOnSuccess({ @@ -42,8 +38,5 @@ Scenarios.Type_Model_Inheritance_Recursive_get = passOnSuccess({ status: 200, body: json(body), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(body) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/model/inheritance/single-discriminator/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/inheritance/single-discriminator/mockapi.ts index 2a45afca5..a68ca51cc 100644 --- a/packages/cadl-ranch-specs/http/type/model/inheritance/single-discriminator/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/inheritance/single-discriminator/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -35,9 +35,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getModel = passOnSuccess({ status: 200, body: json(validPolymorphicBody), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(validPolymorphicBody) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_SingleDiscriminator_putModel = passOnSuccess({ @@ -49,10 +46,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_putModel = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(validPolymorphicBody); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -64,9 +57,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getRecursiveModel = passOnS status: 200, body: json(validRecursiveBody), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(validRecursiveBody) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_SingleDiscriminator_putRecursiveModel = passOnSuccess({ @@ -78,10 +68,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_putRecursiveModel = passOnS response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(validRecursiveBody); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -93,9 +79,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getMissingDiscriminator = p status: 200, body: json({ wingspan: 1 }), }, - handler: (req: MockRequest) => { - return { status: 200, body: json({ wingspan: 1 }) }; - }, kind: "MockApiDefinition", }); @@ -107,9 +90,6 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getWrongDiscriminator = pas status: 200, body: json({ wingspan: 1, kind: "wrongKind" }), }, - handler: (req: MockRequest) => { - return { status: 200, body: json({ wingspan: 1, kind: "wrongKind" }) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Inheritance_SingleDiscriminator_getLegacyModel = passOnSuccess({ @@ -120,8 +100,5 @@ Scenarios.Type_Model_Inheritance_SingleDiscriminator_getLegacyModel = passOnSucc status: 200, body: json({ size: 20, kind: "t-rex" }), }, - handler: (req: MockRequest) => { - return { status: 200, body: json({ size: 20, kind: "t-rex" }) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/model/usage/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/usage/mockapi.ts index 76f4f7488..43c5c0a9d 100644 --- a/packages/cadl-ranch-specs/http/type/model/usage/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/usage/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -16,10 +16,6 @@ Scenarios.Type_Model_Usage_input = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(body); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -31,9 +27,6 @@ Scenarios.Type_Model_Usage_output = passOnSuccess({ status: 200, body: json(body), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(body) }; - }, kind: "MockApiDefinition", }); @@ -49,9 +42,5 @@ Scenarios.Type_Model_Usage_inputAndOutput = passOnSuccess({ status: 200, body: json(body), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(body); - return { status: 200, body: json(body) }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/model/visibility/mockapi.ts b/packages/cadl-ranch-specs/http/type/model/visibility/mockapi.ts index 2016975fc..e9c77f5e6 100644 --- a/packages/cadl-ranch-specs/http/type/model/visibility/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/model/visibility/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -31,10 +31,6 @@ Scenarios.Type_Model_Visibility_putReadOnlyModel = passOnSuccess({ status: 200, body: json(expectBody), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({}); - return { status: 200, body: json(expectBody) }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Visibility_headModel = passOnSuccess({ @@ -46,10 +42,6 @@ Scenarios.Type_Model_Visibility_headModel = passOnSuccess({ response: { status: 200, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(genData(["queryProp"])); - return { status: 200 }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Visibility_getModel = passOnSuccess({ @@ -62,13 +54,6 @@ Scenarios.Type_Model_Visibility_getModel = passOnSuccess({ status: 200, body: json(genData(["readProp"])), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(genData(["queryProp"])); - return { - status: 200, - body: json(genData(["readProp"])), - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Visibility_putModel = passOnSuccess({ @@ -83,10 +68,6 @@ Scenarios.Type_Model_Visibility_putModel = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(genData(["createProp", "updateProp"])); - return { status: 204 }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Visibility_patchModel = passOnSuccess({ @@ -100,10 +81,6 @@ Scenarios.Type_Model_Visibility_patchModel = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(genData(["updateProp"])); - return { status: 204 }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Visibility_postModel = passOnSuccess({ @@ -117,10 +94,6 @@ Scenarios.Type_Model_Visibility_postModel = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(genData(["createProp"])); - return { status: 204 }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Model_Visibility_deleteModel = passOnSuccess({ @@ -132,9 +105,5 @@ Scenarios.Type_Model_Visibility_deleteModel = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(genData(["deleteProp"])); - return { status: 204 }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/property/additional-properties/mockapi.ts b/packages/cadl-ranch-specs/http/type/property/additional-properties/mockapi.ts index 1f7a730f0..5951136ec 100644 --- a/packages/cadl-ranch-specs/http/type/property/additional-properties/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/property/additional-properties/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -108,12 +108,6 @@ function createServerTests(url: string, value: any) { status: 200, body: json(value), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(value), - }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ @@ -125,13 +119,6 @@ function createServerTests(url: string, value: any) { response: { status: 204, }, - handler: (req: MockRequest) => { - const expectedBody = JSON.parse(JSON.stringify(value)); - req.expect.coercedBodyEquals(expectedBody); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/type/property/nullable/mockapi.ts b/packages/cadl-ranch-specs/http/type/property/nullable/mockapi.ts index 05416698b..dd77fe439 100644 --- a/packages/cadl-ranch-specs/http/type/property/nullable/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/property/nullable/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -12,12 +12,6 @@ function createServerTests(url: string, value: unknown, patchNullableProperty?: status: 200, body: json(value), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(value), - }; - }, kind: "MockApiDefinition", }), patch: passOnSuccess({ @@ -35,15 +29,6 @@ function createServerTests(url: string, value: unknown, patchNullableProperty?: response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals({ - requiredProperty: "foo", - nullableProperty: patchNullableProperty || null, - }); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/type/property/optionality/mockapi.ts b/packages/cadl-ranch-specs/http/type/property/optionality/mockapi.ts index fe4b39285..01049584a 100644 --- a/packages/cadl-ranch-specs/http/type/property/optionality/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/property/optionality/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -12,12 +12,6 @@ function createServerTests(url: string, value: unknown) { status: 200, body: json(value), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(value), - }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ @@ -29,12 +23,6 @@ function createServerTests(url: string, value: unknown) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.coercedBodyEquals(value); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }), }; diff --git a/packages/cadl-ranch-specs/http/type/property/value-types/mockapi.ts b/packages/cadl-ranch-specs/http/type/property/value-types/mockapi.ts index 595edfdf9..893576cda 100644 --- a/packages/cadl-ranch-specs/http/type/property/value-types/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/property/value-types/mockapi.ts @@ -3,13 +3,6 @@ import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/ export const Scenarios: Record = {}; function createServerTests(url: string, data: unknown, convertedToFn?: (_: any) => any) { - let property; - if (convertedToFn) { - property = convertedToFn(data); - } else { - property = data; - } - return { get: passOnSuccess({ uri: url, @@ -19,30 +12,17 @@ function createServerTests(url: string, data: unknown, convertedToFn?: (_: any) status: 200, body: json(data), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(data), - }; - }, kind: "MockApiDefinition", }), put: passOnSuccess({ uri: url, method: `put`, request: { - body: property, + body: data, }, response: { status: 204, }, - handler: (req: MockRequest) => { - const expectedBody = JSON.parse(JSON.stringify(property)); - req.expect.coercedBodyEquals(expectedBody); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }), }; @@ -148,7 +128,30 @@ const Type_Property_ValueTypes_Never = createServerTests(`/type/property/value-t property: undefined, }); Scenarios.Type_Property_ValueTypes_Never_get = Type_Property_ValueTypes_Never.get; -Scenarios.Type_Property_ValueTypes_Never_put = Type_Property_ValueTypes_Never.put; +Scenarios.Type_Property_ValueTypes_Never_put = passOnSuccess({ + uri: `/type/property/value-types/never`, + method: `put`, + request: { + body: { + property: undefined, + }, + }, + response: { + status: 204, + }, + handler: (req: MockRequest) => { + const expectedBody = JSON.parse( + JSON.stringify({ + property: undefined, + }), + ); + req.expect.coercedBodyEquals(expectedBody); + return { + status: 204, + }; + }, + kind: "MockApiDefinition", +}); const Type_Property_ValueTypes_Unknown_String = createServerTests(`/type/property/value-types/unknown/string`, { property: "hello", diff --git a/packages/cadl-ranch-specs/http/type/scalar/mockapi.ts b/packages/cadl-ranch-specs/http/type/scalar/mockapi.ts index 81ab4d694..ef6ce43b6 100644 --- a/packages/cadl-ranch-specs/http/type/scalar/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/scalar/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -11,9 +11,6 @@ Scenarios.Type_Scalar_String_get = passOnSuccess({ status: 200, body: json("test"), }, - handler: (req: MockRequest) => { - return { status: 200, body: json("test") }; - }, kind: "MockApiDefinition", }); @@ -29,10 +26,6 @@ Scenarios.Type_Scalar_String_put = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("test"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -44,9 +37,6 @@ Scenarios.Type_Scalar_Boolean_get = passOnSuccess({ status: 200, body: json(true), }, - handler: (req: MockRequest) => { - return { status: 200, body: json(true) }; - }, kind: "MockApiDefinition", }); @@ -62,10 +52,6 @@ Scenarios.Type_Scalar_Boolean_put = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(true); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -77,9 +63,6 @@ Scenarios.Type_Scalar_Unknown_get = passOnSuccess({ status: 200, body: json("test"), }, - handler: (req: MockRequest) => { - return { status: 200, body: json("test") }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_Unknown_put = passOnSuccess({ @@ -94,10 +77,6 @@ Scenarios.Type_Scalar_Unknown_put = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("test"); - return { status: 204 }; - }, kind: "MockApiDefinition", }); @@ -109,12 +88,6 @@ Scenarios.Type_Scalar_DecimalType_responseBody = passOnSuccess({ status: 200, body: json(0.33333), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(0.33333), - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_Decimal128Type_responseBody = passOnSuccess({ @@ -125,12 +98,6 @@ Scenarios.Type_Scalar_Decimal128Type_responseBody = passOnSuccess({ status: 200, body: json(0.33333), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json(0.33333), - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_DecimalType_requestBody = passOnSuccess({ @@ -145,12 +112,6 @@ Scenarios.Type_Scalar_DecimalType_requestBody = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(0.33333); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_Decimal128Type_requestBody = passOnSuccess({ @@ -165,12 +126,6 @@ Scenarios.Type_Scalar_Decimal128Type_requestBody = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(0.33333); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_DecimalType_requestParameter = passOnSuccess({ @@ -182,12 +137,6 @@ Scenarios.Type_Scalar_DecimalType_requestParameter = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("value", "0.33333"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_Decimal128Type_requestParameter = passOnSuccess({ @@ -199,12 +148,6 @@ Scenarios.Type_Scalar_Decimal128Type_requestParameter = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.containsQueryParam("value", "0.33333"); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_DecimalVerify_prepareVerify = passOnSuccess({ @@ -215,12 +158,6 @@ Scenarios.Type_Scalar_DecimalVerify_prepareVerify = passOnSuccess({ status: 200, body: json([0.1, 0.1, 0.1]), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json([0.1, 0.1, 0.1]), - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_Decimal128Verify_prepareVerify = passOnSuccess({ @@ -231,12 +168,6 @@ Scenarios.Type_Scalar_Decimal128Verify_prepareVerify = passOnSuccess({ status: 200, body: json([0.1, 0.1, 0.1]), }, - handler: (req: MockRequest) => { - return { - status: 200, - body: json([0.1, 0.1, 0.1]), - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_DecimalVerify_verify = passOnSuccess({ @@ -251,12 +182,6 @@ Scenarios.Type_Scalar_DecimalVerify_verify = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(0.3); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); Scenarios.Type_Scalar_Decimal128Verify_verify = passOnSuccess({ @@ -271,11 +196,5 @@ Scenarios.Type_Scalar_Decimal128Verify_verify = passOnSuccess({ response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals(0.3); - return { - status: 204, - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/type/union/mockapi.ts b/packages/cadl-ranch-specs/http/type/union/mockapi.ts index 14aeb7a30..83ccfa0c9 100644 --- a/packages/cadl-ranch-specs/http/type/union/mockapi.ts +++ b/packages/cadl-ranch-specs/http/type/union/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -12,9 +12,6 @@ function createGetServerTests(url: string, value: unknown) { status: 200, body: json({ prop: value }), }, - handler: (req: MockRequest) => { - return { status: 200, body: json({ prop: value }) }; - }, kind: "MockApiDefinition", }); } @@ -31,10 +28,6 @@ function createPostServerTests(url: string, value: unknown) { response: { status: 204, }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ prop: value }); - return { status: 204 }; - }, kind: "MockApiDefinition", }); } diff --git a/packages/cadl-ranch-specs/http/versioning/added/mockapi.ts b/packages/cadl-ranch-specs/http/versioning/added/mockapi.ts index 8a48fec21..1fe35f757 100644 --- a/packages/cadl-ranch-specs/http/versioning/added/mockapi.ts +++ b/packages/cadl-ranch-specs/http/versioning/added/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -20,14 +20,6 @@ Scenarios.Versioning_Added_v1 = passOnSuccess({ status: 200, body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: 10 }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ prop: "foo", enumProp: "enumMemberV2", unionProp: 10 }); - req.expect.containsHeader("header-v2", "bar"); - return { - status: 200, - body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: 10 }), - }; - }, kind: "MockApiDefinition", }); @@ -45,13 +37,6 @@ Scenarios.Versioning_Added_v2 = passOnSuccess({ status: 200, body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }); - return { - status: 200, - body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }), - }; - }, kind: "MockApiDefinition", }); @@ -69,12 +54,5 @@ Scenarios.Versioning_Added_InterfaceV2 = passOnSuccess({ status: 200, body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }); - return { - status: 200, - body: json({ prop: "foo", enumProp: "enumMember", unionProp: "bar" }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/versioning/madeOptional/mockapi.ts b/packages/cadl-ranch-specs/http/versioning/madeOptional/mockapi.ts index 877d28b2e..516ea4b6b 100644 --- a/packages/cadl-ranch-specs/http/versioning/madeOptional/mockapi.ts +++ b/packages/cadl-ranch-specs/http/versioning/madeOptional/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -15,12 +15,5 @@ Scenarios.Versioning_MadeOptional_test = passOnSuccess({ status: 200, body: json({ prop: "foo" }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ prop: "foo" }); - return { - status: 200, - body: json({ prop: "foo" }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts b/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts index 801ec6090..0b1d1c46c 100644 --- a/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts +++ b/packages/cadl-ranch-specs/http/versioning/removed/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -17,12 +17,5 @@ Scenarios.Versioning_Removed_v2 = passOnSuccess({ status: 200, body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: "bar" }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ prop: "foo", enumProp: "enumMemberV2", unionProp: "bar" }); - return { - status: 200, - body: json({ prop: "foo", enumProp: "enumMemberV2", unionProp: "bar" }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/versioning/renamedFrom/mockapi.ts b/packages/cadl-ranch-specs/http/versioning/renamedFrom/mockapi.ts index 6ca14928b..328d85bd7 100644 --- a/packages/cadl-ranch-specs/http/versioning/renamedFrom/mockapi.ts +++ b/packages/cadl-ranch-specs/http/versioning/renamedFrom/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -20,14 +20,6 @@ Scenarios.Versioning_RenamedFrom_newOp = passOnSuccess({ status: 200, body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }); - req.expect.containsQueryParam("newQuery", "bar"); - return { - status: 200, - body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }), - }; - }, kind: "MockApiDefinition", }); @@ -45,12 +37,5 @@ Scenarios.Versioning_RenamedFrom_NewInterface = passOnSuccess({ status: 200, body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }); - return { - status: 200, - body: json({ newProp: "foo", enumProp: "newEnumMember", unionProp: 10 }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/versioning/returnTypeChangedFrom/mockapi.ts b/packages/cadl-ranch-specs/http/versioning/returnTypeChangedFrom/mockapi.ts index 9c02743ea..7e20e242d 100644 --- a/packages/cadl-ranch-specs/http/versioning/returnTypeChangedFrom/mockapi.ts +++ b/packages/cadl-ranch-specs/http/versioning/returnTypeChangedFrom/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -16,12 +16,5 @@ Scenarios.Versioning_ReturnTypeChangedFrom_test = passOnSuccess({ status: 200, body: json("test"), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals("test"); - return { - status: 200, - body: json("test"), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch-specs/http/versioning/typeChangedFrom/mockapi.ts b/packages/cadl-ranch-specs/http/versioning/typeChangedFrom/mockapi.ts index 8e0826f2f..36967d8ca 100644 --- a/packages/cadl-ranch-specs/http/versioning/typeChangedFrom/mockapi.ts +++ b/packages/cadl-ranch-specs/http/versioning/typeChangedFrom/mockapi.ts @@ -1,4 +1,4 @@ -import { passOnSuccess, json, MockRequest } from "@azure-tools/cadl-ranch-api"; +import { passOnSuccess, json } from "@azure-tools/cadl-ranch-api"; import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; @@ -19,13 +19,5 @@ Scenarios.Versioning_TypeChangedFrom_test = passOnSuccess({ status: 200, body: json({ prop: "foo", changedProp: "bar" }), }, - handler: (req: MockRequest) => { - req.expect.bodyEquals({ prop: "foo", changedProp: "bar" }); - req.expect.containsQueryParam("param", "baz"); - return { - status: 200, - body: json({ prop: "foo", changedProp: "bar" }), - }; - }, kind: "MockApiDefinition", }); diff --git a/packages/cadl-ranch/src/app/app.ts b/packages/cadl-ranch/src/app/app.ts index a1c09c0e7..7026b340a 100644 --- a/packages/cadl-ranch/src/app/app.ts +++ b/packages/cadl-ranch/src/app/app.ts @@ -1,4 +1,4 @@ -import { RequestExt, ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; +import { MockApiDefinition, MockRequest, RequestExt, ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; import { Response, Router } from "express"; import { getScenarioMetadata } from "../coverage/common.js"; import { CoverageTracker } from "../coverage/coverage-tracker.js"; @@ -46,7 +46,7 @@ export class MockApiApp { }); } else { if (!endpoint.handler) { - continue; + endpoint.handler = createHandler(endpoint); } this.router.route(endpoint.uri)[endpoint.method]((req: RequestExt, res: Response) => { processRequest(this.coverageTracker, name, endpoint.uri, req, res, endpoint.handler!).catch((e) => { @@ -58,3 +58,67 @@ export class MockApiApp { } } } + +function isObject(value: any): boolean { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + +function createHandler(apiDefinition: MockApiDefinition) { + return (req: MockRequest) => { + // Validate body if present in the request + if (apiDefinition.request.body) { + if (apiDefinition.request.headers && apiDefinition.request.headers["Content-Type"] === "application/xml") { + req.expect.xmlBodyEquals( + apiDefinition.request.body.rawContent.replace(``, ""), + ); + } else { + if (isObject(apiDefinition.request.body)) { + Object.entries(apiDefinition.request.body).forEach(([key, value]) => { + req.expect.deepEqual(req.body[key], value); + }); + } else { + req.expect.coercedBodyEquals(apiDefinition.request.body); + } + } + } + + // Validate headers if present in the request + if (apiDefinition.request.headers) { + Object.entries(apiDefinition.request.headers).forEach(([key, value]) => { + if (key.toLowerCase() !== "content-type") { + if (Array.isArray(value)) { + req.expect.deepEqual(req.headers[key], value); + } else { + req.expect.containsHeader(key.toLowerCase(), String(value)); + } + } + }); + } + + // Validate query params if present in the request + if (apiDefinition.request.params) { + Object.entries(apiDefinition.request.params).forEach(([key, value]) => { + if (!req.query[key]) { + if (Array.isArray(value)) { + req.expect.deepEqual(req.params[key], value); + } else { + req.expect.deepEqual(req.params[key], String(value)); + } + } else { + if (Array.isArray(value)) { + req.expect.deepEqual(req.query[key], value); + } else { + req.expect.containsQueryParam(key, String(value)); + } + } + }); + } + + // Validations are done. Now return the response + return { + status: apiDefinition.response.status, + body: apiDefinition.response.body, + headers: apiDefinition.response.headers, + }; + }; +}