Always transform response code (#549)
* Always transform response code * Add test
This commit is contained in:
Родитель
1a1cb1cbe7
Коммит
5f01014b4b
|
@ -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 () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче