Skip to content

AJV constructed on every call #1055

@gnichola

Description

@gnichola

I am using v5.4.6 and an open api spec 3.1.0., and on app luanch I initialize the validtor like so

// 2. Add the OpenApiValidator middleware
app.use(
	OpenApiValidator.middleware({
		apiSpec,
		validateResponses: true 	// default false
		// 3. Provide the path to the controllers directory
		// operationHandlers: path.join(__dirname), // default false
	}),
);

I then made the same endpoint call 3 times. Each time, I see ajv being constructed, the apiSpec is reparsed and validated and the entire spec is re-added to ajv via:

    if ((_a = openApiSpec.components) === null || _a === void 0 ? void 0 : _a.schemas) {
        Object.entries(openApiSpec.components.schemas).forEach(([id, schema]) => {
            ajv.addSchema(openApiSpec.components.schemas[id], `#/components/schemas/${id}`);
        });

Since ajv is a new instance every time, the addSchema call endups up returning undefined for let sch = this._cache.get(schema);

I have not come across anything in the docs that would indicate a way to prevent this continual reload, but I am hoping I missed something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions