From dff4f111c4789cb1df827dc18e962f3b4bf13265 Mon Sep 17 00:00:00 2001 From: Ke Yu <33389195+keryul@users.noreply.github.com> Date: Mon, 16 May 2022 17:31:46 +0800 Subject: [PATCH] Get real schema and data while error's schema has allOf property (#798) --- ChangeLog.md | 4 +++ lib/swaggerValidator/ajvSchemaValidator.ts | 7 ++++- package-lock.json | 4 +-- package.json | 2 +- test/liveValidation/payloads/dateTime.json | 2 ++ .../Microsoft.DateTime/test.json} | 27 ++++++++++++++++++- test/liveValidatorTests.ts | 2 +- 7 files changed, 42 insertions(+), 6 deletions(-) rename test/liveValidation/swaggers/specification/{desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/desktopvirtualization.json => date-time/resource-manager/Microsoft.DateTime/test.json} (96%) diff --git a/ChangeLog.md b/ChangeLog.md index e197dadd..8d1c912c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Change Log - oav +## 04/20/2022 2.12.2 + +- LiveValidator - Get real schema and data while error's schema has allOf property + ## 04/20/2022 2.12.1 - Fix bug about copyfiles command during build diff --git a/lib/swaggerValidator/ajvSchemaValidator.ts b/lib/swaggerValidator/ajvSchemaValidator.ts index 6ec0e072..602fd445 100644 --- a/lib/swaggerValidator/ajvSchemaValidator.ts +++ b/lib/swaggerValidator/ajvSchemaValidator.ts @@ -272,8 +272,13 @@ const ReValidateIfNeed = ( }; const shouldSkipError = (error: ErrorObject, cxt: SchemaValidateContext) => { - const { schema, parentSchema: parentSch, params, keyword, data } = error; + const { parentSchema: parentSch, params, keyword } = error; const parentSchema = parentSch as Schema; + // If schema has allof property, we can get schema in "_realschema", so is data + const schema = Object.keys(error).includes("_realSchema") + ? (error as any)._realSchema + : error.schema; + const data = Object.keys(error).includes("_realData") ? (error as any)._realData : error.data; if (schema?._skipError || parentSchema._skipError) { return true; diff --git a/package-lock.json b/package-lock.json index ba200e82..6c78ef97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "oav", - "version": "2.12.1", + "version": "2.12.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "oav", - "version": "2.12.1", + "version": "2.12.2", "license": "MIT", "dependencies": { "@autorest/schemas": "^1.3.1", diff --git a/package.json b/package.json index 7766cb81..1c349839 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oav", - "version": "2.12.1", + "version": "2.12.2", "author": { "name": "Microsoft Corporation", "email": "azsdkteam@microsoft.com", diff --git a/test/liveValidation/payloads/dateTime.json b/test/liveValidation/payloads/dateTime.json index 883a4d78..5b741838 100644 --- a/test/liveValidation/payloads/dateTime.json +++ b/test/liveValidation/payloads/dateTime.json @@ -74,7 +74,9 @@ "validationEnvironment": false, "ring": null, "registrationInfo": { + "timeType": "RemindDueDate", "expirationTime": "2024-02-29T02:33:35", + "remindTime": "2024-01-29T02:33:35", "token": "a", "registrationTokenOperation": "Update" }, diff --git a/test/liveValidation/swaggers/specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/desktopvirtualization.json b/test/liveValidation/swaggers/specification/date-time/resource-manager/Microsoft.DateTime/test.json similarity index 96% rename from test/liveValidation/swaggers/specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/desktopvirtualization.json rename to test/liveValidation/swaggers/specification/date-time/resource-manager/Microsoft.DateTime/test.json index 83c1052c..e7e96582 100644 --- a/test/liveValidation/swaggers/specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/desktopvirtualization.json +++ b/test/liveValidation/swaggers/specification/date-time/resource-manager/Microsoft.DateTime/test.json @@ -474,10 +474,34 @@ } } }, + "RemindDueDate": { + "description": "Remind the due date of registration.", + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/RegistrationInfo" + } + ], + "properties": { + "remindTime": { + "format": "date-time", + "type": "string", + "description": "Remind time of registration due date." + } + }, + "x-ms-discriminator-value": "RemindDueDate" + }, "RegistrationInfo": { "description": "Represents a RegistrationInfo definition.", "type": "object", + "required": [ + "timeType" + ], "properties": { + "timeType": { + "description": "Type of time.", + "type": "string" + }, "expirationTime": { "format": "date-time", "type": "string", @@ -501,7 +525,8 @@ "description": "The type of resetting the token.", "x-nullable": false } - } + }, + "discriminator": "timeType" }, "MigrationRequestProperties": { "type": "object", diff --git a/test/liveValidatorTests.ts b/test/liveValidatorTests.ts index c92d0e1a..f91475a0 100644 --- a/test/liveValidatorTests.ts +++ b/test/liveValidatorTests.ts @@ -1037,7 +1037,7 @@ describe("Live Validator", () => { isPathCaseSensitive: false, useRelativeSourceLocationUrl: true, swaggerPathsPattern: [ - "specification/desktopvirtualization/resource-manager/Microsoft.DesktopVirtualization/*.json", + "specification/date-time/resource-manager/Microsoft.DateTime/test.json", ], git: { shouldClone: false,