Always transform response code (#549)

* Always transform response code

* Add test
This commit is contained in:
Phoenix He 2020-12-22 09:54:34 +08:00 коммит произвёл GitHub
Родитель 1a1cb1cbe7
Коммит 5f01014b4b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 17 добавлений и 11 удалений

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

@ -372,15 +372,7 @@ export class LiveValidator {
}
let errors: LiveValidationIssue[] = [];
let runtimeException;
// If status code is passed as a status code string (e.g. "OK") transform it to the status code
// number (e.g. '200').
if (
!http.STATUS_CODES[liveResponse.statusCode] &&
utils.statusCodeStringToStatusCode[liveResponse.statusCode.toLowerCase()]
) {
liveResponse.statusCode =
utils.statusCodeStringToStatusCode[liveResponse.statusCode.toLowerCase()];
}
this.transformResponseStatusCode(liveResponse);
try {
errors = await validateSwaggerLiveResponse(
liveResponse,
@ -466,6 +458,7 @@ export class LiveValidator {
const request = requestResponseObj.liveRequest;
const response = requestResponseObj.liveResponse;
this.transformResponseStatusCode(response);
const requestValidationResult = await this.validateLiveRequest(request, {
...options,
@ -495,6 +488,18 @@ export class LiveValidator {
};
}
private transformResponseStatusCode(liveResponse: LiveResponse) {
// If status code is passed as a status code string (e.g. "OK") transform it to the status code
// number (e.g. '200').
if (
!http.STATUS_CODES[liveResponse.statusCode] &&
utils.statusCodeStringToStatusCode[liveResponse.statusCode.toLowerCase()]
) {
liveResponse.statusCode =
utils.statusCodeStringToStatusCode[liveResponse.statusCode.toLowerCase()];
}
}
private getOperationInfo(
request: { url: string; method: string },
correlationId: string,

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

@ -16,7 +16,7 @@
}
},
"liveResponse": {
"statusCode": "200",
"statusCode": "OK",
"headers": {
"x-ms-request-id": "8e3485b6-c8a7-45c2-a9f5-59b826e42880",
"x-ms-correlation-request-id": "8e3485b6-c8a7-45c2-a9f5-59b826e42880",

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

@ -668,7 +668,7 @@ describe("Live Validator", () => {
},
},
});
// Should be able to find Microsoft.Storage with 2015-05-01-preview api version succesfully
// Should be able to find Microsoft.Storage with 2015-05-01-preview api version successfully
const errors = result.responseValidationResult.errors;
assert.deepStrictEqual(errors, []);
assert.equal(result.responseValidationResult.isSuccessful, true);
@ -691,6 +691,7 @@ describe("Live Validator", () => {
throw new Error("runtimeException === undefined");
}
assert.strictEqual(runtimeException.code, "OPERATION_NOT_FOUND_IN_CACHE_WITH_PROVIDER");
assert.strictEqual(payload.liveResponse.statusCode, "200");
});
it(`should not report error in response when both x-ms-secret and requried are declared`, async () => {