diff --git a/lib/components/ParamsList/params-list.css b/lib/components/ParamsList/params-list.css index febf6df3..1138f3e6 100644 --- a/lib/components/ParamsList/params-list.css +++ b/lib/components/ParamsList/params-list.css @@ -10,7 +10,7 @@ h4 { .param > span { padding: 5px 10px; - vertical-align: middle; + vertical-align: top; } .param-name { @@ -18,7 +18,12 @@ h4 { } .param-type { - padding: 2px 10px; background-color: #EAEAEA; border: silver 1px solid; } + +.body-schema { + display: inline-block; + vertical-align: top; + padding: 0 10px; +} diff --git a/lib/components/ParamsList/params-list.html b/lib/components/ParamsList/params-list.html index 8750f4a8..13b1114b 100644 --- a/lib/components/ParamsList/params-list.html +++ b/lib/components/ParamsList/params-list.html @@ -1,5 +1,6 @@

Parameters

No parameters +
{{param.name}} @@ -7,12 +8,14 @@ {{param.description}}
+
{{data.bodyParam.name}} - {{data.bodyParam.type}} - - {{data.bodyParam.description}} - - Body Schema would be somewhere here (unimplemented yet) +
+ + +
diff --git a/lib/components/ParamsList/params-list.js b/lib/components/ParamsList/params-list.js index f3036d4a..c613fd7c 100644 --- a/lib/components/ParamsList/params-list.js +++ b/lib/components/ParamsList/params-list.js @@ -2,11 +2,22 @@ import {JsonPointer} from '../../utils/JsonPointer'; import {RedocComponent, BaseComponent} from '../base'; +import {JsonSchemaView} from '../JsonSchemaView/json-schema-view'; + +/* inject JsonPointer into array elements */ +function injectPointers(array, root) { + if (!array) return array; + return array.map((element, idx) => { + element.$$pointer = JsonPointer.join(root, idx); + return element; + }); +} @RedocComponent({ selector: 'params-list', templateUrl: './lib/components/ParamsList/params-list.html', - styleUrls: ['./lib/components/ParamsList/params-list.css'] + styleUrls: ['./lib/components/ParamsList/params-list.css'], + directives: [JsonSchemaView] }) export class ParamsList extends BaseComponent { constructor(schemaMgr) { @@ -15,17 +26,18 @@ export class ParamsList extends BaseComponent { prepareModel() { this.data = {}; - let params = this.componentSchema || []; + let params = injectPointers(this.componentSchema, this.pointer) || []; let pathParams = this.getPathParams() || []; params = params.concat(pathParams); params = this.resolveRefs(params); this.sortParams(params); - // temporary hanlde body param + // temporary handle body param if (params.length && params[params.length - 1].in === 'body') { let bodyParam = params.pop(); bodyParam.type = bodyParam.schema.type - || `Object(${JsonPointer.baseName(bodyParam.schema.$ref)})`; + || JsonPointer.baseName(bodyParam.schema.$ref); + bodyParam.pointer = bodyParam.$$pointer; this.data.bodyParam = bodyParam; } @@ -37,10 +49,10 @@ export class ParamsList extends BaseComponent { let ptr = JsonPointer.dirName(this.pointer, 2) + '/parameters'; let pathParams = this.schemaMgr.byPointer(ptr); if (Array.isArray(pathParams)) { - return pathParams; + return injectPointers(pathParams, ptr); } if (pathParams && pathParams.$ref) { - return this.schemaMgr.byPointer(pathParams.$ref); + return injectPointers(this.schemaMgr.byPointer(pathParams.$ref), pathParams.$ref); } return []; diff --git a/lib/components/base.js b/lib/components/base.js index e4550ecc..2f4444d2 100644 --- a/lib/components/base.js +++ b/lib/components/base.js @@ -71,6 +71,7 @@ export class BaseComponent { onInit() { this.componentSchema = this.schemaMgr.byPointer(this.pointer || ''); this.prepareModel(); + this.init(); } /** @@ -78,5 +79,11 @@ export class BaseComponent { * @abstract */ prepareModel() {} + + /** + * Used to initialize component. Run after prepareModel + * @abstract + */ + init() {} } BaseComponent.parameters = [[SchemaManager]]; diff --git a/lib/utils/JsonPointer.js b/lib/utils/JsonPointer.js index bd5851cd..165bcffd 100644 --- a/lib/utils/JsonPointer.js +++ b/lib/utils/JsonPointer.js @@ -44,6 +44,20 @@ export class JsonPointer extends JsonPointerLib { } return JsonPointerLib._origParse(ptr); } + + /** + * Creates a JSON pointer path, by joining one or more tokens to a base path. + * + * @param {string} base - The base path + * @param {string|string[]} tokens - The token(s) to append (e.g. ["name", "first"]) + * @returns {string} + */ + static join(base, tokens) { + // TODO: optimize + let baseTokens = JsonPointer.parse(base); + let resTokens = baseTokens.concat(tokens); + return JsonPointer.compile(resTokens); + } } JsonPointerLib._origParse = JsonPointerLib.parse;