Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-police

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-police - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

1

dist/parameter.d.ts

@@ -7,5 +7,4 @@ import { SchemaObject, SchemaObjectOptions } from "./schema-object";

parseStyle(data: string, type: string): any;
coerceToType(data: string, type: string): any;
validate(data: any, opts?: SchemaObjectOptions, path?: string): Promise<any>;
protected typeValidator(data: any, spec: any, path: string, opts: SchemaObjectOptions): any;
}

27

dist/parameter.js

@@ -191,22 +191,2 @@ "use strict";

}
coerceToType(data, type) {
let out = data;
if (typeof out === 'string') {
if (type === 'boolean') {
if (out === 'true' || out === '1') {
out = true;
}
else if (out === 'false' || out === '0') {
out = false;
}
}
else if (type === 'number' || type === 'integer') {
out = parseFloat(out);
}
}
else if (out === undefined && type === 'null') {
out = null;
}
return out;
}
async validate(data, opts = {}, path = '') {

@@ -229,2 +209,5 @@ if (this.parameter.content) {

else {
if (typeof opts.coerceTypes === 'undefined') {
opts.coerceTypes = true;
}
if (typeof data === 'string') {

@@ -235,3 +218,5 @@ if (opts.parseStyle !== false) {

}
data = this.coerceToType(data, spec.type);
if (opts.coerceTypes !== false) {
data = this.coerceToType(data, spec.type);
}
}

@@ -238,0 +223,0 @@ if (typeof data === 'undefined') {

import { Schema, ValidationOptions } from 'jsonpolice';
import { OpenAPIV3 } from './types';
export interface SchemaObjectOptions extends ValidationOptions {
coerceTypes?: boolean;
parseStyle?: boolean;

@@ -12,2 +13,3 @@ contentType?: string;

protected readonly validators: Set<string>;
protected coerceToType(data: string, type: string): any;
protected typeValidator(data: any, spec: any, path: string, opts: SchemaObjectOptions): any;

@@ -14,0 +16,0 @@ protected formatValidator(data: any, spec: any, path: string, opts: SchemaObjectOptions): any;

@@ -49,2 +49,22 @@ "use strict";

}
coerceToType(data, type) {
let out = data;
if (typeof out === 'string') {
if (type === 'boolean') {
if (out === 'true' || out === '1') {
out = true;
}
else if (out === 'false' || out === '0') {
out = false;
}
}
else if (type === 'number' || type === 'integer') {
out = parseFloat(out);
}
}
else if (out === undefined && type === 'null') {
out = null;
}
return out;
}
typeValidator(data, spec, path, opts) {

@@ -58,2 +78,7 @@ if (typeof spec.type !== 'string') {

else {
if (typeof data === 'string' && spec.type !== 'string') {
if (opts.coerceTypes === true) {
data = this.coerceToType(data, spec.type);
}
}
return super.typeValidator(data, spec, path, opts);

@@ -60,0 +85,0 @@ }

{
"name": "openapi-police",
"version": "1.0.8",
"version": "1.0.9",
"description": "OpenAPI v3 validators and utilities",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc