UNPKG

@microsoft.azure/autorest.testserver

Version:
110 lines 4.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const api_1 = require("../../api"); const services_1 = require("../../services"); /** * Scenarios to test DPG and RLC Service driven evolution. * These scenarios here are considered acceptable from an Azure breaking change policy */ api_1.app.category("dpg", () => { /** * Initially has no query parameters. After evolution, a new optional query parameter is added. * Note that when defining HEAD and GET methods for the same path, HEAD needs to be defined before * GET. Otherwise Express would register the GET handler as the handler for both and the app.head would be ignored. */ api_1.app.head("/servicedriven/parameters", "DPGAddOptionalInput_NoParams", (req) => { return { status: 200, headers: { "content-length": "123" }, }; }); /** * Initially only has one required Query Parameter. After evolution, a new optional query parameter is added. */ api_1.app.get("/servicedriven/parameters", "DPGAddOptionalInput", (req) => { if (req.query["parameter"]) { return { status: 200, body: (0, api_1.json)({ message: `An object was successfully returned` }), }; } else { return { status: 400, body: (0, api_1.json)({ message: `Expected required parameter "parameter"` }), }; } }); /** * Initially has one required query parameter and one optional query parameter. After evolution, a new optional query parameter is added */ api_1.app.put("/servicedriven/parameters", "DPGAddOptionalInput_RequiredOptionalParam", (req) => { if (req.query["requiredParam"]) { return { status: 200, body: (0, api_1.json)({ message: `An object was successfully returned` }), }; } else { return { status: 400, body: (0, api_1.json)({ message: `Expected required parameter "requiredParam"` }), }; } }); /** * Initially has one optional query parameter. After evolution, a new optional query parameter is added */ api_1.app.get("/serviceDriven/moreParameters", "DPGAddOptionalInput_OptionalParam", (req) => { return { status: 200, body: (0, api_1.json)({ message: `An object was successfully returned` }), }; }); /** * A new body type is added (was JSON, and now JSON + JPEG). */ services_1.coverageService.register("dpg", "DPGNewBodyType.JSON"); services_1.coverageService.register("dpg", "DPGNewBodyType.JPEG"); api_1.app.post("/servicedriven/parameters", "DPGNewBodyType", (req) => { switch (req.headers["content-type"]) { case "image/jpeg": // req.expect.rawBodyEquals("binary"); services_1.coverageService.track("dpg", "DPGNewBodyType.JPEG"); return { status: 200 }; case "application/json": req.expect.bodyEquals({ url: "http://example.org/myimage.jpeg" }); services_1.coverageService.track("dpg", "DPGNewBodyType.JSON"); return { status: 200 }; default: throw new api_1.ValidationError("Should be image/jpeg or application/json", {}, req.headers["content-type"]); } }); /** * Initially the path exists but there is no delete method. After evolution this is a new method in a known path */ api_1.app.delete("/servicedriven/parameters", "DPGAddNewOperation", (req) => { return { status: 204, }; }); /** * Initially neither path or method exist for this operation. After evolution, this is a new method in a new path */ api_1.app.get("/servicedriven/newpath", "DPGAddNewPath", (req) => { return { status: 200, body: (0, api_1.json)({ message: `An object was successfully returned` }), }; }); /** * An operation that is not part of the swagger definition but can be called */ api_1.app.get("/servicedriven/glassbreaker", "DPGGlassBreaker", (req) => { return { status: 200, body: (0, api_1.json)({ message: `An object was successfully returned` }), }; }); }); //# sourceMappingURL=update.js.map