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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e6f9828..6f2aba7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 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)) +* 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)) 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'); } 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) { 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/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') + ]) ]) ], }) 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; + } + } diff --git a/package.json b/package.json index bbab5615..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" @@ -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", @@ -110,17 +110,17 @@ "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", - "@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" } }