Skip to content

Commit

Permalink
kie-issues#1487: Upgrade “ajv” to v8.17.x on kie-tools packages (#2600)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljmotta authored Sep 20, 2024
1 parent 06e97c4 commit c1c736b
Show file tree
Hide file tree
Showing 30 changed files with 641 additions and 166 deletions.
4 changes: 3 additions & 1 deletion examples/uniforms-patternfly/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"@kie-tools/uniforms-patternfly": "workspace:*",
"@patternfly/react-core": "^4.276.6",
"@patternfly/react-icons": "^4.93.6",
"ajv": "^6.12.6",
"ajv": "^8.17.1",
"ajv-draft-04": "^1.0.0",
"ajv-formats": "^3.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"simpl-schema": "^1.12.0",
Expand Down
8 changes: 5 additions & 3 deletions examples/uniforms-patternfly/src/schemas/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
* under the License.
*/

import * as Ajv from "ajv";
import AjvDraft04 from "ajv-draft-04";
import addFormats from "ajv-formats";
import { JSONSchemaBridge } from "uniforms-bridge-json-schema";

const ajv = new Ajv({ allErrors: true, useDefaults: true });
const ajv = new AjvDraft04({ strict: false, allErrors: true, useDefaults: true });
addFormats(ajv);

function createValidator(schema: any) {
const validator = ajv.compile(schema);
Expand Down Expand Up @@ -56,7 +58,7 @@ const schema = {
type: "string",
format: "date-time",
max: "2000-04-04T10:30:00.000Z",
description: "this is date and time field",
description: "this is the date and time field",
},
},
disabled: false,
Expand Down
4 changes: 3 additions & 1 deletion packages/dashbuilder-component-uniforms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"@kie-tools/uniforms-patternfly": "workspace:*",
"@patternfly/react-core": "^4.276.6",
"@patternfly/react-table": "^4.112.39",
"ajv": "^6.12.6",
"ajv": "^8.17.1",
"ajv-draft-04": "^1.0.0",
"ajv-formats": "^3.0.1",
"lodash": "^4.17.21",
"uniforms": "^3.10.2",
"uniforms-bridge-json-schema": "^3.10.2"
Expand Down
11 changes: 7 additions & 4 deletions packages/dashbuilder-component-uniforms/src/Uniforms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
import { JSONSchemaBridge } from "uniforms-bridge-json-schema";
import { AutoForm } from "@kie-tools/uniforms-patternfly/dist/esm";
import * as Ajv from "ajv";
import * as React from "react";
import { useCallback } from "react";
import { AutoForm } from "@kie-tools/uniforms-patternfly/dist/esm";
import AjvDraft04 from "ajv-draft-04";
import addFormats from "ajv-formats";
import { JSONSchemaBridge } from "uniforms-bridge-json-schema";

const ajv = new AjvDraft04({ strict: false, allErrors: true, useDefaults: true });
addFormats(ajv);

const ajv = new Ajv({ allErrors: true, useDefaults: true });
const createValidator = (schema: any) => {
const validator = ajv.compile(schema);
return (model: any) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/dmn-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"@kie-tools/uniforms-patternfly": "workspace:*",
"@patternfly/react-core": "^4.276.6",
"@patternfly/react-icons": "^4.93.6",
"ajv": "^6.12.6",
"ajv": "^8.17.1",
"ajv-draft-04": "^1.0.0",
"ajv-formats": "^3.0.1",
"deep-object-diff": "^1.1.9",
"json-refs": "^3.0.15",
"lodash": "^4.17.21",
Expand Down
28 changes: 14 additions & 14 deletions packages/dmn-runner/src/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
* under the License.
*/

import Ajv from "ajv";
import * as metaSchemaDraft04 from "ajv/lib/refs/json-schema-draft-04.json";
export { ValidateFunction } from "ajv";
import AjvDraft04, { AnySchemaObject } from "ajv-draft-04";
import addFormats from "ajv-formats";
import { duration } from "moment";
import {
DATE_AND_TIME_ENUM_REGEXP,
Expand Down Expand Up @@ -140,7 +139,7 @@ export class DmnRunnerAjv {
};

private constraintCompiler() {
return (schema: any, parentSchema: { format?: DmnAjvSchemaFormat }, it: any) => {
return (schema: any, parentSchema: AnySchemaObject) => {
if (!parentSchema.format) {
return (data: string) => true;
}
Expand Down Expand Up @@ -217,24 +216,25 @@ export class DmnRunnerAjv {
}

constructor() {
this.ajv = new Ajv({
this.ajv = new AjvDraft04({
allErrors: true,
schemaId: "auto",
useDefaults: true,
removeAdditional: "all",
verbose: true,
});
this.ajv.addMetaSchema(metaSchemaDraft04);
this.ajv.addKeyword(X_DMN_TYPE_KEYWORD, {});
this.ajv.addKeyword(X_DMN_ALLOWED_VALUES_KEYWORD, {
addFormats(this.ajv);
this.ajv.addKeyword(X_DMN_TYPE_KEYWORD);
this.ajv.addKeyword({
keyword: X_DMN_ALLOWED_VALUES_KEYWORD,
compile: this.constraintCompiler(),
});
this.ajv.addKeyword(X_DMN_TYPE_CONSTRAINTS_KEYWORD, {
this.ajv.addKeyword({
keyword: X_DMN_TYPE_CONSTRAINTS_KEYWORD,
compile: this.constraintCompiler(),
});
this.ajv.addKeyword(X_DMN_DESCRIPTIONS_KEYWORD, {});
this.ajv.addKeyword(RECURSION_KEYWORD, {});
this.ajv.addKeyword(RECURSION_REF_KEYWORD, {});
this.ajv.addKeyword(X_DMN_DESCRIPTIONS_KEYWORD);
this.ajv.addKeyword(RECURSION_KEYWORD);
this.ajv.addKeyword(RECURSION_REF_KEYWORD);
this.ajv.addFormat(DAYS_AND_TIME_DURATION_FORMAT, {
type: "string",
validate: (data: string) => !!data.match(DAYS_AND_TIME_DURATION_REGEXP),
Expand All @@ -246,7 +246,7 @@ export class DmnRunnerAjv {
});
}

public getAjv(): Ajv.Ajv {
public getAjv(): AjvDraft04 {
return this.ajv;
}
}
5 changes: 3 additions & 2 deletions packages/dmn-runner/src/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import { JSON_SCHEMA_INPUT_SET_PATH, RECURSION_KEYWORD, RECURSION_REF_KEYWORD } from "./jsonSchemaConstants";
import { DmnAjvSchemaFormat, ValidateFunction } from "./ajv";
import { DmnAjvSchemaFormat } from "./ajv";
import { ValidateFunction } from "ajv-draft-04";
import { ExtendedServicesFormSchema, DmnInputFieldProperties } from "@kie-tools/extended-services-api/dist/formSchema";
import { Holder } from "@kie-tools-core/react-hooks/dist/Holder";
import { resolveRefs, pathFromPtr } from "json-refs";
Expand Down Expand Up @@ -87,7 +88,7 @@ export function removeChangedPropertiesAndAdditionalProperties<T extends Validat
return;
}

const pathList = error.dataPath
const pathList = error.schemaPath
.replace(/\['([^']+)'\]/g, "$1")
.replace(/\[(\d+)\]/g, ".$1")
.split(".")
Expand Down
4 changes: 3 additions & 1 deletion packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"@kie-tools/uniforms-patternfly": "workspace:*",
"@patternfly/react-core": "^4.276.6",
"@patternfly/react-icons": "^4.93.6",
"ajv": "^6.12.6",
"ajv": "^8.17.1",
"ajv-draft-04": "^1.0.0",
"ajv-errors": "^1.0.1",
"ajv-formats": "^3.0.1",
"deep-object-diff": "^1.1.9",
"lodash": "^4.17.21",
"uniforms": "^3.10.2",
Expand Down
10 changes: 7 additions & 3 deletions packages/form/src/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
* under the License.
*/

import Ajv from "ajv";
import AjvDraft04 from "ajv-draft-04";
import addFormats from "ajv-formats";
import { FormJsonSchemaBridge } from "./uniforms/FormJsonSchemaBridge";
import { FormI18n } from "./i18n";

export class Validator {
constructor(public i18n: FormI18n) {}
protected readonly ajv: AjvDraft04;

protected readonly ajv = new Ajv({ allErrors: true, schemaId: "auto", useDefaults: true });
constructor(public i18n: FormI18n) {
this.ajv = new AjvDraft04({ allErrors: true, useDefaults: true });
addFormats(this.ajv);
}

public createValidator(formSchema: object) {
const validator = this.ajv.compile(formSchema);
Expand Down
4 changes: 2 additions & 2 deletions packages/form/tests/Validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("Validator Tests", () => {
const validate = validator.createValidator(schema);
const errors = validate(model);
expect(errors?.details[0].keyword).toEqual("minimum");
expect(errors?.details[0].message).toEqual("should be >= 1");
expect(errors?.details[0].message).toEqual("must be >= 1");
});

it("invalid model - format", () => {
Expand All @@ -82,7 +82,7 @@ describe("Validator Tests", () => {
const validate = validator.createValidator(schema);
const errors = validate(model);
expect(errors?.details[0].keyword).toEqual("format");
expect(errors?.details[0].message).toEqual(`should match format "date-time"`);
expect(errors?.details[0].message).toEqual(`must match format "date-time"`);
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-tools-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"@patternfly/react-icons": "^4.93.6",
"@patternfly/react-styles": "^4.92.6",
"@patternfly/react-table": "^4.112.39",
"ajv": "^6.12.6",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"axios": "^1.7.4",
"copyfiles": "^2.4.1",
"history": "^4.9.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { SCHEMA_VERSION } from "@kie-tools/runtime-tools-shared-gateway-api/dist/types";
import Ajv, { ValidateFunction } from "ajv";
import addFormats from "ajv-formats";

/**
* Defines a basic Form Validator
Expand Down Expand Up @@ -59,11 +60,13 @@ export function lookupValidator(schema: any): FormValidator {
export class Draft7FormValidator implements FormValidator {
readonly schema: any;
readonly validator: ValidateFunction;
readonly ajv: Ajv;

constructor(schema: any) {
this.schema = schema;

this.validator = new Ajv({ allErrors: true, useDefaults: true }).compile(schema);
this.ajv = new Ajv({ strict: false, allErrors: true, useDefaults: true });
addFormats(this.ajv);
this.validator = this.ajv.compile(schema);
}

validate(model: any): any | undefined {
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-tools-process-dev-ui-webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"file-loader": "^6.2.0",
"filemanager-webpack-plugin": "^7.0.0",
"graphql": "14.3.1",
"html-replace-webpack-plugin": "^2.6.0",
"html-webpack-plugin": "^5.3.2",
"https-browserify": "^1.0.0",
"identity-obj-proxy": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
{ id: "saravana", groups: [] },
{ id: "john", groups: [] },
],
quarkusAppOrigin: "http://${WEBPACK_REPLACEMENT_WEBAPP_HOST}:${WEBPACK_REPLACEMENT_WEBAPP_PORT}",
quarkusAppRootPath: "",
page: "Processes",
devUIUrl: "http://localhost:9027",
devUIUrl: "http://${WEBPACK_REPLACEMENT_WEBAPP_HOST}:${WEBPACK_REPLACEMENT_WEBAPP_PORT}",
customLabels: {
singularProcessLabel: "Process",
pluralProcessLabel: "Process",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const emptyForm = require("./forms/EmptyForm");
const formData = require("../MockData/forms/formData");
const customDashboardData = require("../MockData/customDashboard/data");
const hiringSchema = require("./process-forms-schema/hiring");
const uuidv4 = require("uuid");
const { v4: uuid } = require("uuid");
const tasksUnableToTransition = [
"047ec38d-5d57-4330-8c8d-9bd67b53a529",
"841b9dba-3d91-4725-9de3-f9f4853b417e",
Expand Down Expand Up @@ -399,8 +399,11 @@ module.exports = controller = {
},

startProcessInstance: (req, res) => {
console.log(
`......Starting Process Instance:: id: ${req.headers["ce-id"]} type: ${req.headers["ce-type"]} source: ${req.headers["ce-source"]}`
);
const businessKey = req.query.businessKey ? req.query.businessKey : null;
const processId = uuidv4();
const processId = uuid();
const processInstance = {
id: processId,
processId: "hiring",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"resources": {
"styles": {},
"scripts": {}
},
"schema": "{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"$defs\":{\"CandidateData\":{\"type\":\"object\",\"properties\":{\"email\":{\"type\":\"string\"},\"experience\":{\"type\":\"integer\"},\"lastName\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"skills\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}}},\"type\":\"object\",\"properties\":{\"candidateData\":{\"$ref\":\"#/$defs/CandidateData\"}}}"
}
Loading

0 comments on commit c1c736b

Please sign in to comment.