* Fix issues for codegen test

* Change name

* Fix format

* revert change
This commit is contained in:
Pan Shao 2022-03-24 13:42:14 +08:00 коммит произвёл GitHub
Родитель 99c79d7a05
Коммит 45ac0da514
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 16 добавлений и 8 удалений

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "@microsoft.azure/autorest.testserver",
"version": "3.3.23",
"version": "3.3.24",
"description": "Autorest test server.",
"main": "dist/cli/cli.js",
"bin": {

Просмотреть файл

@ -216,7 +216,7 @@ app.category("vanilla", () => {
});
app.put("/array/prim/date-time/valid", "putArrayDateTimeValid", (req) => {
req.expect.bodyEquals(["2000-12-01T00:00:01.000Z", "1980-01-02T00:11:35.000Z", "1492-10-12T10:15:01.000Z"]);
req.expect.coercedBodyEquals(["2000-12-01T00:00:01Z", "1980-01-02T00:11:35Z", "1492-10-12T10:15:01Z"]);
return { status: 200 };
});
@ -243,7 +243,7 @@ app.category("vanilla", () => {
};
});
app.put("/array/prim/date-time-rfc1123/valid", "getDateTimeRfc1123Valid", (req) => {
app.put("/array/prim/date-time-rfc1123/valid", "putArrayDateTimeRfc1123Valid", (req) => {
req.expect.bodyEquals([
"Fri, 01 Dec 2000 00:00:01 GMT",
"Wed, 02 Jan 1980 00:11:35 GMT",

Просмотреть файл

@ -137,7 +137,7 @@ app.category("vanilla", () => {
"Retry",
{
408: ["head"],
502: ["get"],
502: ["get", "options"],
500: ["put", "patch"],
503: ["post", "delete"],
504: ["put", "patch"],
@ -315,7 +315,7 @@ app.category("vanilla", () => {
//#region Endpoint with response for 202, 204, 400 returning valid payloads
app.get("/http/payloads/default/a/response/200/valid", "ResponsesScenarioF200DefaultModel", (req) => {
return { status: 200, body: json({ property: "value" }) };
return { status: 200, body: json({ statusCode: "200" }) };
});
app.get("/http/payloads/default/a/response/200/none", "ResponsesScenarioF200DefaultNone", (req) => {
@ -354,7 +354,7 @@ app.category("vanilla", () => {
});
app.get("/http/payloads/200/a/response/200/valid", "ResponsesScenarioH200MatchingModel", (req) => {
return { status: 200 };
return { status: 200, body: json({ statusCode: "200" }) };
});
app.get("/http/payloads/200/a/response/200/invalid", "ResponsesScenarioH200MatchingInvalid", (req) => {

Просмотреть файл

@ -1,5 +1,6 @@
import { app, ValidationError, json } from "../api";
import { coverageService } from "../services";
import { coerceDateString } from "../utils";
const Constants = {
DEFAULT_SERVER_PORT: "3000",
@ -127,13 +128,17 @@ app.category("vanilla", () => {
};
}
const wireParameter = deserializeValue(type as never, req.params.wireParameter);
let wireParameter = deserializeValue(type as never, req.params.wireParameter);
if (scenarioConfig === undefined) {
return { status: 404, body: json({ message: `Scenario "${scenarioName}" not found for type ${type}` }) };
}
const expectedValue = getScenarioExpectedValue(scenarioName, scenarioConfig);
let expectedValue = getScenarioExpectedValue(scenarioName, scenarioConfig);
if (type === "datetime") {
wireParameter = coerceDateString(wireParameter);
expectedValue = coerceDateString(expectedValue as string);
}
if (wireParameter !== expectedValue) {
throw new ValidationError("wireParameter path does not match expected value", expectedValue, wireParameter);
}

Просмотреть файл

@ -1 +1,4 @@
export const toPascalCase = (input: string): string => "" + input.charAt(0).toUpperCase() + input.slice(1);
export const coerceDateString = (date: string): string =>
date.replace(/(\d\d\d\d-\d\d-\d\d[Tt]\d\d:\d\d:\d\d)\.\d{3,7}([Zz]|[+-]00:00)/g, "$1Z");