From 1f855f7bb943038ae808b3243e1364cbbfdd1a60 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 20 Dec 2016 00:28:39 +0200 Subject: [PATCH 01/10] Update changelogs --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e6f9828..f37eb230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 1.6.2 (2016-12-19) +### Bug fixes +* Disable side-menu animation (workaround for [#162](https://github.com/Rebilly/ReDoc/issues/162)) +* Use markdown for response description (fixes [#158](https://github.com/Rebilly/ReDoc/issues/158)) +* Fix leaks (fixes [#167](https://github.com/Rebilly/ReDoc/issues/167)) +* Update webpack and stick to ts@2.0.9 (fixes [#169](https://github.com/Rebilly/ReDoc/issues/169), [#168](https://github.com/Rebilly/ReDoc/issues/168)) + +### Features/Improvements +* add `expand-responses` option - specify which responses are expand by default ([#165](https://github.com/Rebilly/ReDoc/issues/165)). + # 1.6.2 (2016-12-11) ### Bug fixes * Use markdown in responses description ([#158](https://github.com/Rebilly/ReDoc/issues/158)) From ab002ba113138aba8e7e919b5ee2b7b53367f1f8 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 20 Dec 2016 00:32:29 +0200 Subject: [PATCH 02/10] Fix crash on MS Edge (fixes #166) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbab5615..74da8520 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "remarkable": "^1.6.2", "scrollparent": "^1.0.0", "slugify": "^1.0.2", - "stream-http": "^2.3.1" + "stream-http": "^2.5.0" }, "peerDependencies": { "@angular/common": "^2.3.1", From 0c8f5d5c2122d054f7468823ed929e918cdbed65 Mon Sep 17 00:00:00 2001 From: Adrien Gallou Date: Tue, 20 Dec 2016 10:09:55 +0100 Subject: [PATCH 03/10] fix version number in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f37eb230..6f2aba7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.6.2 (2016-12-19) +# 1.6.3 (2016-12-19) ### Bug fixes * Disable side-menu animation (workaround for [#162](https://github.com/Rebilly/ReDoc/issues/162)) * Use markdown for response description (fixes [#158](https://github.com/Rebilly/ReDoc/issues/158)) From 4e1fe68abb4b387a81ee627fa62a03514e17957f Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 22 Dec 2016 01:32:16 +0200 Subject: [PATCH 04/10] update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 01e1272c..045d5fea 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ lib/**/*.css # files produced by ngc lib/**/*.ngfactory.ts lib/**/*.css.shim.ts -lib/**/*.ngsummary.json +**/*.ngsummary.json lib/**/*.shim.ngstyle.ts # other From 1c5ef2e2b31ac8690acaff2946ce1e2976165bea Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 22 Dec 2016 01:32:34 +0200 Subject: [PATCH 05/10] update dependecies --- package.json | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 74da8520..22c724c2 100644 --- a/package.json +++ b/package.json @@ -45,13 +45,13 @@ "author": "Roman Hotsiy", "license": "MIT", "devDependencies": { - "@angular/common": "^2.3.1", - "@angular/compiler": "^2.3.1", - "@angular/compiler-cli": "^2.3.1", - "@angular/core": "^2.3.1", - "@angular/platform-browser": "^2.3.1", - "@angular/platform-browser-dynamic": "^2.3.1", - "@angular/platform-server": "^2.3.1", + "@angular/common": "^2.4.0", + "@angular/compiler": "^2.4.0", + "@angular/compiler-cli": "^2.4.0", + "@angular/core": "^2.4.0", + "@angular/platform-browser": "^2.4.0", + "@angular/platform-browser-dynamic": "^2.4.0", + "@angular/platform-server": "^2.4.0", "@types/core-js": "^0.9.31", "@types/jasmine": "^2.2.32", "@types/requirejs": "^2.1.26", @@ -60,7 +60,7 @@ "awesome-typescript-loader": "^2.2.4", "branch-release": "^1.0.3", "chalk": "^1.1.3", - "codelyzer": "^2.0.0-beta.3", + "codelyzer": "^2.0.0-beta.4", "core-js": "^2.4.1", "coveralls": "^2.11.9", "css-loader": "^0.26.0", @@ -81,11 +81,11 @@ "karma-sinon": "^1.0.4", "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^1.8.0", - "node-sass": "^3.11.2", + "node-sass": "^4.1.1", "phantomjs-prebuilt": "^2.1.7", "protractor": "^4.0.10", "raw-loader": "^0.5.1", - "rxjs": "^5.0.0-rc.4", + "rxjs": "^5.0.1", "sass-loader": "^4.0.2", "shelljs": "^0.7.0", "should": "^11.1.0", @@ -113,14 +113,14 @@ "stream-http": "^2.5.0" }, "peerDependencies": { - "@angular/common": "^2.3.1", - "@angular/compiler": "^2.3.1", - "@angular/core": "^2.3.1", - "@angular/platform-browser": "^2.3.1", - "@angular/platform-browser-dynamic": "^2.3.1", - "@angular/platform-server": "^2.3.1", + "@angular/common": "^2.4.0", + "@angular/compiler": "^2.4.0", + "@angular/core": "^2.4.0", + "@angular/platform-browser": "^2.4.0", + "@angular/platform-browser-dynamic": "^2.4.0", + "@angular/platform-server": "^2.4.0", "core-js": "^2.4.1", - "rxjs": "5.0.0-rc.4", + "rxjs": "^5.0.1", "zone.js": "^0.7.2" } } From 17fd100da45026c2b11fd5c77048f1745bc3c20d Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 22 Dec 2016 01:35:43 +0200 Subject: [PATCH 06/10] Uncomment animation after upgrage to latest ng2 (resolves #162) --- lib/components/SideMenu/side-menu.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/components/SideMenu/side-menu.ts b/lib/components/SideMenu/side-menu.ts index 3a6bc0fc..63a36c59 100644 --- a/lib/components/SideMenu/side-menu.ts +++ b/lib/components/SideMenu/side-menu.ts @@ -21,10 +21,9 @@ const global = window; style({ height: '0px' })), state('expanded', style({ height: '*' })), - // https://github.com/Rebilly/ReDoc/issues/162 - // transition('collapsed <=> expanded', [ - // animate('200ms ease') - // ]) + transition('collapsed <=> expanded', [ + animate('200ms ease') + ]) ]) ], }) From d3af2e68675df38f9d69661a91bb988d6b74dd54 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 23 Dec 2016 00:40:41 +0200 Subject: [PATCH 07/10] Fix minor issue in webpack dev config --- build/webpack.dev.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/webpack.dev.js b/build/webpack.dev.js index e7b24293..ca8cf7c7 100644 --- a/build/webpack.dev.js +++ b/build/webpack.dev.js @@ -75,13 +75,13 @@ module.exports = { loader: StringReplacePlugin.replace({ replacements: [ { - pattern: /styleUrls:\s*\[\s*'([\w\.\/-]*)\.css'\s*\][\s,]*$/m, + pattern: /styleUrls:\s*\[\s*'([\w\.\/-]*)\.css'\s*\][\s,]*$/gm, replacement: function (match, p1, offset, string) { return `styleUrls: ['${p1}.scss'],`; } }, { - pattern: /(\.\/components\/Redoc\/redoc-initial-styles\.css)/m, + pattern: /(\.\/components\/Redoc\/redoc-initial-styles\.css)/gm, replacement: function (match, p1, offset, string) { return p1.replace('.css', '.scss'); } From 86c0dcbfe1027b8d9f739b9039c4077b90fb2e43 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 28 Dec 2016 14:04:57 +0200 Subject: [PATCH 08/10] Support inherited discriminator (only one at the moment) --- lib/components/JsonSchema/json-schema.ts | 17 +++++---- lib/components/SchemaSample/schema-sample.ts | 4 +-- lib/utils/spec-manager.ts | 38 ++++++++++++++++++-- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts index 19ec9449..323cf8af 100644 --- a/lib/components/JsonSchema/json-schema.ts +++ b/lib/components/JsonSchema/json-schema.ts @@ -45,8 +45,8 @@ export class JsonSchema extends BaseComponent implements OnInit { }); activeDescendant.active = true; - this.pointer = activeDescendant.$ref; - this.schema = this.specMgr.byPointer(this.pointer); + this.schema = this.specMgr.getDescendant(activeDescendant, this.componentSchema); + this.pointer = this.schema._pointer || activeDescendant.$ref; this.normalizer.reset(); this.schema = this.normalizer.normalize(this.schema, this.normPointer, {resolved: true}); @@ -54,19 +54,22 @@ export class JsonSchema extends BaseComponent implements OnInit { } initDescendants() { - this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer); + this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer, this.schema); if (!this.descendants.length) return; this.hasDescendants = true; let discriminator = this.schema.discriminator || this.schema['x-extendedDiscriminator']; - let discrProperty = this.schema._properties && - this.schema._properties.filter((prop) => prop.name === discriminator)[0]; + let discrProperty = this.schema.properties && + this.schema.properties[discriminator]; if (discrProperty && discrProperty.enum) { let enumOrder = {}; discrProperty.enum.forEach((enumItem, idx) => { - enumOrder[enumItem.val] = idx; + enumOrder[enumItem] = idx; }); - this.schema._descendants.sort((a, b) => { + this.descendants = this.descendants + .filter(a => { + return enumOrder[a.name] != undefined; + }).sort((a, b) => { return enumOrder[a.name] > enumOrder[b.name] ? 1 : -1; }); } diff --git a/lib/components/SchemaSample/schema-sample.ts b/lib/components/SchemaSample/schema-sample.ts index 40cedfff..79a533d2 100644 --- a/lib/components/SchemaSample/schema-sample.ts +++ b/lib/components/SchemaSample/schema-sample.ts @@ -51,11 +51,11 @@ export class SchemaSample extends BaseComponent implements OnInit { let discriminator = this.componentSchema.discriminator || this.componentSchema['x-discriminatorBasePointer']; if (discriminator) { - let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer); + let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer, this.componentSchema); if (descendants.length) { // TODO: sync up with dropdown selectedDescendant = descendants[0]; - let descSchema = this.specMgr.byPointer(selectedDescendant.$ref); + let descSchema = this.specMgr.getDescendant(selectedDescendant, this.componentSchema); this.componentSchema = this._normalizer.normalize(Object.assign({}, descSchema), selectedDescendant.$ref, {omitParent: false}); } diff --git a/lib/utils/spec-manager.ts b/lib/utils/spec-manager.ts index 7a9e3c94..e9356895 100644 --- a/lib/utils/spec-manager.ts +++ b/lib/utils/spec-manager.ts @@ -7,6 +7,10 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { MdRenderer } from './md-renderer'; +function getDiscriminator(obj) { + return obj.discriminator || obj['x-extendedDiscriminator']; +} + export class SpecManager { public _schema: any = {}; public apiUrl: string; @@ -158,8 +162,8 @@ export class SpecManager { return tagsMap; } - findDerivedDefinitions(defPointer) { - let definition = this.byPointer(defPointer); + findDerivedDefinitions(defPointer, schema) { + let definition = schema || this.byPointer(defPointer); if (!definition) throw new Error(`Can't load schema at ${defPointer}`); if (!definition.discriminator && !definition['x-extendedDiscriminator']) return []; @@ -172,7 +176,20 @@ export class SpecManager { !def['x-derived-from']) continue; let subTypes = def['x-derived-from'] || def.allOf.map(subType => subType._pointer || subType.$ref); - let idx = subTypes.findIndex(ref => ref === defPointer); + + let pointers; + if (definition['x-derived-from']) { + pointers = [defPointer, ...definition['x-derived-from']]; + } else { + pointers = [defPointer]; + } + let idx = -1; + + for (let ptr of pointers) { + idx = subTypes.findIndex(ref => ptr && ref === ptr); + if (idx >= 0) break; + } + if (idx < 0) continue; let derivedName = defName; @@ -188,4 +205,19 @@ export class SpecManager { return res; } + getDescendant(descendant, componentSchema) { + let res; + if (!getDiscriminator(componentSchema) && componentSchema.allOf) { + // discriminator inherited from parents + // only one discriminator and only one level of inheritence is supported at the moment + res = Object.assign({}, componentSchema); + let idx = res.allOf.findIndex(subSpec => !!getDiscriminator(subSpec)); + res.allOf[idx] = this.byPointer(descendant.$ref); + } else { + // this.pointer = activeDescendant.$ref; + res = this.byPointer(descendant.$ref); + } + return res; + } + } From 892d4f0082be5407ac84904fef99035968f5971d Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 28 Dec 2016 15:11:43 +0200 Subject: [PATCH 09/10] disable cors for dev demopage --- demo/index.html | 3 +++ demo/main.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/demo/index.html b/demo/index.html index 55ce64f3..ee983bf4 100644 --- a/demo/index.html +++ b/demo/index.html @@ -24,6 +24,9 @@ + diff --git a/demo/main.js b/demo/main.js index 1255acf6..80bc6cb2 100644 --- a/demo/main.js +++ b/demo/main.js @@ -7,7 +7,8 @@ var url = window.location.search.match(/url=([^&]+)/); if (url && url.length > 1) { url = decodeURIComponent(url[1]); - document.getElementsByTagName('redoc')[0].setAttribute('spec-url', '\\\\cors.apis.guru/' + url); + url = window.__REDOC_DEV__ ? url : '\\\\cors.apis.guru/' + url; + document.getElementsByTagName('redoc')[0].setAttribute('spec-url', url); } function updateQueryStringParameter(uri, key, value) { From 77877381a872c21ad1bf39feb4399b8fe989ba9b Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 28 Dec 2016 15:12:42 +0200 Subject: [PATCH 10/10] v1.6.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 22c724c2..248cac67 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "redoc", "description": "Swagger-generated API Reference Documentation", - "version": "1.6.3", + "version": "1.6.4", "repository": { "type": "git", "url": "git://github.com/Rebilly/ReDoc"