diff --git a/README.md b/README.md index 63ef580d..533d86d6 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,9 @@ For npm: ## Configuration +### Security Definition location +You can inject Security Definitions widget into any place of your specification `description`. Check out details [here](docs/security-definitions-injection.md). + ### Swagger vendor extensions ReDoc makes use of the following [vendor extensions](http://swagger.io/specification/#vendorExtensions): * [`x-logo`](docs/redoc-vendor-extensions.md#x-logo) - is used to specify API logo @@ -132,11 +135,7 @@ Redoc.init('http://petstore.swagger.io/v2/swagger.json', { `cd ReDoc` - Install dependencies `npm install` -- *(Temporary step, will be obsolete after fixing #97)* Compile CSS -```bash -npm run build:sass -``` -- _(optional)_ Replace `demo/swagger.json` with your own schema +- _(optional)_ Replace `demo/swagger.yaml` with your own schema - Start the server `npm start` - Open `http://localhost:9000` diff --git a/build/webpack.dev.js b/build/webpack.dev.js index cc6afc4a..449f6d50 100644 --- a/build/webpack.dev.js +++ b/build/webpack.dev.js @@ -1,5 +1,6 @@ const webpack = require('webpack'); const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin; +const StringReplacePlugin = require("string-replace-webpack-plugin"); const root = require('./helpers').root; const VERSION = JSON.stringify(require('../package.json').version); @@ -62,6 +63,28 @@ module.exports = { exclude: [ /node_modules/ ] + }, { + enforce: 'pre', + test: /\.ts$/, + exclude: [ + /node_modules/ + ], + loader: StringReplacePlugin.replace({ + replacements: [ + { + pattern: /styleUrls:\s*\[\s*'([\w\.\/-]*)\.css'\s*\][\s,]*$/m, + replacement: function (match, p1, offset, string) { + return `styleUrls: ['${p1}.scss'],`; + } + }, + { + pattern: /(\.\/components\/Redoc\/redoc-initial-styles\.css)/m, + replacement: function (match, p1, offset, string) { + return p1.replace('.css', '.scss'); + } + } + ] + }) }, { test: /\.ts$/, loaders: [ @@ -70,13 +93,16 @@ module.exports = { ], exclude: [/\.(spec|e2e)\.ts$/] }, { - test: /lib[\\\/].*\.css$/, - loaders: ['raw-loader'], - exclude: [/redoc-initial-styles\.css$/] + test: /lib[\\\/].*\.scss$/, + loaders: ['raw-loader', "sass"], + exclude: [/redoc-initial-styles\.scss$/] + }, { + test: /\.scss$/, + loaders: ['style', 'css?-import', "sass"], + exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.scss$/] }, { test: /\.css$/, loaders: ['style', 'css?-import'], - exclude: [/lib[\\\/](?!.*redoc-initial-styles).*\.css$/] }, { test: /\.html$/, loader: 'raw-loader' @@ -97,6 +123,8 @@ module.exports = { 'AOT': IS_PRODUCTION }), - new ForkCheckerPlugin() + new ForkCheckerPlugin(), + + new StringReplacePlugin() ], } diff --git a/build/webpack.prod.js b/build/webpack.prod.js index ffecdfe0..8fc8ef45 100644 --- a/build/webpack.prod.js +++ b/build/webpack.prod.js @@ -12,18 +12,6 @@ const BANNER = const IS_MODULE = process.env.IS_MODULE != null; -const TS_RULE = { - test: /\.ts$/, - loader: 'awesome-typescript-loader', - exclude: /(node_modules)/, -}; -// -// if (IS_MODULE) { -// TS_RULE.query = { -// noEmitHelpers: false -// } -// } - const config = { context: root(), devtool: 'source-map', @@ -70,7 +58,14 @@ const config = { exclude: [ /node_modules/ ] - }, TS_RULE, { + }, { + test: /node_modules\/.*\.ngfactory\.ts$/, + loader: 'awesome-typescript-loader' + }, { + test: /\.ts$/, + loader: 'awesome-typescript-loader', + exclude: /(node_modules)/, + }, { test: /lib[\\\/].*\.css$/, loaders: ['raw-loader'], exclude: [/redoc-initial-styles\.css$/] diff --git a/demo/swagger.yaml b/demo/swagger.yaml index 9bb9dee4..ac84c381 100644 --- a/demo/swagger.yaml +++ b/demo/swagger.yaml @@ -26,7 +26,6 @@ info: This API features Cross-Origin Resource Sharing (CORS) implemented in compliance with [W3C spec](https://www.w3.org/TR/cors/). And that allows cross-domain communication from the browser. All responses have a wildcard same-origin which makes them completely public and accessible to everyone, including any code on any site. - version: 1.0.0 title: Swagger Petstore termsOfService: 'http://swagger.io/terms/' diff --git a/docs/redoc-vendor-extensions.md b/docs/redoc-vendor-extensions.md index e12ef1e5..6cda3908 100644 --- a/docs/redoc-vendor-extensions.md +++ b/docs/redoc-vendor-extensions.md @@ -49,7 +49,7 @@ info: ### Tag Object vendor extensions Extends OpenAPI [Tag Object](http://swagger.io/specification/#tagObject) -#### x-traitTag +#### x-traitTag [DEPRECATED] | Field Name | Type | Description | | :------------- | :------: | :---------- | | x-traitTag | boolean | In Swagger two operations can have multiply tags. This property distinguish between tags that are used to group operations (default) from tags that are used to mark operation with certain trait (`true` value) | diff --git a/docs/security-definitions-injection.md b/docs/security-definitions-injection.md new file mode 100644 index 00000000..84071c07 --- /dev/null +++ b/docs/security-definitions-injection.md @@ -0,0 +1,19 @@ +# Injection security definitions + +You can inject Security Definitions widget into any place of your specification `description`: + +```markdown +... +# Authorization +Some description + + +... +``` +Inject instruction is wrapped into HTML comment so it is **visible only in ReDoc**. It won't be visible e.g. in SwaggerUI. + +# Default behavior +If injection tag is not found in the description it will be appended to the end +of description under `Authentication` header. + +If `Authentication` header is already present in the description, Security Definitions won't be inserted and rendered at all. diff --git a/lib/app.module.ts b/lib/app.module.ts new file mode 100644 index 00000000..37ee2c5a --- /dev/null +++ b/lib/app.module.ts @@ -0,0 +1,13 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +import { RedocModule } from './redoc.module'; +import { Redoc } from './components/index'; + +@NgModule({ + imports: [ BrowserModule, RedocModule ], + bootstrap: [ Redoc ], + exports: [ Redoc ] +}) +export class AppModule { +} diff --git a/lib/bootstrap.dev.ts b/lib/bootstrap.dev.ts index f826b733..296618d7 100644 --- a/lib/bootstrap.dev.ts +++ b/lib/bootstrap.dev.ts @@ -1,6 +1,6 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { RedocModule } from './redoc.module'; +import { AppModule } from './app.module'; export function bootstrapRedoc() { - return platformBrowserDynamic().bootstrapModule(RedocModule); + return platformBrowserDynamic().bootstrapModule(AppModule); } diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index d7439b26..c55ccecb 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -1,6 +1,6 @@ import { platformBrowser } from '@angular/platform-browser'; -import { RedocModuleNgFactory } from './redoc.module.ngfactory'; +import { AppModuleNgFactory } from './app.module.ngfactory'; export function bootstrapRedoc() { - return platformBrowser().bootstrapModuleFactory(RedocModuleNgFactory); + return platformBrowser().bootstrapModuleFactory(AppModuleNgFactory); } diff --git a/lib/components/ApiInfo/api-info.html b/lib/components/ApiInfo/api-info.html index de1daf78..b8a8428c 100644 --- a/lib/components/ApiInfo/api-info.html +++ b/lib/components/ApiInfo/api-info.html @@ -17,5 +17,5 @@ {{info.license.name}}
-+