From e96760fd6a686c0a6322c3eda270c7dffb99a6d0 Mon Sep 17 00:00:00 2001 From: Ray Chen Date: Wed, 23 Nov 2022 17:27:40 +0800 Subject: [PATCH] Ignore unknown formats in AJV (#910) * Ignore unknown formats in AJV * Added testing spec * Updated test --- ChangeLog.md | 4 +++ lib/swaggerValidator/ajvSchemaValidator.ts | 1 + package-lock.json | 6 ++-- package.json | 6 ++-- .../Microsoft.Contoso/2020-01-01/contoso.json | 3 +- .../Swagger-with-unknown-format.json | 34 +++++++++++++++++++ test/semanticValidatorTests.ts | 5 +++ 7 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 test/semanticValidation/specification/validateCompile/Swagger-with-unknown-format.json diff --git a/ChangeLog.md b/ChangeLog.md index f66ba8ed..95db4d23 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # Change Log - oav +## 11/23/2022 3.2.3 + +- AjvSchemaValidator - Ignore unknown format when compile schema + ## 11/07/2022 3.2.2 - API Scenario diff --git a/lib/swaggerValidator/ajvSchemaValidator.ts b/lib/swaggerValidator/ajvSchemaValidator.ts index 602fd445..840e9a5b 100644 --- a/lib/swaggerValidator/ajvSchemaValidator.ts +++ b/lib/swaggerValidator/ajvSchemaValidator.ts @@ -51,6 +51,7 @@ export class AjvSchemaValidator implements SchemaValidator { inlineRefs: false, passContext: true, loopRequired: 2, + unknownFormats: "ignore", loadSchema: async (uri) => { const spec: SwaggerSpec = await loader.resolveFile(uri); return { [$id]: spec[$id], definitions: spec.definitions, parameters: spec.parameters }; diff --git a/package-lock.json b/package-lock.json index cc1eb8e8..7c8d8df5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "oav", - "version": "3.2.2", + "version": "3.2.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "oav", - "version": "3.2.2", + "version": "3.2.3", "license": "MIT", "dependencies": { "@autorest/schemas": "^1.3.4", @@ -88,7 +88,7 @@ "typescript": "^3.9.10" }, "engines": { - "node": ">=10.11.0" + "node": ">=16.18.1" } }, "node_modules/@ampproject/remapping": { diff --git a/package.json b/package.json index c4b57436..e54db02e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oav", - "version": "3.2.2", + "version": "3.2.3", "author": { "name": "Microsoft Corporation", "email": "azsdkteam@microsoft.com", @@ -131,9 +131,9 @@ "li": "npm install @ts-common/local-install --no-save && local-install" }, "engines": { - "node": ">=10.11.0" + "node": ">=16.18.1" }, "jest-junit": { "output": "test-results.xml" } -} +} \ No newline at end of file diff --git a/test/liveValidation/swaggers/specification/contoso/resource-manager/Microsoft.Contoso/2020-01-01/contoso.json b/test/liveValidation/swaggers/specification/contoso/resource-manager/Microsoft.Contoso/2020-01-01/contoso.json index a63579eb..daa2f57a 100644 --- a/test/liveValidation/swaggers/specification/contoso/resource-manager/Microsoft.Contoso/2020-01-01/contoso.json +++ b/test/liveValidation/swaggers/specification/contoso/resource-manager/Microsoft.Contoso/2020-01-01/contoso.json @@ -192,7 +192,8 @@ "properties": { "firstName": { "type": "string", - "description": "First name." + "description": "First name.", + "format": "unknown format" }, "password": { "type": "string", diff --git a/test/semanticValidation/specification/validateCompile/Swagger-with-unknown-format.json b/test/semanticValidation/specification/validateCompile/Swagger-with-unknown-format.json new file mode 100644 index 00000000..f172db7e --- /dev/null +++ b/test/semanticValidation/specification/validateCompile/Swagger-with-unknown-format.json @@ -0,0 +1,34 @@ +{ + "swagger": "2.0", + "info": { + "title": "title", + "description": "", + "version": "2022-11-23" + }, + "host": "host", + "schemes": [ + "https" + ], + "paths": { + "/hello": { + "get": { + "operationId": "Resource_Create", + "description": "Test operation", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/model" + } + } + } + } + } + }, + "definitions": { + "model": { + "type": "string", + "format": "unknown format" + } + } +} \ No newline at end of file diff --git a/test/semanticValidatorTests.ts b/test/semanticValidatorTests.ts index 472d1708..aa94abf1 100644 --- a/test/semanticValidatorTests.ts +++ b/test/semanticValidatorTests.ts @@ -147,6 +147,11 @@ describe("Semantic validation", () => { "Failed to compile validator on operation" ); }); + it("should ignore unknown format when compile schema", async () => { + const specPath = `${testPath}/semanticValidation/specification/validateCompile/Swagger-with-unknown-format.json`; + const result = await validate.validateSpec(specPath, undefined); + assert(result.validityStatus === true); + }); }); describe("validateDiscriminator", () => {