feat: add ignoredHeaderParameters option

This commit is contained in:
Roman Hotsiy 2017-09-21 01:18:38 +03:00
parent 9aac636687
commit 56d62e5ab2
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 47 additions and 13 deletions

View File

@ -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-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-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-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
### `<redoc>` tag attributes ### `<redoc>` tag attributes
* `spec-url` - relative or absolute url to your spec file; * `spec-url` - relative or absolute url to your spec file;

View File

@ -54,7 +54,28 @@ x-tagGroups:
- Secondary Stats - Secondary Stats
``` ```
#### <a name="logoObject"></a>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 ### Info Object vendor extensions
Extends OpenAPI [Info Object](http://swagger.io/specification/#infoObject) Extends OpenAPI [Info Object](http://swagger.io/specification/#infoObject)

View File

@ -1,7 +1,8 @@
'use strict'; import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { Component, Input, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { BaseComponent, SpecManager } from '../base'; import { OptionsService } from '../../services/options.service';
import { SchemaHelper } from '../../services/schema-helper.service'; import { SchemaHelper } from '../../services/schema-helper.service';
import { BaseComponent, SpecManager } from '../base';
function safePush(obj, prop, item) { function safePush(obj, prop, item) {
if (!obj[prop]) obj[prop] = []; if (!obj[prop]) obj[prop] = [];
@ -12,16 +13,16 @@ function safePush(obj, prop, item) {
selector: 'params-list', selector: 'params-list',
templateUrl: './params-list.html', templateUrl: './params-list.html',
styleUrls: ['./params-list.css'], styleUrls: ['./params-list.css'],
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class ParamsList extends BaseComponent implements OnInit { export class ParamsList extends BaseComponent implements OnInit {
@Input() pointer:string; @Input() pointer: string;
params: Array<any>; params: Array<any>;
empty: boolean; empty: boolean;
bodyParam: any; bodyParam: any;
constructor(specMgr:SpecManager) { constructor(specMgr: SpecManager, private options: OptionsService) {
super(specMgr); super(specMgr);
} }
@ -29,11 +30,20 @@ export class ParamsList extends BaseComponent implements OnInit {
this.params = []; this.params = [];
let paramsList = this.specMgr.getOperationParams(this.pointer); let paramsList = this.specMgr.getOperationParams(this.pointer);
paramsList = paramsList.map(paramSchema => { const igrnoredHeaders =
let propPointer = paramSchema._pointer; this.specMgr.schema['x-ignoredHeaderParameters'] ||
if (paramSchema.in === 'body') return paramSchema; this.options.options.ignoredHeaderParameters ||
return SchemaHelper.preprocess(paramSchema, propPointer, this.pointer); [];
});
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); let paramsMap = this.orderParams(paramsList);

View File

@ -20,7 +20,8 @@ const OPTION_NAMES = new Set([
'noAutoAuth', 'noAutoAuth',
'pathInMiddlePanel', 'pathInMiddlePanel',
'untrustedSpec', 'untrustedSpec',
'hideLoading' 'hideLoading',
'ignoredHeaderParameters',
]); ]);
export interface Options { export interface Options {
@ -38,6 +39,7 @@ export interface Options {
untrustedSpec?: boolean; untrustedSpec?: boolean;
hideLoading?: boolean; hideLoading?: boolean;
spec?: any; spec?: any;
ignoredHeaderParameters?: string[];
} }
@Injectable() @Injectable()