1.0.5 • Published 3 years ago

translator-validation-oas v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

translator-validation

A lightweight framework for validation modified swagger files in lion-translator.

Features

  1. Build OAS validation rules easily with modular functions
  2. Allows for custom code for generating rules in python

Requirements

This package uses python-shell for customized functions. Make sure you pass the path to the python env when calling the custom function.

Installation

npm i translator-validation-oas

Documentation

var rules= require('./rules.js')

rules.rules(OrignalSwaggerfile, translatedSwaggerFile, [,options])

OrignalSwaggerfile: Parent Swagger File (needed for checkJsonSchema) translatedSwaggerFile: Modified Swagger File created after the user has modified the original files ,options: Json object or array of json objects

Usage

const rules = require('translator-validation-oas');

let result = rules.rules('sample_oas.json', 'sample_translation.json', {
  "id": "Rule2",
  "functionName": "checkMatch",
  "path": "$.servers[*]",
  "ruledesc": "Check if server match Rule2",
  "fieldname": "url",
  "regexp": "[a-z]+",
  "level": "warn",
  "errmsg": "Expression does not seem to be a URL."
});

console.log(result);

API Reference

Options documentation

Options is a json object.

OptionsTypeDescription
functionNameStringChoose from functions below
ruledescStringGive a brief description of the rule
ruleididGive a unique rule id
JsonPathStringLook up JSon path documentation. This will determine the target object the function is applied to.
fieldnameStringGive the target field name that the function is applied to
levelStringChoose from warn, error,info
parameterkey,valueAdd required parameters for the chosen function

functions documentation

functionNamerequired parameters
checkMatchregexp
checkEnumenumValues (seperated by ',')
checkUniquefieldname
checkLengthmaxsize,minsize
customFunctioncode, pythonPath. Refer to PythonShell documentation
checkJsonSchemaparentSchema,childSchema
checkfieldExistsfieldname
checkfieldNotExistsfieldname