You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

swagger-object-validator

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-object-validator - npm Package Compare versions

Comparing version

to
1.2.0

1

lib/configuration-interfaces/validator-config.d.ts

@@ -6,2 +6,3 @@ import * as Swagger from 'swagger-schema-official';

allowAdditionalProperties?: boolean;
allowXNullable?: boolean;
disallowHttp?: boolean;

@@ -8,0 +9,0 @@ disallowHttps?: boolean;

5

lib/validators/GenericValidator.d.ts

@@ -6,2 +6,5 @@ /// <reference types="bluebird" />

import { ITraceStep, IValidationError } from '../result';
export declare function validateType(test: any, schema: Swagger.Schema, spec: Swagger.Spec, config: IValidatorConfig, trace: Array<ITraceStep>): Promise<Array<IValidationError>>;
export interface ISchemaWithNullable extends Swagger.Schema {
'x-nullable'?: boolean;
}
export declare function validateType(test: any, schema: ISchemaWithNullable, spec: Swagger.Spec, config: IValidatorConfig, trace: Array<ITraceStep>): Promise<Array<IValidationError>>;

@@ -26,2 +26,5 @@ "use strict";

}
if (config.allowXNullable === true && typeIs === 'null' && schema['x-nullable'] === true) {
typeShouldBe = 'null';
}
if (typeIs !== typeShouldBe) {

@@ -28,0 +31,0 @@ pushError_1.pushError({

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

break;
case 'null':
break;
case 'array':

@@ -51,0 +53,0 @@ validator = ArrayValidator_1.validateArray;

@@ -6,2 +6,5 @@ /// <reference types="bluebird" />

import { ITraceStep, IValidationError } from '../result';
export declare function validateObject(test: any, schema: Swagger.Schema, spec: Swagger.Spec, config: IValidatorConfig, trace: Array<ITraceStep>): Promise<Array<IValidationError>>;
export interface ISchemaWithNullable extends Swagger.Schema {
'x-nullable'?: boolean;
}
export declare function validateObject(test: any, schema: ISchemaWithNullable, spec: Swagger.Spec, config: IValidatorConfig, trace: Array<ITraceStep>): Promise<Array<IValidationError>>;

@@ -11,2 +11,5 @@ "use strict";

}
if (config.allowXNullable === true && test === null && schema['x-nullable'] === true) {
return Promise.resolve([]);
}
if (!test || !(test instanceof Object)) {

@@ -17,2 +20,5 @@ var typeIs = typeof (test);

}
if (test === null) {
typeIs = 'null';
}
var typeShouldBe = schema.title ? schema.title : 'object';

@@ -19,0 +25,0 @@ return Promise.resolve([

{
"name": "swagger-object-validator",
"version": "1.1.7",
"version": "1.2.0",
"description": "Validate your objects against a swagger spec and receive in-depth error traces",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -192,2 +192,5 @@ # What?

// allow usage of x-nullable for properties, defaults to disallow
allowXNullable?: boolean;
// HTTP and HTTPS are allowed by default

@@ -260,3 +263,17 @@ disallowHttp?: boolean;

## Allowing `x-nullable` properties
A common extension for Swagger 2 is `x-nullable`, based on
[`nullable` from the OpenAPI 3 spec](https://swagger.io/specification/#schemaNullable).
This allows a property to be returned as `null` instead of the intended type.
By enabling this configuration, the `x-nullable` property is recognized and respected
when validating types.
```TypeScript
let config: IValidatorConfig = {
allowXNullable: true
};
```
## Ignoring errors

@@ -263,0 +280,0 @@ You may want to ignore certain errors. Let's assume you need some magic to allow a certain