From f66b194e3da222aa1ad01fb2cff1a779bc1807f0 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 30 Aug 2016 21:29:22 +0300 Subject: [PATCH 01/14] Updated README and CHANGELOG --- CHANGELOG.md | 19 +++++++++++++++++++ README.md | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 303a3214..54b9aed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# 1.2.0 (2016-08-30) +### Bug fixes +* Fix sticky sidebar top sticking (#75) +* Fix array inside objects if referenced directly (#84) +* Add banner to the bundle file (#89) +* Fix broken additionalProperties +* Fix version render issue (extra "v" letter) + +### Features/Improvements +* Change the way discriminator is rendered +* Created CDN major release 1.x.x (#87) +* Smaller bundle size (371KB gzipped) +* Better start-up time due to [AoT](http://blog.mgechev.com/2016/08/14/ahead-of-time-compilation-angular-offline-precompilation/) + +### Code refactoring +* Moved build-system to Webpack +* Moved to latest Typescript + get rid of typings +* Upgrade to the latest Angular2 RC.5 + # 1.1.2 (2016-08-21) ### Bug fixes * Revert "Fix markdown newlines to be GFM" (#82) diff --git a/README.md b/README.md index e3b12758..1002eeb2 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,9 @@ ## Releases We host latest and all the previous ReDoc releases on GitHub Pages-based **CDN**: -- `latest` release: https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js -- particular release, e.g. `v0.16.1`: https://rebilly.github.io/ReDoc/releases/v0.16.0/redoc.min.js +- particular release, e.g. `v1.2.0`: https://rebilly.github.io/ReDoc/releases/v1.2.0/redoc.min.js +- `v1.x.x` release: https://rebilly.github.io/ReDoc/releases/v1.x.x/redoc.min.js +- `latest` release: https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js **[not for production]** ## Deployment From 2be02c5aa15fb84c52d8d2e08f5dcb4cb3400653 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 30 Aug 2016 21:29:56 +0300 Subject: [PATCH 02/14] Fix broken order in discriminator dropdowns --- lib/components/JsonSchema/json-schema.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts index 1d8acc4a..cee7aa64 100644 --- a/lib/components/JsonSchema/json-schema.ts +++ b/lib/components/JsonSchema/json-schema.ts @@ -53,6 +53,20 @@ export class JsonSchema extends BaseComponent implements OnInit { initDescendants() { this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer); + if (!this.descendants.length) return; + let discriminator = this.schema.discriminator; + let discrProperty = this.schema._properties && + this.schema._properties.filter((prop) => prop.name === discriminator)[0]; + if (discrProperty && discrProperty.enum) { + let enumOrder = {}; + discrProperty.enum.forEach((enumItem, idx) => { + enumOrder[enumItem.val] = idx; + }); + + this.schema._descendants.sort((a, b) => { + return enumOrder[a.name] > enumOrder[b.name] ? 1 : -1; + }); + } this.selectDescendant(0); } From 1f53d9405393672e7817a33fcafbf5a8b9269a6a Mon Sep 17 00:00:00 2001 From: kedashoe Date: Wed, 31 Aug 2016 10:20:11 -0700 Subject: [PATCH 03/14] give type "string" for pipe transforms --- lib/utils/pipes.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/utils/pipes.ts b/lib/utils/pipes.ts index 3e2c8328..516fcec5 100644 --- a/lib/utils/pipes.ts +++ b/lib/utils/pipes.ts @@ -41,7 +41,7 @@ export class ValuesPipe implements PipeTransform { @Pipe({ name: 'jsonPointerEscape' }) export class JsonPointerEscapePipe implements PipeTransform { - transform(value) { + transform(value:string) { if (isBlank(value)) return value; if (!isString(value)) { throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value); @@ -53,7 +53,7 @@ export class JsonPointerEscapePipe implements PipeTransform { @Pipe({ name: 'marked' }) export class MarkedPipe implements PipeTransform { constructor(private sanitizer: DomSanitizationService) {} - transform(value) { + transform(value:string) { if (isBlank(value)) return value; if (!isString(value)) { throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value); @@ -68,7 +68,7 @@ export class MarkedPipe implements PipeTransform { @Pipe({ name: 'safe' }) export class SafePipe implements PipeTransform { constructor(private sanitizer: DomSanitizationService) {} - transform(value) { + transform(value:string) { if (isBlank(value)) return value; if (!isString(value)) { throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value); @@ -109,7 +109,7 @@ export class PrismPipe implements PipeTransform { @Pipe({ name: 'encodeURIComponent' }) export class EncodeURIComponentPipe implements PipeTransform { - transform(value) { + transform(value:string) { if (isBlank(value)) return value; if (!isString(value)) { throw new InvalidPipeArgumentException(EncodeURIComponentPipe, value); From 027cdc19c8fec61de64c5522fcf9a9db622d20d6 Mon Sep 17 00:00:00 2001 From: kedashoe Date: Wed, 31 Aug 2016 11:35:51 -0700 Subject: [PATCH 04/14] support "x-nullable" property --- demo/swagger.yaml | 1 + lib/components/JsonSchema/_json-schema-common.scss | 8 ++++++++ lib/components/JsonSchema/json-schema.html | 1 + lib/services/schema-helper.service.ts | 1 + 4 files changed, 11 insertions(+) diff --git a/demo/swagger.yaml b/demo/swagger.yaml index 47cad699..86abb4f6 100644 --- a/demo/swagger.yaml +++ b/demo/swagger.yaml @@ -819,6 +819,7 @@ definitions: type: string pattern: "^\\+(?:[0-9]-?){6,14}[0-9]$" example: +1-202-555-0192 + x-nullable: true userStatus: description: User status type: integer diff --git a/lib/components/JsonSchema/_json-schema-common.scss b/lib/components/JsonSchema/_json-schema-common.scss index 26b41559..d50ad788 100644 --- a/lib/components/JsonSchema/_json-schema-common.scss +++ b/lib/components/JsonSchema/_json-schema-common.scss @@ -63,6 +63,14 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin; font-weight: bold; } +.param-nullable { + vertical-align: middle; + line-height: $param-name-height; + color: #3195a6; + font-size: 12px; + font-weight: bold; +} + .param-type { vertical-align: middle; line-height: $param-name-height; diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index 9b16818d..e5228e5f 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -70,6 +70,7 @@ {{prop._range}} Required + Nullable
Default: {{prop.default | json}}
{{enumItem.val | json}} diff --git a/lib/services/schema-helper.service.ts b/lib/services/schema-helper.service.ts index c812f9e7..d0de7761 100644 --- a/lib/services/schema-helper.service.ts +++ b/lib/services/schema-helper.service.ts @@ -229,6 +229,7 @@ export class SchemaHelper { propertySchema._pointer = null; } propertySchema._required = !!requiredMap[propName]; + propertySchema._nullable = !!propertySchema['x-nullable']; propertySchema.isDiscriminator = (schema.discriminator === propName); return propertySchema; }); From acaf54b28ffd31d9606d5d153a669d532e164804 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 20:41:13 +0300 Subject: [PATCH 05/14] Fix code samples are not shown for operations without body param (#93) --- lib/components/Method/method.html | 5 ++--- lib/components/Method/method.scss | 1 + lib/components/RequestSamples/request-samples.html | 4 ++-- lib/components/RequestSamples/request-samples.ts | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/components/Method/method.html b/lib/components/Method/method.html index d4347097..20d908a5 100644 --- a/lib/components/Method/method.html +++ b/lib/components/Method/method.html @@ -22,9 +22,8 @@ -->
-
-
- +
+
diff --git a/lib/components/Method/method.scss b/lib/components/Method/method.scss index 2fcadd4b..af11795f 100644 --- a/lib/components/Method/method.scss +++ b/lib/components/Method/method.scss @@ -5,6 +5,7 @@ padding-bottom: 100px; display: block; border-bottom: 1px solid rgba(127, 127, 127, 0.25); + margin-top: 1em; } :host:last-of-type { diff --git a/lib/components/RequestSamples/request-samples.html b/lib/components/RequestSamples/request-samples.html index ea370552..8f4956cd 100644 --- a/lib/components/RequestSamples/request-samples.html +++ b/lib/components/RequestSamples/request-samples.html @@ -1,7 +1,7 @@
Request samples
- + - + diff --git a/lib/components/RequestSamples/request-samples.ts b/lib/components/RequestSamples/request-samples.ts index 159d291d..14651d54 100644 --- a/lib/components/RequestSamples/request-samples.ts +++ b/lib/components/RequestSamples/request-samples.ts @@ -1,7 +1,7 @@ 'use strict'; import { Component, ViewChildren, QueryList, EventEmitter, Input, - ChangeDetectionStrategy, OnInit } from '@angular/core'; + ChangeDetectionStrategy, OnInit, HostBinding } from '@angular/core'; import { BaseComponent, SpecManager } from '../base'; import JsonPointer from '../../utils/JsonPointer'; @@ -18,6 +18,7 @@ export class RequestSamples extends BaseComponent implements OnInit { @Input() pointer:string; @Input() schemaPointer:string; @ViewChildren(Tabs) childQuery:QueryList; + @HostBinding('attr.hidden') hidden; childTabs: Tabs; selectedLang: EventEmitter; @@ -35,8 +36,9 @@ export class RequestSamples extends BaseComponent implements OnInit { } init() { - this.schemaPointer = JsonPointer.join(this.schemaPointer, 'schema');; + this.schemaPointer = this.schemaPointer ? JsonPointer.join(this.schemaPointer, 'schema') : null; this.samples = this.componentSchema['x-code-samples'] || []; + if (!this.schemaPointer && !this.samples.length) this.hidden = true; } ngOnInit() { From b2cd855aa8418cf69adf55caabf70f9ba7666534 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 21:58:55 +0300 Subject: [PATCH 06/14] Make e2e less verbose + minor fixes --- lib/components/JsonSchema/json-schema.ts | 1 + package.json | 3 ++- tests/e2e/helpers.js | 3 ++- tests/e2e/index.html | 2 +- tests/e2e/redoc.e2e.js | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts index cee7aa64..3bb1c3c6 100644 --- a/lib/components/JsonSchema/json-schema.ts +++ b/lib/components/JsonSchema/json-schema.ts @@ -54,6 +54,7 @@ export class JsonSchema extends BaseComponent implements OnInit { initDescendants() { this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer); if (!this.descendants.length) return; + this.hasDescendants = true; let discriminator = this.schema.discriminator; let discrProperty = this.schema._properties && this.schema._properties.filter((prop) => prop.name === discriminator)[0]; diff --git a/package.json b/package.json index 12c91f33..5ae87004 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "e2e-server": "http-server -p 3000 tests/e2e", "e2e-copy": "cp dist/redoc.min.js tests/e2e/", "webdriver": "webdriver-manager update", - "serve:prod": "NODE_ENV=production npm start" + "serve:prod": "NODE_ENV=production npm start", + "protractor": "protractor" }, "keywords": [ "OpenAPI", diff --git a/tests/e2e/helpers.js b/tests/e2e/helpers.js index 16aeedd1..4c00744b 100644 --- a/tests/e2e/helpers.js +++ b/tests/e2e/helpers.js @@ -51,7 +51,8 @@ function verifyNoBrowserErrors() { if (message.match(/^Unknown property.*Declaration dropped/)) return false; if (message.match(/^Error in parsing value for.*Declaration dropped/)) return false; if (message.indexOf('The character encoding of the HTML document was not declared') > -1) return false; - if (message.match(/addons.manager\s+DEBUG/)) return false; + if (message.match(/^\d{13}\s+(DeferredSave|addons)/)) return false; + if (message.match(/This site makes use of a SHA-1 Certificate/)) return false; if (logEntry.level.value >= LogLevel.INFO) { diff --git a/tests/e2e/index.html b/tests/e2e/index.html index 2c62cec6..2653b34f 100644 --- a/tests/e2e/index.html +++ b/tests/e2e/index.html @@ -15,7 +15,7 @@ window.redocError = null; /* init redoc */ var url = window.location.search.substr(5) || 'http://rebilly.github.io/SwaggerTemplateRepo/swagger.json'; - Redoc.init(decodeURIComponent(url), {disableLazySchemas: true}).then(function() {}, function(err) { + Redoc.init(decodeURIComponent(url), {disableLazySchemas: true, suppressWarnings: true}).then(function() {}, function(err) { window.redocError = err; }); diff --git a/tests/e2e/redoc.e2e.js b/tests/e2e/redoc.e2e.js index 01c5e940..eaf250e3 100644 --- a/tests/e2e/redoc.e2e.js +++ b/tests/e2e/redoc.e2e.js @@ -91,6 +91,7 @@ if (process.env.JOB === 'e2e-guru') { delete apisGuruList['googleapis.com:mirror']; // bad urls in images delete apisGuruList['googleapis.com:discovery']; // non-string references delete apisGuruList['clarify.io']; // non-string references + delete apisGuruList['clickmeter.com']; // some complex circular reference //delete apisGuruList['pushpay.com']; // https://github.com/Rebilly/ReDoc/issues/30 delete apisGuruList['bbci.co.uk']; // too big From 40c40cd3276f589155a806c59e778a79eea0971a Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 22:45:34 +0300 Subject: [PATCH 07/14] Add x-nullable to the docs --- README.md | 1 + docs/redoc-vendor-extensions.md | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 1002eeb2..f378ba91 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ ReDoc makes use of the following [vendor extensions](http://swagger.io/specifica * [`x-logo`](docs/redoc-vendor-extensions.md#x-logo) - is used to specify API logo * [`x-traitTag`](docs/redoc-vendor-extensions.md#x-traitTag) - useful for handling out common things like Pagination, Rate-Limits, etc * [`x-code-samples`](docs/redoc-vendor-extensions.md#x-code-samples) - specify operation code samples +* [`x-nullable`](docs/redoc-vendor-extensions.md#nullable) - mark schema param as a nullable ### `` tag attributes * `spec-url` - relative or absolute url to your spec file; diff --git a/docs/redoc-vendor-extensions.md b/docs/redoc-vendor-extensions.md index 9f9ea251..e12ef1e5 100644 --- a/docs/redoc-vendor-extensions.md +++ b/docs/redoc-vendor-extensions.md @@ -106,3 +106,13 @@ yaml lang: JavaScript source: console.log('Hello World'); ``` + +### Schema Object vendor extensions +Extends OpenAPI [Schema Object](http://swagger.io/specification/#schemaObject) +#### x-code-samples +| Field Name | Type | Description | +| :------------- | :------: | :---------- | +| x-nullable | boolean | marks schema as a nullable | + +###### Usage in ReDoc +Schemas marked as `x-nullable` are marked in ReDoc with the label Nullable From b649d52c39d46f7053d8e008f2ec940e4eb5a6c8 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 22:45:59 +0300 Subject: [PATCH 08/14] x-nullable support for non-object schemas --- lib/components/JsonSchema/json-schema.html | 3 ++- lib/services/schema-helper.service.ts | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index e5228e5f..ff4000ac 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -21,6 +21,7 @@ title="{{schema._displayTypeHint}}">{{schema._displayType}} {{schema._displayFormat}} {{schema._range}} + Nullable
{{enumItem.val | json}}
@@ -70,7 +71,7 @@ {{prop._range}} Required - Nullable + Nullable
Default: {{prop.default | json}}
{{enumItem.val | json}} diff --git a/lib/services/schema-helper.service.ts b/lib/services/schema-helper.service.ts index d0de7761..315761fd 100644 --- a/lib/services/schema-helper.service.ts +++ b/lib/services/schema-helper.service.ts @@ -163,7 +163,7 @@ const injectors = { range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ]`; } else if (propertySchema.maxLength) { range = '<= ' + propertySchema.maxLength; - } else if (propertySchema.minimum) { + } else if (propertySchema.minLength) { range = '>= ' + propertySchema.minLength; } @@ -229,7 +229,6 @@ export class SchemaHelper { propertySchema._pointer = null; } propertySchema._required = !!requiredMap[propName]; - propertySchema._nullable = !!propertySchema['x-nullable']; propertySchema.isDiscriminator = (schema.discriminator === propName); return propertySchema; }); From a8d98b127be770063ea5ac199f3c550a0943eb75 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 23:34:14 +0300 Subject: [PATCH 09/14] Fixed side menu overlapped site footer (#75) --- .../StickySidebar/sticky-sidebar.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/shared/components/StickySidebar/sticky-sidebar.ts b/lib/shared/components/StickySidebar/sticky-sidebar.ts index 9482697e..5fb15a20 100644 --- a/lib/shared/components/StickySidebar/sticky-sidebar.ts +++ b/lib/shared/components/StickySidebar/sticky-sidebar.ts @@ -32,11 +32,24 @@ export class StickySidebar implements OnInit, OnDestroy { } updatePosition() { + var stuck = false; if ( this.scrollY + this.scrollYOffset() >= this.$redocEl.offsetTop) { this.stick(); + stuck = true; } else { this.unstick(); } + + if ( this.scrollY + window.innerHeight - this.scrollYOffset() >= this.$redocEl.scrollHeight) { + this.stickBottom(); + stuck = true; + } else { + this.unstickBottom(); + } + + if (!stuck) { + DOM.setStyle(this.$element, 'position', 'absolute'); + } } stick() { @@ -45,19 +58,33 @@ export class StickySidebar implements OnInit, OnDestroy { } unstick() { - DOM.setStyle(this.$element, 'position', 'absolute'); DOM.setStyle(this.$element, 'top', '0'); } + stickBottom() { + DOM.setStyle(this.$element, 'position', 'fixed'); + var offset = this.scrollY + this.scrollParentHeight - (this.$redocEl.scrollHeight + this.$redocEl.offsetTop); + DOM.setStyle(this.$element, 'bottom', offset + 'px'); + } + + unstickBottom() { + DOM.setStyle(this.$element, 'bottom', '0'); + } + get scrollY() { return (this.scrollParent.pageYOffset != undefined) ? this.scrollParent.pageYOffset : this.scrollParent.scrollTop; } + get scrollParentHeight() { + return (this.scrollParent.innerHeight != undefined) ? this.scrollParent.innerHeight : this.scrollParent.clientHeight; + } + ngOnInit() { // FIXME use more reliable code this.$redocEl = this.$element.offsetParent.parentNode || DOM.defaultDoc().body; this.bind(); - this.updatePosition(); + setTimeout(() => this.updatePosition()); + //this.updatePosition() } ngOnDestroy() { From 4066362ab96ec38acd451a2322bb00e059e2d524 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 23:51:56 +0300 Subject: [PATCH 10/14] Add + fix tests --- lib/components/JsonSchema/json-schema.html | 2 +- .../StickySidebar/sticky-sidebar.spec.ts | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index ff4000ac..c7865ff6 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -21,7 +21,7 @@ title="{{schema._displayTypeHint}}">{{schema._displayType}} {{schema._displayFormat}} {{schema._range}} - Nullable + Nullable
{{enumItem.val | json}}
diff --git a/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts b/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts index 14a86ecd..43bbaf2e 100644 --- a/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts +++ b/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts @@ -27,10 +27,23 @@ describe('Common components', () => { expect(component).not.toBeNull(); }); - it('should start sticked', () => { + it('should start unsticked', () => { spyOn(component, 'stick').and.callThrough(); + spyOn(component, 'stickBottom').and.callThrough(); fixture.detectChanges(); - expect(component.stick).toHaveBeenCalled(); + expect(component.stick).not.toHaveBeenCalled(); + expect(component.stickBottom).not.toHaveBeenCalled(); + }); + + it('should stick to the top on the next VM tick', (done) => { + spyOn(component, 'stick').and.callThrough(); + spyOn(component, 'stickBottom').and.callThrough(); + fixture.detectChanges(); + setTimeout(() => { + expect(component.stick).toHaveBeenCalled(); + expect(component.stickBottom).toHaveBeenCalled(); + done(); + }); }); it('should stick if scrolled more than scrollYOffset', () => { @@ -42,6 +55,8 @@ describe('Common components', () => { component.updatePosition(); expect(component.stick).toHaveBeenCalled(); }); + + // TODO: add tests for stickBottom }); }); From 74d384086ffa3c76877ee9a5b0a00a406c0ac33b Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 23:52:54 +0300 Subject: [PATCH 11/14] Not run extra prod build on simple CI run --- .travis.yml | 2 -- package.json | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc55b556..3cf9427d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,8 +31,6 @@ before_script: - sleep 3 # give server time to start after_script: - kill %1 # kill e2e server -before_deploy: -- npm run build-dist deploy: - provider: npm skip_cleanup: true diff --git a/package.json b/package.json index 5ae87004..fa7e9d6d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "main": "dist/redoc.min.js", "scripts": { "test": "npm run lint && node ./build/run_tests.js", + "prepublish": "npm run build:prod", "branch-release": "git reset --hard && branch-release", "lint": "tslint -e \"lib/**/*{ngfactory|css.shim}.ts\" lib/**/*.ts", "unit": "npm run build:sass && karma start", From 34d8230f8be76685a699c964c52d10c274ef7a11 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 31 Aug 2016 23:56:26 +0300 Subject: [PATCH 12/14] Revert "Not run extra prod build on simple CI run" - npm runs prebublish on install :( This reverts commit 74d384086ffa3c76877ee9a5b0a00a406c0ac33b. --- .travis.yml | 2 ++ package.json | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3cf9427d..bc55b556 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,8 @@ before_script: - sleep 3 # give server time to start after_script: - kill %1 # kill e2e server +before_deploy: +- npm run build-dist deploy: - provider: npm skip_cleanup: true diff --git a/package.json b/package.json index fa7e9d6d..5ae87004 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "main": "dist/redoc.min.js", "scripts": { "test": "npm run lint && node ./build/run_tests.js", - "prepublish": "npm run build:prod", "branch-release": "git reset --hard && branch-release", "lint": "tslint -e \"lib/**/*{ngfactory|css.shim}.ts\" lib/**/*.ts", "unit": "npm run build:sass && karma start", From d3ef8f003c6d511f47f874ad37ea9da6740ca870 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 1 Sep 2016 09:53:42 +0300 Subject: [PATCH 13/14] Fix e2e tests + minor refactoring --- lib/components/JsonSchema/json-schema-lazy.ts | 2 +- lib/components/JsonSchema/json-schema.ts | 5 +++-- lib/components/ParamsList/params-list.html | 2 +- lib/components/ParamsList/params-list.ts | 1 - lib/services/schema-normalizer.service.ts | 18 ++++++++++++++---- tests/e2e/redoc.e2e.js | 1 - 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/components/JsonSchema/json-schema-lazy.ts b/lib/components/JsonSchema/json-schema-lazy.ts index edbea22f..80dc3f63 100644 --- a/lib/components/JsonSchema/json-schema-lazy.ts +++ b/lib/components/JsonSchema/json-schema-lazy.ts @@ -46,7 +46,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit { } load() { - if (this.optionsService.options.disableLazySchemas) return; + if (this.disableLazy) return; if (this.loaded) return; if (this.pointer) { this._loadAfterSelf(); diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts index 3bb1c3c6..6cc6642d 100644 --- a/lib/components/JsonSchema/json-schema.ts +++ b/lib/components/JsonSchema/json-schema.ts @@ -47,7 +47,8 @@ export class JsonSchema extends BaseComponent implements OnInit { this.pointer = activeDescendant.$ref; this.schema = this.specMgr.byPointer(this.pointer); - this.schema = this.normalizer.normalize(this.schema, this.normPointer, {omitParent: false}); + this.schema = this.normalizer.normalize(this.schema, this.normPointer, + {resolved: true}); this.preprocessSchema(); } @@ -80,7 +81,7 @@ export class JsonSchema extends BaseComponent implements OnInit { this.applyStyling(); - this.schema = this.normalizer.normalize(this.schema, this.normPointer); + this.schema = this.normalizer.normalize(this.schema, this.normPointer, {resolved: true}); this.schema = SchemaHelper.unwrapArray(this.schema, this.normPointer); this.initDescendants(); this.preprocessSchema(); diff --git a/lib/components/ParamsList/params-list.html b/lib/components/ParamsList/params-list.html index 6601e4dc..89211a1b 100644 --- a/lib/components/ParamsList/params-list.html +++ b/lib/components/ParamsList/params-list.html @@ -33,7 +33,7 @@

- +
diff --git a/lib/components/ParamsList/params-list.ts b/lib/components/ParamsList/params-list.ts index d21e2661..3bf40dcf 100644 --- a/lib/components/ParamsList/params-list.ts +++ b/lib/components/ParamsList/params-list.ts @@ -40,7 +40,6 @@ export class ParamsList extends BaseComponent implements OnInit { if (paramsMap.body && paramsMap.body.length) { let bodyParam = paramsMap.body[0]; - bodyParam.pointer = bodyParam._pointer; this.bodyParam = bodyParam; paramsMap.body = undefined; } diff --git a/lib/services/schema-normalizer.service.ts b/lib/services/schema-normalizer.service.ts index 73a2d4f9..8b1de77a 100644 --- a/lib/services/schema-normalizer.service.ts +++ b/lib/services/schema-normalizer.service.ts @@ -24,17 +24,20 @@ export class SchemaNormalizer { this._dereferencer = new SchemaDereferencer(_schema, this); } normalize(schema, ptr, opts:any ={}) { - opts.omitParent = opts.omitParent !== false; + let hasPtr = !!schema.$ref; + if (opts.resolved && !hasPtr) this._dereferencer.visit(ptr); + if (schema['x-redoc-normalized']) return schema; let res = SchemaWalker.walk(schema, ptr, (subSchema, ptr) => { let resolved = this._dereferencer.dereference(subSchema, ptr); if (resolved.allOf) { resolved._pointer = resolved._pointer || ptr; resolved = Object.assign({}, resolved); - AllOfMerger.merge(resolved, resolved.allOf, {omitParent: opts.omitParent}); + AllOfMerger.merge(resolved, resolved.allOf); } return resolved; }); + if (opts.resolved && !hasPtr) this._dereferencer.exit(ptr); res['x-redoc-normalized'] = true; return res; } @@ -88,12 +91,11 @@ class SchemaWalker { } class AllOfMerger { - static merge(into, schemas, opts) { + static merge(into, schemas) { into['x-derived-from'] = []; for (let i=0; i < schemas.length; i++) { let subSchema = schemas[i]; into['x-derived-from'].push(subSchema._pointer); - if (opts && opts.omitParent && subSchema.discriminator) continue; AllOfMerger.checkCanMerge(subSchema, into); @@ -177,6 +179,14 @@ class SchemaDereferencer { constructor(private _spec: SpecManager, private normalizator: SchemaNormalizer) { } + visit($ref) { + this._refCouner.visit($ref); + } + + exit($ref) { + this._refCouner.exit($ref); + } + dereference(schema: Reference, pointer:string):any { if (!schema || !schema.$ref) return schema; window['derefCount'] = window['derefCount'] ? window['derefCount'] + 1 : 1; diff --git a/tests/e2e/redoc.e2e.js b/tests/e2e/redoc.e2e.js index eaf250e3..01c5e940 100644 --- a/tests/e2e/redoc.e2e.js +++ b/tests/e2e/redoc.e2e.js @@ -91,7 +91,6 @@ if (process.env.JOB === 'e2e-guru') { delete apisGuruList['googleapis.com:mirror']; // bad urls in images delete apisGuruList['googleapis.com:discovery']; // non-string references delete apisGuruList['clarify.io']; // non-string references - delete apisGuruList['clickmeter.com']; // some complex circular reference //delete apisGuruList['pushpay.com']; // https://github.com/Rebilly/ReDoc/issues/30 delete apisGuruList['bbci.co.uk']; // too big From dd686004766a2cdd54dc733cb4d27b258c055e46 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 1 Sep 2016 10:08:17 +0300 Subject: [PATCH 14/14] v1.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5ae87004..a8f4db64 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "redoc", "description": "Swagger-generated API Reference Documentation", - "version": "1.2.0", + "version": "1.3.0", "repository": { "type": "git", "url": "git://github.com/Rebilly/ReDoc"