0.0.6 • Published 1 year ago

@henkel_dx_ipaas/schema-validation-package v0.0.6

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
1 year ago

Schema Validation Package

Schema Validation Package is a simple NestJS package (module) that allows you to validate your data against a schema which is get from a Schema Registry API and cached locally.

Features

  • Validate incoming data against a schema. Uses AJV under the hood.
  • Get schema from a Schema Registry API.
  • Cache schema locally for faster access. It stores the cache entries for 5 minutes.

Getting Started

  1. Add to your app.module.ts the following import:

    @Module({
      imports: [
        SchemaValidationModule,
      ],
      controllers: [],
      providers: [],
    })
  2. In your services or guards, use the SchemaValidationService to validate your data against a schema.

How it works

The package is exposing a SchemaValidationModule which is a NestJS module that should be imported in your application. This module provides a SchemaValidationService which is a service that can be used to validate data against a schema.

SchemaValidationService exposes a single method called validateAgainstSchema with the following signature:

async validateAgainstSchema(schemaName: string, objectToValidate: unknown, schemaVersion?: string): { isValid: boolean, errors: Record<string, string> }

Required configuration

The package is using the following environment variables:

- SCHEMA_API_URL - URL of the Schema Registry API
- SCHEMA_API_SUBSCRIPTION_KEY - Subscription key for the Schema Registry API
- SCHEMA_VALIDATION_CACHE_TTL - TTL of the cached schema in milliseconds
0.0.5

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago