diff --git a/lib/utils/JsonPointer.js b/lib/utils/JsonPointer.js new file mode 100644 index 00000000..eb0e9bc2 --- /dev/null +++ b/lib/utils/JsonPointer.js @@ -0,0 +1,18 @@ +'use strict'; +import JsonPointerLib from 'json-pointer'; + +/** + * Wrapper for JsonPointer. Provides common operations + */ +export class JsonPointer extends JsonPointerLib { + + /** + * returns last JsonPointer token + * @example + * // returns subpath + * new JsonPointerHelper.dirName('/path/0/subpath') + */ + static dirName(pointer) { + return JsonPointer.parse(pointer).pop(); + } +} diff --git a/lib/utils/pipes.js b/lib/utils/pipes.js new file mode 100644 index 00000000..ed3c8ab8 --- /dev/null +++ b/lib/utils/pipes.js @@ -0,0 +1,31 @@ +'use strict'; + +import {Pipe} from 'angular2/angular2'; +import {JsonPointer} from './JsonPointer'; + +@Pipe({ + name: 'keys' +}) +export class KeysPipe { + transform(obj) { + return Object.keys(obj); + } +} + +@Pipe({ + name: 'values' +}) +export class ValuesPipe { + transform(obj) { + return Object.keys(obj).map(key => obj[key]); + } +} + +@Pipe({ + name: 'jsonPointerEscape' +}) +export class JsonPointerEscapePipe { + transform(str) { + return JsonPointer.escape(str); + } +} diff --git a/lib/utils/swagger-defs.js b/lib/utils/swagger-defs.js new file mode 100644 index 00000000..16c1afd6 --- /dev/null +++ b/lib/utils/swagger-defs.js @@ -0,0 +1,3 @@ +'use strict'; + +export var methods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch']);