@aws-cdk/cloud-assembly-schema 39.1.38 → 39.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.jsii CHANGED
@@ -8,7 +8,7 @@
8
8
  "url": "https://aws.amazon.com"
9
9
  },
10
10
  "bundled": {
11
- "jsonschema": "^1.4.1",
11
+ "jsonschema": "^1.5.0",
12
12
  "semver": "^7.6.3"
13
13
  },
14
14
  "description": "Cloud Assembly Schema",
@@ -5511,6 +5511,6 @@
5511
5511
  "symbolId": "lib/cloud-assembly/context-queries:VpcContextQuery"
5512
5512
  }
5513
5513
  },
5514
- "version": "39.1.38",
5515
- "fingerprint": "zx/hMM2/aPZdnNiUIyG5A3eOFR8nJDwpTg0NYmemgkM="
5514
+ "version": "39.1.39",
5515
+ "fingerprint": "1EGrfgAm+uyb/RyQdI/wfTO2vJkSbh2RfjcoyfWwk1Y="
5516
5516
  }
package/lib/manifest.js CHANGED
@@ -249,7 +249,7 @@ class Manifest {
249
249
  }
250
250
  exports.Manifest = Manifest;
251
251
  _a = JSII_RTTI_SYMBOL_1;
252
- Manifest[_a] = { fqn: "@aws-cdk/cloud-assembly-schema.Manifest", version: "39.1.38" };
252
+ Manifest[_a] = { fqn: "@aws-cdk/cloud-assembly-schema.Manifest", version: "39.1.39" };
253
253
  function mapValues(xs, fn) {
254
254
  if (!xs) {
255
255
  return undefined;
@@ -80,6 +80,8 @@ var p = {
80
80
  v.addSchema(addressSchema, '/SimpleAddress');
81
81
  console.log(v.validate(p, schema));
82
82
  ```
83
+ Returned ValidatorResult object, will show this example is NOT valid since: `"votes": "lots"` is not an integer.
84
+
83
85
  ### Example for Array schema
84
86
 
85
87
  ```json
@@ -268,6 +270,34 @@ function importNextSchema(){
268
270
  }
269
271
  importNextSchema();
270
272
  ```
273
+ ### Disallowing unknown attributes
274
+
275
+ 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.
276
+
277
+ ```javascript
278
+ {
279
+ "$schema": "http://json-schema.org/draft-04/schema#",
280
+ "title": "Accounting Resource - Add Item",
281
+ "type": "object",
282
+ "additionalProperties": false,
283
+ "properties": {
284
+ "itemNumber": {
285
+ "type":"string"
286
+ },
287
+ "title": {
288
+ "type":"string"
289
+ },
290
+ "description": {
291
+ "type":"string"
292
+ }
293
+ },
294
+ "required": [
295
+ "itemNumber",
296
+ "title",
297
+ "description"
298
+ ]
299
+ }
300
+ ```
271
301
 
272
302
  ### Default base URI
273
303
 
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var uri = require('url');
4
-
5
3
  var ValidationError = exports.ValidationError = function ValidationError (message, instance, schema, path, name, argument) {
6
4
  if(Array.isArray(path)){
7
5
  this.path = path;
@@ -84,7 +82,7 @@ Object.defineProperty(ValidatorResult.prototype, "valid", { get: function() {
84
82
 
85
83
  module.exports.ValidatorResultError = ValidatorResultError;
86
84
  function ValidatorResultError(result) {
87
- if(Error.captureStackTrace){
85
+ if(typeof Error.captureStackTrace === 'function'){
88
86
  Error.captureStackTrace(this, ValidatorResultError);
89
87
  }
90
88
  this.instance = result.instance;
@@ -105,7 +103,9 @@ var SchemaError = exports.SchemaError = function SchemaError (msg, schema) {
105
103
  this.message = msg;
106
104
  this.schema = schema;
107
105
  Error.call(this, msg);
108
- Error.captureStackTrace(this, SchemaError);
106
+ if(typeof Error.captureStackTrace === 'function'){
107
+ Error.captureStackTrace(this, SchemaError);
108
+ }
109
109
  };
110
110
  SchemaError.prototype = Object.create(Error.prototype,
111
111
  {
@@ -129,13 +129,13 @@ var SchemaContext = exports.SchemaContext = function SchemaContext (schema, opti
129
129
  };
130
130
 
131
131
  SchemaContext.prototype.resolve = function resolve (target) {
132
- return uri.resolve(this.base, target);
132
+ return (() => resolveUrl(this.base,target))();
133
133
  };
134
134
 
135
135
  SchemaContext.prototype.makeChild = function makeChild(schema, propertyName){
136
136
  var path = (propertyName===undefined) ? this.path : this.path.concat([propertyName]);
137
137
  var id = schema.$id || schema.id;
138
- var base = uri.resolve(this.base, id||'');
138
+ let base = (() => resolveUrl(this.base,id||''))();
139
139
  var ctx = new SchemaContext(schema, this.options, path, base, Object.create(this.schemas));
140
140
  if(id && !ctx.schemas[base]){
141
141
  ctx.schemas[base] = schema;
@@ -388,3 +388,19 @@ exports.isSchema = function isSchema(val){
388
388
  return (typeof val === 'object' && val) || (typeof val === 'boolean');
389
389
  };
390
390
 
391
+ /**
392
+ * Resolve target URL from a base and relative URL.
393
+ * Similar to Node's URL Lib's legacy resolve function.
394
+ * Code from example in deprecation note in said library.
395
+ * @param string
396
+ * @param string
397
+ * @returns {string}
398
+ */
399
+ var resolveUrl = exports.resolveUrl = function resolveUrl(from, to) {
400
+ const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
401
+ if (resolvedUrl.protocol === 'resolve:') {
402
+ const { pathname, search, hash } = resolvedUrl;
403
+ return pathname + search + hash;
404
+ }
405
+ return resolvedUrl.toString();
406
+ }
@@ -27,6 +27,13 @@ export declare class ValidatorResult {
27
27
  toString(): string;
28
28
  }
29
29
 
30
+ export declare class ValidatorResultError extends Error {
31
+ instance: any;
32
+ schema: Schema;
33
+ options: Options;
34
+ errors: ValidationError;
35
+ }
36
+
30
37
  export declare class ValidationError {
31
38
  constructor(message?: string, instance?: any, schema?: Schema, propertyPath?: any, name?: string, argument?: any);
32
39
  path: (string|number)[];
@@ -65,12 +72,14 @@ export interface Schema {
65
72
  pattern?: string | RegExp
66
73
  additionalItems?: boolean | Schema
67
74
  items?: Schema | Schema[]
75
+ contains?: Schema
68
76
  maxItems?: number
69
77
  minItems?: number
70
78
  uniqueItems?: boolean
71
79
  maxProperties?: number
72
80
  minProperties?: number
73
81
  required?: string[] | boolean
82
+ propertyNames?: boolean | Schema
74
83
  additionalProperties?: boolean | Schema
75
84
  definitions?: {
76
85
  [name: string]: Schema
@@ -95,6 +104,8 @@ export interface Schema {
95
104
  if?: Schema
96
105
  then?: Schema
97
106
  else?: Schema
107
+ default?: any
108
+ examples?: any[]
98
109
  }
99
110
 
100
111
  export interface Options {
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var urilib = require('url');
4
3
  var helpers = require('./helpers');
5
4
 
6
5
  module.exports.SchemaScanResult = SchemaScanResult;
@@ -20,12 +19,13 @@ module.exports.scan = function scan(base, schema){
20
19
  if(!schema || typeof schema!='object') return;
21
20
  // Mark all referenced schemas so we can tell later which schemas are referred to, but never defined
22
21
  if(schema.$ref){
23
- var resolvedUri = urilib.resolve(baseuri, schema.$ref);
22
+ let resolvedUri = helpers.resolveUrl(baseuri,schema.$ref);
24
23
  ref[resolvedUri] = ref[resolvedUri] ? ref[resolvedUri]+1 : 0;
25
24
  return;
26
25
  }
27
26
  var id = schema.$id || schema.id;
28
- var ourBase = id ? urilib.resolve(baseuri, id) : baseuri;
27
+ let resolvedBase = helpers.resolveUrl(baseuri,id);
28
+ var ourBase = id ? resolvedBase : baseuri;
29
29
  if (ourBase) {
30
30
  // If there's no fragment, append an empty one
31
31
  if(ourBase.indexOf('#')<0) ourBase += '#';
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var urilib = require('url');
4
-
5
3
  var attribute = require('./attribute');
6
4
  var helpers = require('./helpers');
7
5
  var scanSchema = require('./scan').scan;
@@ -115,7 +113,7 @@ Validator.prototype.validate = function validate (instance, schema, options, ctx
115
113
  // This section indexes subschemas in the provided schema, so they don't need to be added with Validator#addSchema
116
114
  // This will work so long as the function at uri.resolve() will resolve a relative URI to a relative URI
117
115
  var id = schema.$id || schema.id;
118
- var base = urilib.resolve(options.base||anonymousBase, id||'');
116
+ let base = helpers.resolveUrl(options.base,id||'');
119
117
  if(!ctx){
120
118
  ctx = new SchemaContext(schema, options, [], base, Object.create(this.schemas));
121
119
  if (!ctx.schemas[base]) {
@@ -262,8 +260,8 @@ Validator.prototype.resolve = function resolve (schema, switchSchema, ctx) {
262
260
  return {subschema: ctx.schemas[switchSchema], switchSchema: switchSchema};
263
261
  }
264
262
  // Else try walking the property pointer
265
- var parsed = urilib.parse(switchSchema);
266
- var fragment = parsed && parsed.hash;
263
+ let parsed = new URL(switchSchema,'thismessage::/');
264
+ let fragment = parsed.hash;
267
265
  var document = fragment && fragment.length && switchSchema.substr(0, switchSchema.length - fragment.length);
268
266
  if (!document || !ctx.schemas[document]) {
269
267
  throw new SchemaError("no such schema <" + switchSchema + ">", schema);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Tom de Grunt <tom@degrunt.nl>",
3
3
  "name": "jsonschema",
4
- "version": "1.4.1",
4
+ "version": "1.5.0",
5
5
  "license": "MIT",
6
6
  "dependencies": {},
7
7
  "contributors": [
@@ -39,4 +39,4 @@
39
39
  "stryker": "stryker run",
40
40
  "test": "./node_modules/.bin/mocha -R spec"
41
41
  }
42
- }
42
+ }
package/package.json CHANGED
@@ -66,7 +66,7 @@
66
66
  "typescript-json-schema": "^0.65.1"
67
67
  },
68
68
  "dependencies": {
69
- "jsonschema": "^1.4.1",
69
+ "jsonschema": "^1.5.0",
70
70
  "semver": "^7.6.3"
71
71
  },
72
72
  "bundledDependencies": [
@@ -80,7 +80,7 @@
80
80
  "main": "lib/index.js",
81
81
  "license": "Apache-2.0",
82
82
  "homepage": "https://github.com/cdklabs/cloud-assembly-schema",
83
- "version": "39.1.38",
83
+ "version": "39.1.39",
84
84
  "types": "lib/index.d.ts",
85
85
  "stability": "stable",
86
86
  "jsii": {