@aws-cdk/cloud-assembly-schema
Advanced tools
Comparing version 39.1.38 to 39.1.39
@@ -252,3 +252,3 @@ "use strict"; | ||
_a = JSII_RTTI_SYMBOL_1; | ||
Manifest[_a] = { fqn: "@aws-cdk/cloud-assembly-schema.Manifest", version: "39.1.38" }; | ||
Manifest[_a] = { fqn: "@aws-cdk/cloud-assembly-schema.Manifest", version: "39.1.39" }; | ||
function mapValues(xs, fn) { | ||
@@ -255,0 +255,0 @@ if (!xs) { |
'use strict'; | ||
var uri = require('url'); | ||
var ValidationError = exports.ValidationError = function ValidationError (message, instance, schema, path, name, argument) { | ||
@@ -87,3 +85,3 @@ if(Array.isArray(path)){ | ||
function ValidatorResultError(result) { | ||
if(Error.captureStackTrace){ | ||
if(typeof Error.captureStackTrace === 'function'){ | ||
Error.captureStackTrace(this, ValidatorResultError); | ||
@@ -109,3 +107,5 @@ } | ||
Error.call(this, msg); | ||
Error.captureStackTrace(this, SchemaError); | ||
if(typeof Error.captureStackTrace === 'function'){ | ||
Error.captureStackTrace(this, SchemaError); | ||
} | ||
}; | ||
@@ -134,3 +134,3 @@ SchemaError.prototype = Object.create(Error.prototype, | ||
SchemaContext.prototype.resolve = function resolve (target) { | ||
return uri.resolve(this.base, target); | ||
return (() => resolveUrl(this.base,target))(); | ||
}; | ||
@@ -141,3 +141,3 @@ | ||
var id = schema.$id || schema.id; | ||
var base = uri.resolve(this.base, id||''); | ||
let base = (() => resolveUrl(this.base,id||''))(); | ||
var ctx = new SchemaContext(schema, this.options, path, base, Object.create(this.schemas)); | ||
@@ -395,1 +395,17 @@ if(id && !ctx.schemas[base]){ | ||
/** | ||
* Resolve target URL from a base and relative URL. | ||
* Similar to Node's URL Lib's legacy resolve function. | ||
* Code from example in deprecation note in said library. | ||
* @param string | ||
* @param string | ||
* @returns {string} | ||
*/ | ||
var resolveUrl = exports.resolveUrl = function resolveUrl(from, to) { | ||
const resolvedUrl = new URL(to, new URL(from, 'resolve://')); | ||
if (resolvedUrl.protocol === 'resolve:') { | ||
const { pathname, search, hash } = resolvedUrl; | ||
return pathname + search + hash; | ||
} | ||
return resolvedUrl.toString(); | ||
} |
@@ -30,2 +30,9 @@ /* | ||
export declare class ValidatorResultError extends Error { | ||
instance: any; | ||
schema: Schema; | ||
options: Options; | ||
errors: ValidationError; | ||
} | ||
export declare class ValidationError { | ||
@@ -69,2 +76,3 @@ constructor(message?: string, instance?: any, schema?: Schema, propertyPath?: any, name?: string, argument?: any); | ||
items?: Schema | Schema[] | ||
contains?: Schema | ||
maxItems?: number | ||
@@ -76,2 +84,3 @@ minItems?: number | ||
required?: string[] | boolean | ||
propertyNames?: boolean | Schema | ||
additionalProperties?: boolean | Schema | ||
@@ -101,2 +110,4 @@ definitions?: { | ||
else?: Schema | ||
default?: any | ||
examples?: any[] | ||
} | ||
@@ -103,0 +114,0 @@ |
"use strict"; | ||
var urilib = require('url'); | ||
var helpers = require('./helpers'); | ||
@@ -23,3 +22,3 @@ | ||
if(schema.$ref){ | ||
var resolvedUri = urilib.resolve(baseuri, schema.$ref); | ||
let resolvedUri = helpers.resolveUrl(baseuri,schema.$ref); | ||
ref[resolvedUri] = ref[resolvedUri] ? ref[resolvedUri]+1 : 0; | ||
@@ -29,3 +28,4 @@ return; | ||
var id = schema.$id || schema.id; | ||
var ourBase = id ? urilib.resolve(baseuri, id) : baseuri; | ||
let resolvedBase = helpers.resolveUrl(baseuri,id); | ||
var ourBase = id ? resolvedBase : baseuri; | ||
if (ourBase) { | ||
@@ -32,0 +32,0 @@ // If there's no fragment, append an empty one |
'use strict'; | ||
var urilib = require('url'); | ||
var attribute = require('./attribute'); | ||
@@ -118,3 +116,3 @@ var helpers = require('./helpers'); | ||
var id = schema.$id || schema.id; | ||
var base = urilib.resolve(options.base||anonymousBase, id||''); | ||
let base = helpers.resolveUrl(options.base,id||''); | ||
if(!ctx){ | ||
@@ -266,4 +264,4 @@ ctx = new SchemaContext(schema, options, [], base, Object.create(this.schemas)); | ||
// Else try walking the property pointer | ||
var parsed = urilib.parse(switchSchema); | ||
var fragment = parsed && parsed.hash; | ||
let parsed = new URL(switchSchema,'thismessage::/'); | ||
let fragment = parsed.hash; | ||
var document = fragment && fragment.length && switchSchema.substr(0, switchSchema.length - fragment.length); | ||
@@ -270,0 +268,0 @@ if (!document || !ctx.schemas[document]) { |
{ | ||
"author": "Tom de Grunt <tom@degrunt.nl>", | ||
"name": "jsonschema", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"license": "MIT", | ||
@@ -42,2 +42,2 @@ "dependencies": {}, | ||
} | ||
} | ||
} |
@@ -83,2 +83,4 @@ [![Build Status](https://secure.travis-ci.org/tdegrunt/jsonschema.svg)](http://travis-ci.org/tdegrunt/jsonschema) | ||
``` | ||
Returned ValidatorResult object, will show this example is NOT valid since: `"votes": "lots"` is not an integer. | ||
### Example for Array schema | ||
@@ -272,3 +274,31 @@ | ||
``` | ||
### Disallowing unknown attributes | ||
Sometimes you may want to disallow unknown attributes passed in the body of the request, in order to disallow those unknown attributes before the validation of the body, you need to set additionalProperties to false. | ||
```javascript | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Accounting Resource - Add Item", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"itemNumber": { | ||
"type":"string" | ||
}, | ||
"title": { | ||
"type":"string" | ||
}, | ||
"description": { | ||
"type":"string" | ||
} | ||
}, | ||
"required": [ | ||
"itemNumber", | ||
"title", | ||
"description" | ||
] | ||
} | ||
``` | ||
### Default base URI | ||
@@ -275,0 +305,0 @@ |
@@ -69,3 +69,3 @@ { | ||
"dependencies": { | ||
"jsonschema": "^1.4.1", | ||
"jsonschema": "^1.5.0", | ||
"semver": "^7.6.3" | ||
@@ -84,3 +84,3 @@ }, | ||
"homepage": "https://github.com/cdklabs/cloud-assembly-schema", | ||
"version": "39.1.38", | ||
"version": "39.1.39", | ||
"types": "lib/index.d.ts", | ||
@@ -87,0 +87,0 @@ "stability": "stable", |
Sorry, the diff of this file is not supported yet
632857
8280
Updatedjsonschema@^1.5.0