Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

@apicurio/data-models-spectral-extension

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apicurio/data-models-spectral-extension

An extension to validate Spectral rulesets using apicurio-data-models

latest
Source
npmnpm
Version
0.1.1-alpha1
Version published
Maintainers
3
Created
Source

Spectral Validation Extension for Apicurio Data Models

Spectral is a popular open-source JSON/YAML linter by Stoplight. This extension lets you validate your data models using the Apicurio Data Models library with Spectral rulesets.

Installation and Usage

Install with npm:

npm install @apicurio/data-models-spectral-validation-extension

Load a Spectral ruleset from a configuration file:

import { SpectralValidationExtension, bundleAndLoadRuleset } from '@apicurio/data-models-spectral-validation-extension';
import { fetch } from '@stoplight/spectral-runtime';
import * as path from 'path';
import * as fs from 'fs';

const rulesetFilepath = path.join(__dirname, ".spectral.yaml");

const spectral = new SpectralValidationExtension({
	ruleset: await bundleAndLoadRuleset(rulesetFilepath, { fs, fetch })
});

Or you can pass in a ruleset object:

import { SpectralValidationExtension } from '@apicurio/data-models-spectral-validation-extension';
import { truthy } from '@stoplight/spectral-functions';
import { DiagnosticSeverity } from '@stoplight/types';

const spectral = new SpectralValidationExtension({
	ruleset: {
		rules: {
			'title-required': {
				given: '$.info',
				description: 'Info title is required',
				severity: DiagnosticSeverity.Hint,
				then: {
					function: truthy,
					field: 'title'
				}
			}
		}
	}
});

Now you can call Library.validateDocument(...) to validate your data model using the Spectral ruleset:

import { Library, ValidationProblem, ValidationProblemSeverity } from 'apicurio-data-models';

const validationProblems = await Library.validateDocument(document, null, [spectral]);

FAQs

Package last updated on 13 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts