diff --git a/lib/liveValidation/liveValidator.ts b/lib/liveValidation/liveValidator.ts index 23f070a4..66283ec1 100644 --- a/lib/liveValidation/liveValidator.ts +++ b/lib/liveValidation/liveValidator.ts @@ -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, diff --git a/test/liveValidation/payloads/fooResourceProvider_input.json b/test/liveValidation/payloads/fooResourceProvider_input.json index f5343b4e..33d46a10 100644 --- a/test/liveValidation/payloads/fooResourceProvider_input.json +++ b/test/liveValidation/payloads/fooResourceProvider_input.json @@ -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", diff --git a/test/liveValidatorTests.ts b/test/liveValidatorTests.ts index d9fd6ad5..51763848 100644 --- a/test/liveValidatorTests.ts +++ b/test/liveValidatorTests.ts @@ -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 () => {