From 6a5e03cab9cf6dc17459c1fdf971059331514d55 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sat, 17 Sep 2016 09:52:57 -0400 Subject: [PATCH 1/8] Update openapi-sampler lib (#111) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0834b2cc..b803e2e9 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "hint.css": "^2.3.2", "json-pointer": "^0.5.0", "json-schema-ref-parser": "^3.1.2", - "openapi-sampler": "^0.3.0", + "openapi-sampler": "^0.3.1", "prismjs": "^1.5.1", "remarkable": "^1.6.2", "rxjs": "^5.0.0-beta.11", From 6cc525e5941dda2893fd938b26528734abcb33ac Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 20 Sep 2016 18:28:42 -0400 Subject: [PATCH 2/8] Update local dev steps (fixes #114) --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 80cf0226..63ef580d 100644 --- a/README.md +++ b/README.md @@ -126,16 +126,17 @@ Redoc.init('http://petstore.swagger.io/v2/swagger.json', { ----------- ## Development #### Running local dev-server -1. Clone repository +- Clone repository `git clone https://github.com/Rebilly/ReDoc.git` -2. Go to the project folder +- Go to the project folder `cd ReDoc` -3. Install node modules and front-end dependencies +- Install dependencies +`npm install` +- *(Temporary step, will be obsolete after fixing #97)* Compile CSS +```bash +npm run build:sass ``` -npm install -npm run jspm-install -``` -4. _(optional)_ Replace `demo/swagger.json` with your own schema -5. Start the server +- _(optional)_ Replace `demo/swagger.json` with your own schema +- Start the server `npm start` -6. Open `http://localhost:9000` +- Open `http://localhost:9000` From 546fccb7960576539e616e11705c114e34518bc7 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 27 Sep 2016 09:02:49 +0300 Subject: [PATCH 3/8] Update angular to 2.0.1 --- package.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index b803e2e9..3ed16ef9 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "author": "Roman Hotsiy", "license": "MIT", "devDependencies": { - "@angular/compiler-cli": "^0.6.0", + "@angular/compiler-cli": "^0.6.3", "@types/core-js": "^0.9.31", "@types/jasmine": "^2.2.32", "@types/requirejs": "^2.1.26", @@ -49,7 +49,7 @@ "awesome-typescript-loader": "^2.2.1", "branch-release": "^1.0.3", "chalk": "^1.1.3", - "codelyzer": "0.0.28", + "codelyzer": "^1.0.0-beta.0", "copy-webpack-plugin": "^3.0.1", "coveralls": "^2.11.9", "css-loader": "^0.24.0", @@ -87,12 +87,12 @@ "webpack-dev-server": "^2.1.0-beta.2" }, "dependencies": { - "@angular/common": "^2.0.0-rc.6", - "@angular/compiler": "^2.0.0-rc.6", - "@angular/core": "^2.0.0-rc.6", - "@angular/platform-browser": "^2.0.0-rc.6", - "@angular/platform-browser-dynamic": "^2.0.0-rc.6", - "@angular/platform-server": "^2.0.0-rc.6", + "@angular/common": "^2.0.1", + "@angular/compiler": "^2.0.1", + "@angular/core": "^2.0.1", + "@angular/platform-browser": "^2.0.1", + "@angular/platform-browser-dynamic": "^2.0.1", + "@angular/platform-server": "^2.0.1", "core-js": "^2.4.1", "dropkickjs": "^2.1.10", "hint.css": "^2.3.2", @@ -101,10 +101,10 @@ "openapi-sampler": "^0.3.1", "prismjs": "^1.5.1", "remarkable": "^1.6.2", - "rxjs": "^5.0.0-beta.11", + "rxjs": "^5.0.0-beta.12", "scrollparent": "^1.0.0", "slugify": "^1.0.2", "stream-http": "^2.3.1", - "zone.js": "^0.6.17" + "zone.js": "^0.6.25" } } From f02a23b2805bf5c96e47fac4093c0a0ba0c8da31 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 27 Sep 2016 09:03:04 +0300 Subject: [PATCH 4/8] Update webpack to latest beta --- build/webpack.dev.js | 19 +++++++-------- build/webpack.prod.js | 12 ++++------ build/webpack.test.js | 55 ++++++++++++++++++++----------------------- package.json | 8 +++---- 4 files changed, 42 insertions(+), 52 deletions(-) diff --git a/build/webpack.dev.js b/build/webpack.dev.js index 831fbc35..c48af3f3 100644 --- a/build/webpack.dev.js +++ b/build/webpack.dev.js @@ -9,12 +9,9 @@ const IS_PRODUCTION = process.env.NODE_ENV === "production"; module.exports = { context: root(), devtool: 'source-map', - debug: false, resolve: { - extensions: ['', '.ts', '.js', '.json', '.css'], - root: root('lib'), - modulesDirectories: ['node_modules'], + extensions: ['.ts', '.js', '.json', '.css'], alias: { './lib/bootstrap': root('lib/bootstrap.dev'), http: 'stream-http', @@ -28,7 +25,7 @@ module.exports = { node: { fs: "empty", crypto: "empty", - global: "window", + global: true, process: true, module: false, clearImmediate: false, @@ -58,29 +55,29 @@ module.exports = { }, module: { - preLoaders: [{ + loaders: [{ + enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [ /node_modules/ ] - }], - loaders: [{ + }, { test: /\.ts$/, loaders: [ 'awesome-typescript-loader', 'angular2-template-loader' ], exclude: [/\.(spec|e2e)\.ts$/] - },{ + }, { test: /lib\/.*\.css$/, loaders: ['raw-loader'], exclude: [/redoc-initial-styles\.css$/] - },{ + }, { test: /\.css$/, loaders: ['style', 'css?-import'], exclude: [/lib\/(?!.*redoc-initial-styles).*\.css$/] - },{ + }, { test: /\.html$/, loader: 'raw-loader' }] diff --git a/build/webpack.prod.js b/build/webpack.prod.js index e234dd44..0ccfa7ab 100644 --- a/build/webpack.prod.js +++ b/build/webpack.prod.js @@ -15,9 +15,7 @@ module.exports = { devtool: 'source-map', resolve: { - extensions: ['', '.ts', '.js', '.json', '.css'], - root: root('lib'), - modulesDirectories: ['node_modules'], + extensions: ['.ts', '.js', '.json', '.css'], alias: { http: 'stream-http', https: 'stream-http' @@ -30,7 +28,7 @@ module.exports = { node: { fs: "empty", crypto: "empty", - global: "window", + global: true, process: true, module: false, clearImmediate: false, @@ -50,14 +48,14 @@ module.exports = { }, module: { - preLoaders: [{ + loaders: [{ + enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [ /node_modules/ ] - }], - loaders: [{ + },{ test: /\.ts$/, loader: 'awesome-typescript-loader', exclude: /(node_modules)/ diff --git a/build/webpack.test.js b/build/webpack.test.js index ba223e6e..9aa2cde9 100644 --- a/build/webpack.test.js +++ b/build/webpack.test.js @@ -8,9 +8,7 @@ module.exports = { devtool: 'inline-source-map', resolve: { - extensions: ['', '.ts', '.js', '.json', '.css'], - root: root('lib'), - modulesDirectories: ['node_modules'], + extensions: ['.ts', '.js', '.json', '.css'], alias: { './lib/bootstrap': root('lib/bootstrap.dev'), http: 'stream-http', @@ -24,7 +22,7 @@ module.exports = { node: { fs: "empty", crypto: "empty", - global: "window", + global: true, process: true, module: false, clearImmediate: false, @@ -39,60 +37,50 @@ module.exports = { }, module: { - preLoaders: [{ + rules: [{ + enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [ /node_modules/ ] - }], - loaders: [ { + },{ test: /\.ts$/, loaders: [ 'awesome-typescript-loader' - ], - query: { - "sourceMap": false, - "inlineSourceMap": true, - "removeComments": true, - "module": "commonjs" - } + ] }, { test: /\.ts$/, loaders: [ 'angular2-template-loader' ], exclude: [/\.(spec|e2e)\.ts$/] - },{ + }, { test: /lib\/.*\.css$/, loaders: ['raw-loader'], exclude: [/redoc-initial-styles\.css$/] - },{ + }, { test: /\.css$/, loaders: ['style', 'css?-import'], exclude: [/lib\/(?!.*redoc-initial-styles).*\.css$/] - },{ + }, { test: /\.html$/, loader: 'raw-loader' - }], - postLoaders: [ - + }, { /** * Instruments JS files with Istanbul for subsequent code coverage reporting. * Instrument only testing sources. * * See: https://github.com/deepsweet/istanbul-instrumenter-loader */ - { - test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', - include: root('lib'), - exclude: [ - /\.(e2e|spec)\.ts$/, - /node_modules/ - ] - } - - ] + enforce: 'post', + test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', + include: root('lib'), + exclude: [ + /\.(e2e|spec)\.ts$/, + /node_modules/ + ] + }] }, plugins: [ @@ -100,6 +88,13 @@ module.exports = { 'IS_PRODUCTION': false, 'LIB_VERSION': VERSION }), + new webpack.LoaderOptionsPlugin({ + test: /\.ts$/, + sourceMap: false, + inlineSourceMap: true, + removeComments: true, + module: "commonjs" + }), // ignore changes during tests new webpack.WatchIgnorePlugin([ /\/ReDoc$/i, // ignore change of ReDoc folder itself diff --git a/package.json b/package.json index 3ed16ef9..9e406a6a 100644 --- a/package.json +++ b/package.json @@ -80,11 +80,11 @@ "source-map-loader": "^0.1.5", "style-loader": "^0.13.1", "ts-helpers": "^1.1.1", - "tslint": "^3.15.0-dev.0", + "tslint": "^3.15.1", "tslint-stylish": "^2.1.0-beta", - "typescript": "^2.0.2", - "webpack": "^2.1.0-beta.21", - "webpack-dev-server": "^2.1.0-beta.2" + "typescript": "^2.0.3", + "webpack": "^2.1.0-beta.25", + "webpack-dev-server": "^2.1.0-beta.6" }, "dependencies": { "@angular/common": "^2.0.1", From 79693e1b276225be256b5e5ea0db849f31c7b3a6 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 28 Sep 2016 00:30:33 +0300 Subject: [PATCH 5/8] Fix npm start on windows, fixes #119, #118 --- build/webpack.dev.js | 11 ++++++----- build/webpack.prod.js | 6 ++++-- build/webpack.test.js | 19 ++++++++++--------- lib/index.ts | 8 +++++++- manual-types/index.d.ts | 1 + 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/build/webpack.dev.js b/build/webpack.dev.js index c48af3f3..ff2ddacc 100644 --- a/build/webpack.dev.js +++ b/build/webpack.dev.js @@ -13,7 +13,6 @@ module.exports = { resolve: { extensions: ['.ts', '.js', '.json', '.css'], alias: { - './lib/bootstrap': root('lib/bootstrap.dev'), http: 'stream-http', https: 'stream-http' } @@ -55,7 +54,8 @@ module.exports = { }, module: { - loaders: [{ + exprContextCritical: false, + rules: [{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', @@ -70,13 +70,13 @@ module.exports = { ], exclude: [/\.(spec|e2e)\.ts$/] }, { - test: /lib\/.*\.css$/, + test: /lib[\\\/].*\.css$/, loaders: ['raw-loader'], exclude: [/redoc-initial-styles\.css$/] }, { test: /\.css$/, loaders: ['style', 'css?-import'], - exclude: [/lib\/(?!.*redoc-initial-styles).*\.css$/] + exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.css$/] }, { test: /\.html$/, loader: 'raw-loader' @@ -93,7 +93,8 @@ module.exports = { new webpack.DefinePlugin({ 'IS_PRODUCTION': IS_PRODUCTION, - 'LIB_VERSION': VERSION + 'LIB_VERSION': VERSION, + 'AOT': IS_PRODUCTION }), new ForkCheckerPlugin() diff --git a/build/webpack.prod.js b/build/webpack.prod.js index 0ccfa7ab..ae10a82e 100644 --- a/build/webpack.prod.js +++ b/build/webpack.prod.js @@ -48,7 +48,8 @@ module.exports = { }, module: { - loaders: [{ + exprContextCritical: false, + rules: [{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', @@ -84,7 +85,8 @@ module.exports = { new webpack.BannerPlugin(BANNER), new webpack.DefinePlugin({ 'IS_PRODUCTION': true, - 'LIB_VERSION': VERSION + 'LIB_VERSION': VERSION, + 'AOT': true }) ], } diff --git a/build/webpack.test.js b/build/webpack.test.js index 9aa2cde9..869faf91 100644 --- a/build/webpack.test.js +++ b/build/webpack.test.js @@ -10,7 +10,6 @@ module.exports = { resolve: { extensions: ['.ts', '.js', '.json', '.css'], alias: { - './lib/bootstrap': root('lib/bootstrap.dev'), http: 'stream-http', https: 'stream-http' } @@ -37,6 +36,7 @@ module.exports = { }, module: { + exprContextCritical: false, rules: [{ enforce: 'pre', test: /\.js$/, @@ -56,13 +56,13 @@ module.exports = { ], exclude: [/\.(spec|e2e)\.ts$/] }, { - test: /lib\/.*\.css$/, + test: /lib[\\\/].*\.css$/, loaders: ['raw-loader'], exclude: [/redoc-initial-styles\.css$/] }, { test: /\.css$/, loaders: ['style', 'css?-import'], - exclude: [/lib\/(?!.*redoc-initial-styles).*\.css$/] + exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.css$/] }, { test: /\.html$/, loader: 'raw-loader' @@ -86,7 +86,8 @@ module.exports = { plugins: [ new webpack.DefinePlugin({ 'IS_PRODUCTION': false, - 'LIB_VERSION': VERSION + 'LIB_VERSION': VERSION, + 'AOT': 'false' }), new webpack.LoaderOptionsPlugin({ test: /\.ts$/, @@ -97,11 +98,11 @@ module.exports = { }), // ignore changes during tests new webpack.WatchIgnorePlugin([ - /\/ReDoc$/i, // ignore change of ReDoc folder itself - /node_modules\/(?:[^\/]*(?:\/|$))*[^\/]*$/, - /\.tmp\/(?:[^\/]*(?:\/|$))*[^\/]*$/, - /dist\/(?:[^\/]*(?:\/|$))*[^\/]*$/, - /(?:[^\/]*(?:\/|$))*[^\/]*\.css$/ // ignore css files + /[\\\/]ReDoc$/i, // ignore change of ReDoc folder itself + /node_modules[\\\/].*$/, + /\.tmp[\\\/].*$/, + /dist[\\\/].*$/, + /(?:[^\\\/]*(?:[\\\/]|$))*[^\\\/]*\.css$/ // ignore css files ]) ], } diff --git a/lib/index.ts b/lib/index.ts index 06eeef8a..1ad46f3a 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -6,7 +6,13 @@ import { Redoc } from './components/index'; import { SpecManager } from './utils/SpecManager'; import { BrowserDomAdapter as DOM } from './utils/browser-adapter'; import { disableDebugTools } from '@angular/platform-browser'; -import { bootstrapRedoc } from './bootstrap'; + +var bootstrapRedoc; +if (AOT) { + bootstrapRedoc = require('./bootstrap').bootstrapRedoc; +} else { + bootstrapRedoc = require('./bootstrap.dev').bootstrapRedoc; +} if (IS_PRODUCTION) { disableDebugTools(); diff --git a/manual-types/index.d.ts b/manual-types/index.d.ts index 22733ca1..faecbd1c 100644 --- a/manual-types/index.d.ts +++ b/manual-types/index.d.ts @@ -14,6 +14,7 @@ declare module "*.css" { declare var LIB_VERSION: any; declare var IS_PRODUCTION: any; +declare var AOT: any; interface ErrorStackTraceLimit { stackTraceLimit: number; From 3ab25b9ff8229f278e551fe5caa31370b83c4edb Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 28 Sep 2016 09:33:56 +0300 Subject: [PATCH 6/8] Add engines to package.json, fixes #83 --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 9e406a6a..be3b1442 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,10 @@ "type": "git", "url": "git://github.com/Rebilly/ReDoc" }, + "engines": { + "node": ">=4.0.0", + "npm": ">=3.0.0" + }, "main": "dist/redoc.min.js", "scripts": { "test": "npm run lint && node ./build/run_tests.js", From 0678c4c595e19bb1103bed08934a81863b2b644e Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 28 Sep 2016 09:36:21 +0300 Subject: [PATCH 7/8] implemented x-extendedDiscriminator to workaround name clashes in big specs --- lib/components/JsonSchema/json-schema.ts | 2 +- lib/components/SchemaSample/schema-sample.ts | 2 +- lib/services/schema-helper.service.ts | 6 ++++-- lib/services/schema-normalizer.service.ts | 2 +- lib/utils/SpecManager.ts | 22 ++++++++++++++------ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts index 6fa7917d..1ad68d8b 100644 --- a/lib/components/JsonSchema/json-schema.ts +++ b/lib/components/JsonSchema/json-schema.ts @@ -57,7 +57,7 @@ export class JsonSchema extends BaseComponent implements OnInit { this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer); if (!this.descendants.length) return; this.hasDescendants = true; - let discriminator = this.schema.discriminator; + let discriminator = this.schema.discriminator || this.schema['x-extendedDiscriminator']; let discrProperty = this.schema._properties && this.schema._properties.filter((prop) => prop.name === discriminator)[0]; if (discrProperty && discrProperty.enum) { diff --git a/lib/components/SchemaSample/schema-sample.ts b/lib/components/SchemaSample/schema-sample.ts index 11de5307..74e77366 100644 --- a/lib/components/SchemaSample/schema-sample.ts +++ b/lib/components/SchemaSample/schema-sample.ts @@ -48,7 +48,7 @@ export class SchemaSample extends BaseComponent implements OnInit { this.componentSchema = this._normalizer.normalize(this.componentSchema, this.pointer); - let discriminator = this.componentSchema.discriminator; + let discriminator = this.componentSchema.discriminator || this.componentSchema['x-extendedDiscriminator']; if (discriminator) { let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer); if (descendants.length) { diff --git a/lib/services/schema-helper.service.ts b/lib/services/schema-helper.service.ts index 315761fd..fac99333 100644 --- a/lib/services/schema-helper.service.ts +++ b/lib/services/schema-helper.service.ts @@ -57,9 +57,10 @@ const injectors = { } }, discriminator: { - check: (propertySchema) => propertySchema.discriminator, + check: (propertySchema) => propertySchema.discriminator || propertySchema['x-extendedDiscriminator'], inject: (injectTo, propertySchema = injectTo, pointer) => { injectTo.discriminator = propertySchema.discriminator; + injectTo['x-extendedDiscriminator'] = propertySchema['x-extendedDiscriminator']; } }, simpleArray: { @@ -229,7 +230,8 @@ export class SchemaHelper { propertySchema._pointer = null; } propertySchema._required = !!requiredMap[propName]; - propertySchema.isDiscriminator = (schema.discriminator === propName); + propertySchema.isDiscriminator = (schema.discriminator === propName + || schema['x-extendedDiscriminator'] === propName); return propertySchema; }); diff --git a/lib/services/schema-normalizer.service.ts b/lib/services/schema-normalizer.service.ts index f97d6d65..300a4e27 100644 --- a/lib/services/schema-normalizer.service.ts +++ b/lib/services/schema-normalizer.service.ts @@ -118,7 +118,7 @@ class AllOfMerger { private static mergeObject(into, subSchema, allOfNumber) { if (subSchema.properties) { - if (!into.properties) into.properties = {}; + into.properties = Object.assign({}, into.properties || {}); Object.assign(into.properties, subSchema.properties); Object.keys(subSchema.properties).forEach(propName => { let prop = subSchema.properties[propName]; diff --git a/lib/utils/SpecManager.ts b/lib/utils/SpecManager.ts index 64755d6a..1c4032d5 100644 --- a/lib/utils/SpecManager.ts +++ b/lib/utils/SpecManager.ts @@ -152,19 +152,29 @@ export class SpecManager { findDerivedDefinitions(defPointer) { let definition = this.byPointer(defPointer); if (!definition) throw new Error(`Can't load schema at ${defPointer}`); - if (!definition.discriminator) return []; + if (!definition.discriminator && !definition['x-extendedDiscriminator']) return []; let globalDefs = this._schema.definitions || {}; let res = []; + let extendedDiscriminatorProp = definition['x-extendedDiscriminator']; for (let defName of Object.keys(globalDefs)) { - if (!globalDefs[defName].allOf && - !globalDefs[defName]['x-derived-from']) continue; - let subTypes = globalDefs[defName]['x-derived-from'] || - globalDefs[defName].allOf.map(subType => subType._pointer || subType.$ref); + let def = globalDefs[defName]; + if (!def.allOf && + !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); if (idx < 0) continue; - res.push({name: defName, $ref: `#/definitions/${defName}`}); + let derivedName = defName; + if (extendedDiscriminatorProp) { + let prop = def.properties && def.properties[extendedDiscriminatorProp]; + if (prop && prop.enum && prop.enum.length === 1) { + derivedName = prop.enum[0]; + } + } + + res.push({name: derivedName, $ref: `#/definitions/${defName}`}); } return res; } From 59a3ddf2d0a7f1a7158b3b6314c7a4fa6ed8faa0 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 28 Sep 2016 09:55:59 +0300 Subject: [PATCH 8/8] v1.3.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be3b1442..6f84ef02 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "redoc", "description": "Swagger-generated API Reference Documentation", - "version": "1.3.2", + "version": "1.3.3", "repository": { "type": "git", "url": "git://github.com/Rebilly/ReDoc"