diff --git a/README.md b/README.md index e670b722..1b206b1b 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ ReDoc makes use of the following [vendor extensions](http://swagger.io/specifica * [`x-displayName`](docs/redoc-vendor-extensions.md#x-displayname) - specify human-friendly names for the menu categories * [`x-tagGroups`](docs/redoc-vendor-extensions.md#x-tagGroups) - group tags by categories in the side menu * [`x-servers`](docs/redoc-vendor-extensions.md#x-servers) - ability to specify different servers for API (backported from OpenAPI 3.0) +* [`x-ignoredHeaderParameters`](docs/redoc-vendor-extensions.md#x-ignoredHeaderParameters) - ability to specify header parameter names to ignore ### `` 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 b285aafb..8985bf6b 100644 --- a/docs/redoc-vendor-extensions.md +++ b/docs/redoc-vendor-extensions.md @@ -54,7 +54,28 @@ x-tagGroups: - Secondary Stats ``` -#### Logo Object +#### x-ignoredHeaderParameters + + +| Field Name | Type | Description | +| :-------------------------- | :-----------: | :---------- | +| x-ignoredHeaderParameters | [ string ] | A list of ignored headers | + + +###### Usage in Redoc +`x-ignoredHeaderParameters` is used to specify header parameter names which are ignored by ReDoc + +###### x-ignoredHeaderParameters example +```yaml +swagger: '2.0' +info: + ... +tags: [...] +x-ignoredHeaderParameters: + - Accept + - User-Agent + - X-Test-Header +``` ### Info Object vendor extensions Extends OpenAPI [Info Object](http://swagger.io/specification/#infoObject) diff --git a/lib/components/ParamsList/params-list.ts b/lib/components/ParamsList/params-list.ts index 281c68a6..63629d08 100644 --- a/lib/components/ParamsList/params-list.ts +++ b/lib/components/ParamsList/params-list.ts @@ -1,7 +1,8 @@ -'use strict'; -import { Component, Input, ChangeDetectionStrategy, OnInit } from '@angular/core'; -import { BaseComponent, SpecManager } from '../base'; +import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; + +import { OptionsService } from '../../services/options.service'; import { SchemaHelper } from '../../services/schema-helper.service'; +import { BaseComponent, SpecManager } from '../base'; function safePush(obj, prop, item) { if (!obj[prop]) obj[prop] = []; @@ -12,16 +13,16 @@ function safePush(obj, prop, item) { selector: 'params-list', templateUrl: './params-list.html', styleUrls: ['./params-list.css'], - changeDetection: ChangeDetectionStrategy.OnPush + changeDetection: ChangeDetectionStrategy.OnPush, }) export class ParamsList extends BaseComponent implements OnInit { - @Input() pointer:string; + @Input() pointer: string; params: Array; empty: boolean; bodyParam: any; - constructor(specMgr:SpecManager) { + constructor(specMgr: SpecManager, private options: OptionsService) { super(specMgr); } @@ -29,11 +30,20 @@ export class ParamsList extends BaseComponent implements OnInit { this.params = []; let paramsList = this.specMgr.getOperationParams(this.pointer); - paramsList = paramsList.map(paramSchema => { - let propPointer = paramSchema._pointer; - if (paramSchema.in === 'body') return paramSchema; - return SchemaHelper.preprocess(paramSchema, propPointer, this.pointer); - }); + const igrnoredHeaders = + this.specMgr.schema['x-ignoredHeaderParameters'] || + this.options.options.ignoredHeaderParameters || + []; + + paramsList = paramsList + .map(paramSchema => { + let propPointer = paramSchema._pointer; + if (paramSchema.in === 'body') return paramSchema; + return SchemaHelper.preprocess(paramSchema, propPointer, this.pointer); + }) + .filter(param => { + return param.in !== 'header' || igrnoredHeaders.indexOf(param.name) < 0; + }); let paramsMap = this.orderParams(paramsList); diff --git a/lib/services/options.service.ts b/lib/services/options.service.ts index c046e01e..ef2cc975 100644 --- a/lib/services/options.service.ts +++ b/lib/services/options.service.ts @@ -20,7 +20,8 @@ const OPTION_NAMES = new Set([ 'noAutoAuth', 'pathInMiddlePanel', 'untrustedSpec', - 'hideLoading' + 'hideLoading', + 'ignoredHeaderParameters', ]); export interface Options { @@ -38,6 +39,7 @@ export interface Options { untrustedSpec?: boolean; hideLoading?: boolean; spec?: any; + ignoredHeaderParameters?: string[]; } @Injectable()