Skip to content

Commit

Permalink
[@azure-tools/azure-http-specs] - Remove handler for majority of the …
Browse files Browse the repository at this point in the history
…Scenarios (#1691)

This is the continuation of the PR
microsoft/typespec#4725. This PR handles the
removal of handler property in majority of the Scenarios (Except ones
related to LRO and that checks the absence of a parameter). All
Scenarios are validated and tested. Please review and approve the PR.
Thanks
  • Loading branch information
sarangan12 authored Oct 16, 2024
1 parent df4b8c3 commit 1505570
Show file tree
Hide file tree
Showing 16 changed files with 13 additions and 993 deletions.
3 changes: 1 addition & 2 deletions packages/azure-http-specs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"homepage": "https://azure.github.io/typespec-azure",
"dependencies": {
"@typespec/spector": "workspace:~",
"@typespec/spec-api": "workspace:~",
"@typespec/spector": "workspace:~"
"@typespec/spec-api": "workspace:~"
},
"devDependencies": {
"@azure-tools/typespec-azure-resource-manager": "workspace:~",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
json,
MockApiDefinition,
MockRequest,
passOnSuccess,
ScenarioMockApi,
ValidationError,
} from "@typespec/spec-api";
import { json, MockApiDefinition, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand All @@ -22,15 +15,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",
};
}
Expand Down Expand Up @@ -64,15 +48,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",
},
{
Expand All @@ -87,15 +62,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",
},
]);
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
json,
MockApiDefinition,
MockRequest,
passOnSuccess,
ScenarioMockApi,
} from "@typespec/spec-api";
import { json, MockApiDefinition, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
function createMockApiDefinitions(route: string, request: any, response: any): MockApiDefinition {
Expand All @@ -18,13 +12,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",
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand All @@ -14,11 +14,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",
},
{
Expand All @@ -29,12 +24,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",
},
{
Expand All @@ -45,12 +34,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",
},
]);
71 changes: 1 addition & 70 deletions packages/azure-http-specs/specs/azure/core/basic/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
json,
MockRequest,
passOnSuccess,
ScenarioMockApi,
ValidationError,
} from "@typespec/spec-api";
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
const validUser = { id: 1, name: "Madge", etag: "11bdc430-65e8-45ad-81d9-8ffa60d55b59" };
Expand All @@ -23,16 +17,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",
});

Expand All @@ -47,16 +31,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",
});

Expand All @@ -70,13 +44,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 = {
Expand Down Expand Up @@ -110,22 +77,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",
});

Expand All @@ -141,13 +92,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",
});

Expand All @@ -165,14 +109,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",
});

Expand All @@ -187,10 +123,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",
});
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ Scenarios.Azure_Core_Lro_Standard_createOrReplace = passOnSuccess([
status: 200,
body: json(validUser),
},
handler: (req: MockRequest) => {
return { status: 200, body: json(validUser) };
},
kind: "MockApiDefinition",
},
]);
Expand Down
14 changes: 0 additions & 14 deletions packages/azure-http-specs/specs/azure/core/model/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,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",
});

Expand All @@ -20,10 +17,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",
});

Expand All @@ -33,12 +26,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",
});
37 changes: 1 addition & 36 deletions packages/azure-http-specs/specs/azure/core/page/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, MockRequest, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
const validUser = { id: 1, name: "Madge", etag: "11bdc430-65e8-45ad-81d9-8ffa60d55b59" };
Expand All @@ -8,12 +8,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",
});

Expand All @@ -27,17 +21,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",
});

Expand All @@ -47,25 +30,13 @@ 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",
},
{
uri: "/azure/core/page/second-item",
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",
},
]);
Expand All @@ -75,11 +46,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",
});
Loading

0 comments on commit 1505570

Please sign in to comment.