Merge commit '59a3ddf2d0a7f1a7158b3b6314c7a4fa6ed8faa0' into releases

This commit is contained in:
RedocBot 2016-09-28 07:35:09 +00:00 committed by travis@localhost
commit 0a67f0bb5a
12 changed files with 117 additions and 99 deletions

View File

@ -126,16 +126,17 @@ Redoc.init('http://petstore.swagger.io/v2/swagger.json', {
----------- -----------
## Development ## Development
#### Running local dev-server #### Running local dev-server
1. Clone repository - Clone repository
`git clone https://github.com/Rebilly/ReDoc.git` `git clone https://github.com/Rebilly/ReDoc.git`
2. Go to the project folder - Go to the project folder
`cd ReDoc` `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 - _(optional)_ Replace `demo/swagger.json` with your own schema
npm run jspm-install - Start the server
```
4. _(optional)_ Replace `demo/swagger.json` with your own schema
5. Start the server
`npm start` `npm start`
6. Open `http://localhost:9000` - Open `http://localhost:9000`

View File

@ -9,14 +9,10 @@ const IS_PRODUCTION = process.env.NODE_ENV === "production";
module.exports = { module.exports = {
context: root(), context: root(),
devtool: 'source-map', devtool: 'source-map',
debug: false,
resolve: { resolve: {
extensions: ['', '.ts', '.js', '.json', '.css'], extensions: ['.ts', '.js', '.json', '.css'],
root: root('lib'),
modulesDirectories: ['node_modules'],
alias: { alias: {
'./lib/bootstrap': root('lib/bootstrap.dev'),
http: 'stream-http', http: 'stream-http',
https: 'stream-http' https: 'stream-http'
} }
@ -28,7 +24,7 @@ module.exports = {
node: { node: {
fs: "empty", fs: "empty",
crypto: "empty", crypto: "empty",
global: "window", global: true,
process: true, process: true,
module: false, module: false,
clearImmediate: false, clearImmediate: false,
@ -58,29 +54,30 @@ module.exports = {
}, },
module: { module: {
preLoaders: [{ exprContextCritical: false,
rules: [{
enforce: 'pre',
test: /\.js$/, test: /\.js$/,
loader: 'source-map-loader', loader: 'source-map-loader',
exclude: [ exclude: [
/node_modules/ /node_modules/
] ]
}], }, {
loaders: [{
test: /\.ts$/, test: /\.ts$/,
loaders: [ loaders: [
'awesome-typescript-loader', 'awesome-typescript-loader',
'angular2-template-loader' 'angular2-template-loader'
], ],
exclude: [/\.(spec|e2e)\.ts$/] exclude: [/\.(spec|e2e)\.ts$/]
},{ }, {
test: /lib\/.*\.css$/, test: /lib[\\\/].*\.css$/,
loaders: ['raw-loader'], loaders: ['raw-loader'],
exclude: [/redoc-initial-styles\.css$/] exclude: [/redoc-initial-styles\.css$/]
},{ }, {
test: /\.css$/, test: /\.css$/,
loaders: ['style', 'css?-import'], loaders: ['style', 'css?-import'],
exclude: [/lib\/(?!.*redoc-initial-styles).*\.css$/] exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.css$/]
},{ }, {
test: /\.html$/, test: /\.html$/,
loader: 'raw-loader' loader: 'raw-loader'
}] }]
@ -96,7 +93,8 @@ module.exports = {
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'IS_PRODUCTION': IS_PRODUCTION, 'IS_PRODUCTION': IS_PRODUCTION,
'LIB_VERSION': VERSION 'LIB_VERSION': VERSION,
'AOT': IS_PRODUCTION
}), }),
new ForkCheckerPlugin() new ForkCheckerPlugin()

View File

@ -15,9 +15,7 @@ module.exports = {
devtool: 'source-map', devtool: 'source-map',
resolve: { resolve: {
extensions: ['', '.ts', '.js', '.json', '.css'], extensions: ['.ts', '.js', '.json', '.css'],
root: root('lib'),
modulesDirectories: ['node_modules'],
alias: { alias: {
http: 'stream-http', http: 'stream-http',
https: 'stream-http' https: 'stream-http'
@ -30,7 +28,7 @@ module.exports = {
node: { node: {
fs: "empty", fs: "empty",
crypto: "empty", crypto: "empty",
global: "window", global: true,
process: true, process: true,
module: false, module: false,
clearImmediate: false, clearImmediate: false,
@ -50,14 +48,15 @@ module.exports = {
}, },
module: { module: {
preLoaders: [{ exprContextCritical: false,
rules: [{
enforce: 'pre',
test: /\.js$/, test: /\.js$/,
loader: 'source-map-loader', loader: 'source-map-loader',
exclude: [ exclude: [
/node_modules/ /node_modules/
] ]
}], },{
loaders: [{
test: /\.ts$/, test: /\.ts$/,
loader: 'awesome-typescript-loader', loader: 'awesome-typescript-loader',
exclude: /(node_modules)/ exclude: /(node_modules)/
@ -86,7 +85,8 @@ module.exports = {
new webpack.BannerPlugin(BANNER), new webpack.BannerPlugin(BANNER),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'IS_PRODUCTION': true, 'IS_PRODUCTION': true,
'LIB_VERSION': VERSION 'LIB_VERSION': VERSION,
'AOT': true
}) })
], ],
} }

View File

@ -8,11 +8,8 @@ module.exports = {
devtool: 'inline-source-map', devtool: 'inline-source-map',
resolve: { resolve: {
extensions: ['', '.ts', '.js', '.json', '.css'], extensions: ['.ts', '.js', '.json', '.css'],
root: root('lib'),
modulesDirectories: ['node_modules'],
alias: { alias: {
'./lib/bootstrap': root('lib/bootstrap.dev'),
http: 'stream-http', http: 'stream-http',
https: 'stream-http' https: 'stream-http'
} }
@ -24,7 +21,7 @@ module.exports = {
node: { node: {
fs: "empty", fs: "empty",
crypto: "empty", crypto: "empty",
global: "window", global: true,
process: true, process: true,
module: false, module: false,
clearImmediate: false, clearImmediate: false,
@ -39,74 +36,73 @@ module.exports = {
}, },
module: { module: {
preLoaders: [{ exprContextCritical: false,
rules: [{
enforce: 'pre',
test: /\.js$/, test: /\.js$/,
loader: 'source-map-loader', loader: 'source-map-loader',
exclude: [ exclude: [
/node_modules/ /node_modules/
] ]
}], },{
loaders: [ {
test: /\.ts$/, test: /\.ts$/,
loaders: [ loaders: [
'awesome-typescript-loader' 'awesome-typescript-loader'
], ]
query: {
"sourceMap": false,
"inlineSourceMap": true,
"removeComments": true,
"module": "commonjs"
}
}, { }, {
test: /\.ts$/, test: /\.ts$/,
loaders: [ loaders: [
'angular2-template-loader' 'angular2-template-loader'
], ],
exclude: [/\.(spec|e2e)\.ts$/] exclude: [/\.(spec|e2e)\.ts$/]
},{ }, {
test: /lib\/.*\.css$/, test: /lib[\\\/].*\.css$/,
loaders: ['raw-loader'], loaders: ['raw-loader'],
exclude: [/redoc-initial-styles\.css$/] exclude: [/redoc-initial-styles\.css$/]
},{ }, {
test: /\.css$/, test: /\.css$/,
loaders: ['style', 'css?-import'], loaders: ['style', 'css?-import'],
exclude: [/lib\/(?!.*redoc-initial-styles).*\.css$/] exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.css$/]
},{ }, {
test: /\.html$/, test: /\.html$/,
loader: 'raw-loader' loader: 'raw-loader'
}], }, {
postLoaders: [
/** /**
* Instruments JS files with Istanbul for subsequent code coverage reporting. * Instruments JS files with Istanbul for subsequent code coverage reporting.
* Instrument only testing sources. * Instrument only testing sources.
* *
* See: https://github.com/deepsweet/istanbul-instrumenter-loader * See: https://github.com/deepsweet/istanbul-instrumenter-loader
*/ */
{ enforce: 'post',
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
include: root('lib'), include: root('lib'),
exclude: [ exclude: [
/\.(e2e|spec)\.ts$/, /\.(e2e|spec)\.ts$/,
/node_modules/ /node_modules/
] ]
} }]
]
}, },
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'IS_PRODUCTION': false, 'IS_PRODUCTION': false,
'LIB_VERSION': VERSION 'LIB_VERSION': VERSION,
'AOT': 'false'
}), }),
new webpack.LoaderOptionsPlugin({
test: /\.ts$/,
sourceMap: false,
inlineSourceMap: true,
removeComments: true,
module: "commonjs"
}),
// ignore changes during tests // ignore changes during tests
new webpack.WatchIgnorePlugin([ new webpack.WatchIgnorePlugin([
/\/ReDoc$/i, // ignore change of ReDoc folder itself /[\\\/]ReDoc$/i, // ignore change of ReDoc folder itself
/node_modules\/(?:[^\/]*(?:\/|$))*[^\/]*$/, /node_modules[\\\/].*$/,
/\.tmp\/(?:[^\/]*(?:\/|$))*[^\/]*$/, /\.tmp[\\\/].*$/,
/dist\/(?:[^\/]*(?:\/|$))*[^\/]*$/, /dist[\\\/].*$/,
/(?:[^\/]*(?:\/|$))*[^\/]*\.css$/ // ignore css files /(?:[^\\\/]*(?:[\\\/]|$))*[^\\\/]*\.css$/ // ignore css files
]) ])
], ],
} }

View File

@ -57,7 +57,7 @@ export class JsonSchema extends BaseComponent implements OnInit {
this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer); this.descendants = this.specMgr.findDerivedDefinitions(this.normPointer);
if (!this.descendants.length) return; if (!this.descendants.length) return;
this.hasDescendants = true; this.hasDescendants = true;
let discriminator = this.schema.discriminator; let discriminator = this.schema.discriminator || this.schema['x-extendedDiscriminator'];
let discrProperty = this.schema._properties && let discrProperty = this.schema._properties &&
this.schema._properties.filter((prop) => prop.name === discriminator)[0]; this.schema._properties.filter((prop) => prop.name === discriminator)[0];
if (discrProperty && discrProperty.enum) { if (discrProperty && discrProperty.enum) {

View File

@ -48,7 +48,7 @@ export class SchemaSample extends BaseComponent implements OnInit {
this.componentSchema = this._normalizer.normalize(this.componentSchema, this.pointer); 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) { if (discriminator) {
let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer); let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer);
if (descendants.length) { if (descendants.length) {

View File

@ -6,7 +6,13 @@ import { Redoc } from './components/index';
import { SpecManager } from './utils/SpecManager'; import { SpecManager } from './utils/SpecManager';
import { BrowserDomAdapter as DOM } from './utils/browser-adapter'; import { BrowserDomAdapter as DOM } from './utils/browser-adapter';
import { disableDebugTools } from '@angular/platform-browser'; 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) { if (IS_PRODUCTION) {
disableDebugTools(); disableDebugTools();

View File

@ -57,9 +57,10 @@ const injectors = {
} }
}, },
discriminator: { discriminator: {
check: (propertySchema) => propertySchema.discriminator, check: (propertySchema) => propertySchema.discriminator || propertySchema['x-extendedDiscriminator'],
inject: (injectTo, propertySchema = injectTo, pointer) => { inject: (injectTo, propertySchema = injectTo, pointer) => {
injectTo.discriminator = propertySchema.discriminator; injectTo.discriminator = propertySchema.discriminator;
injectTo['x-extendedDiscriminator'] = propertySchema['x-extendedDiscriminator'];
} }
}, },
simpleArray: { simpleArray: {
@ -229,7 +230,8 @@ export class SchemaHelper {
propertySchema._pointer = null; propertySchema._pointer = null;
} }
propertySchema._required = !!requiredMap[propName]; propertySchema._required = !!requiredMap[propName];
propertySchema.isDiscriminator = (schema.discriminator === propName); propertySchema.isDiscriminator = (schema.discriminator === propName
|| schema['x-extendedDiscriminator'] === propName);
return propertySchema; return propertySchema;
}); });

View File

@ -118,7 +118,7 @@ class AllOfMerger {
private static mergeObject(into, subSchema, allOfNumber) { private static mergeObject(into, subSchema, allOfNumber) {
if (subSchema.properties) { if (subSchema.properties) {
if (!into.properties) into.properties = {}; into.properties = Object.assign({}, into.properties || {});
Object.assign(into.properties, subSchema.properties); Object.assign(into.properties, subSchema.properties);
Object.keys(subSchema.properties).forEach(propName => { Object.keys(subSchema.properties).forEach(propName => {
let prop = subSchema.properties[propName]; let prop = subSchema.properties[propName];

View File

@ -152,19 +152,29 @@ export class SpecManager {
findDerivedDefinitions(defPointer) { findDerivedDefinitions(defPointer) {
let definition = this.byPointer(defPointer); let definition = this.byPointer(defPointer);
if (!definition) throw new Error(`Can't load schema at ${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 globalDefs = this._schema.definitions || {};
let res = []; let res = [];
let extendedDiscriminatorProp = definition['x-extendedDiscriminator'];
for (let defName of Object.keys(globalDefs)) { for (let defName of Object.keys(globalDefs)) {
if (!globalDefs[defName].allOf && let def = globalDefs[defName];
!globalDefs[defName]['x-derived-from']) continue; if (!def.allOf &&
let subTypes = globalDefs[defName]['x-derived-from'] || !def['x-derived-from']) continue;
globalDefs[defName].allOf.map(subType => subType._pointer || subType.$ref); let subTypes = def['x-derived-from'] ||
def.allOf.map(subType => subType._pointer || subType.$ref);
let idx = subTypes.findIndex(ref => ref === defPointer); let idx = subTypes.findIndex(ref => ref === defPointer);
if (idx < 0) continue; 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; return res;
} }

View File

@ -14,6 +14,7 @@ declare module "*.css" {
declare var LIB_VERSION: any; declare var LIB_VERSION: any;
declare var IS_PRODUCTION: any; declare var IS_PRODUCTION: any;
declare var AOT: any;
interface ErrorStackTraceLimit { interface ErrorStackTraceLimit {
stackTraceLimit: number; stackTraceLimit: number;

View File

@ -1,11 +1,15 @@
{ {
"name": "redoc", "name": "redoc",
"description": "Swagger-generated API Reference Documentation", "description": "Swagger-generated API Reference Documentation",
"version": "1.3.2", "version": "1.3.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/Rebilly/ReDoc" "url": "git://github.com/Rebilly/ReDoc"
}, },
"engines": {
"node": ">=4.0.0",
"npm": ">=3.0.0"
},
"main": "dist/redoc.min.js", "main": "dist/redoc.min.js",
"scripts": { "scripts": {
"test": "npm run lint && node ./build/run_tests.js", "test": "npm run lint && node ./build/run_tests.js",
@ -40,7 +44,7 @@
"author": "Roman Hotsiy", "author": "Roman Hotsiy",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@angular/compiler-cli": "^0.6.0", "@angular/compiler-cli": "^0.6.3",
"@types/core-js": "^0.9.31", "@types/core-js": "^0.9.31",
"@types/jasmine": "^2.2.32", "@types/jasmine": "^2.2.32",
"@types/requirejs": "^2.1.26", "@types/requirejs": "^2.1.26",
@ -49,7 +53,7 @@
"awesome-typescript-loader": "^2.2.1", "awesome-typescript-loader": "^2.2.1",
"branch-release": "^1.0.3", "branch-release": "^1.0.3",
"chalk": "^1.1.3", "chalk": "^1.1.3",
"codelyzer": "0.0.28", "codelyzer": "^1.0.0-beta.0",
"copy-webpack-plugin": "^3.0.1", "copy-webpack-plugin": "^3.0.1",
"coveralls": "^2.11.9", "coveralls": "^2.11.9",
"css-loader": "^0.24.0", "css-loader": "^0.24.0",
@ -80,31 +84,31 @@
"source-map-loader": "^0.1.5", "source-map-loader": "^0.1.5",
"style-loader": "^0.13.1", "style-loader": "^0.13.1",
"ts-helpers": "^1.1.1", "ts-helpers": "^1.1.1",
"tslint": "^3.15.0-dev.0", "tslint": "^3.15.1",
"tslint-stylish": "^2.1.0-beta", "tslint-stylish": "^2.1.0-beta",
"typescript": "^2.0.2", "typescript": "^2.0.3",
"webpack": "^2.1.0-beta.21", "webpack": "^2.1.0-beta.25",
"webpack-dev-server": "^2.1.0-beta.2" "webpack-dev-server": "^2.1.0-beta.6"
}, },
"dependencies": { "dependencies": {
"@angular/common": "^2.0.0-rc.6", "@angular/common": "^2.0.1",
"@angular/compiler": "^2.0.0-rc.6", "@angular/compiler": "^2.0.1",
"@angular/core": "^2.0.0-rc.6", "@angular/core": "^2.0.1",
"@angular/platform-browser": "^2.0.0-rc.6", "@angular/platform-browser": "^2.0.1",
"@angular/platform-browser-dynamic": "^2.0.0-rc.6", "@angular/platform-browser-dynamic": "^2.0.1",
"@angular/platform-server": "^2.0.0-rc.6", "@angular/platform-server": "^2.0.1",
"core-js": "^2.4.1", "core-js": "^2.4.1",
"dropkickjs": "^2.1.10", "dropkickjs": "^2.1.10",
"hint.css": "^2.3.2", "hint.css": "^2.3.2",
"json-pointer": "^0.5.0", "json-pointer": "^0.5.0",
"json-schema-ref-parser": "^3.1.2", "json-schema-ref-parser": "^3.1.2",
"openapi-sampler": "^0.3.0", "openapi-sampler": "^0.3.1",
"prismjs": "^1.5.1", "prismjs": "^1.5.1",
"remarkable": "^1.6.2", "remarkable": "^1.6.2",
"rxjs": "^5.0.0-beta.11", "rxjs": "^5.0.0-beta.12",
"scrollparent": "^1.0.0", "scrollparent": "^1.0.0",
"slugify": "^1.0.2", "slugify": "^1.0.2",
"stream-http": "^2.3.1", "stream-http": "^2.3.1",
"zone.js": "^0.6.17" "zone.js": "^0.6.25"
} }
} }