From b8b3bf328e06796c9763ea85eb98a8b5645f15b6 Mon Sep 17 00:00:00 2001
From: Roman Hotsiy
Date: Sun, 30 Oct 2016 17:58:06 +0200
Subject: [PATCH] Security Definitions + other
---
demo/swagger.yaml | 1 -
lib/components/ApiInfo/api-info.html | 2 +-
.../security-definitions.html | 42 +++++++++++++++++-
.../security-definitions.scss | 44 +++++++++++--------
.../security-definitions.ts | 29 +++++++++++-
lib/redoc.module.ts | 25 ++++++++---
lib/services/index.ts | 3 ++
lib/services/menu.service.ts | 5 ++-
8 files changed, 118 insertions(+), 33 deletions(-)
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/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}}
-
+
diff --git a/lib/components/SecurityDefinitions/security-definitions.html b/lib/components/SecurityDefinitions/security-definitions.html
index 1a1955ad..864f239f 100644
--- a/lib/components/SecurityDefinitions/security-definitions.html
+++ b/lib/components/SecurityDefinitions/security-definitions.html
@@ -1,2 +1,40 @@
- Hello world
- {{message}} {{pointer}}
+
+
+
+
+
+
+ Security scheme type: |
+ {{def.details._displayType}} |
+
+
+ {{def.details.in}} parameter name: |
+ {{def.details.name}} |
+
+
+
+ OAuth2 Flow |
+ {{def.details.flow}} |
+
+
+ Authorization URL |
+ {{def.details.authorizationUrl}} |
+
+
+ Token URL |
+ {{def.details.tokenUrl}} |
+
+
+
+
+ OAuth2 Scopes
+
+
+ {{scopeName}} |
+ {{def.details.scopes[scopeName]}} |
+
+
+
+
+
diff --git a/lib/components/SecurityDefinitions/security-definitions.scss b/lib/components/SecurityDefinitions/security-definitions.scss
index 0c7c1a81..a587e985 100644
--- a/lib/components/SecurityDefinitions/security-definitions.scss
+++ b/lib/components/SecurityDefinitions/security-definitions.scss
@@ -1,28 +1,36 @@
@import '../../shared/styles/variables';
-.api-info-header {
- font-weight: normal;
+.security-definition:not(:last-of-type) {
+ border-bottom: 1px solid rgba($text-color, .3);
+ padding-bottom: 20px;
}
-:host > div {
- width: 60%;
- padding: 40px;
- box-sizing: border-box;
-
- @media (max-width: $right-panel-squash-breakpoint) {
- width: 100%;
- }
+h2, h3 {
+ color: $secondary-color;
}
-a.openapi-button {
- padding: 3px 8px 4px 8px;
- color: $primary-color;
- border: 1px solid $primary-color;
- margin-left: 0.5em;
- font-weight: normal;
+:host h2 {
+ margin-top: 40px;
}
-:host /deep/ [section] {
- padding-top: 60px;
+h3 {
+ margin: 1em 0;
+ font-size: 1em;
+}
+
+:host .redoc-markdown-block table {
margin-top: 20px;
}
+
+table.details th, table.details td {
+ font-weight: bold;
+ width: 200px;
+ max-width: 50%;
+}
+
+table.details th {
+ text-align: left;
+ padding: 6px;
+ text-transform: capitalize;
+ font-weight: normal;
+}
diff --git a/lib/components/SecurityDefinitions/security-definitions.ts b/lib/components/SecurityDefinitions/security-definitions.ts
index 401bb06e..b5cd30fc 100644
--- a/lib/components/SecurityDefinitions/security-definitions.ts
+++ b/lib/components/SecurityDefinitions/security-definitions.ts
@@ -1,7 +1,15 @@
'use strict';
-import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
+import { Component, ChangeDetectionStrategy, OnInit, HostListener } from '@angular/core';
import { SpecManager, BaseComponent } from '../base';
+import { ComponentParser } from '../../services/';
+
+const AUTH_TYPES = {
+ 'oauth2': 'OAuth2',
+ 'apiKey': 'API Key',
+ 'basic': 'Basic Authorization'
+}
+
@Component({
selector: 'security-definitions',
styleUrls: ['./security-definitions.css'],
@@ -11,12 +19,29 @@ import { SpecManager, BaseComponent } from '../base';
export class SecurityDefinitions extends BaseComponent implements OnInit {
info: any = {};
specUrl: String;
- message: string = 'Roman';
+ defs: any[];
+
+ static insertTagIntoDescription(md:string) {
+ if (ComponentParser.contains(md, 'security-definitions')) return md;
+ if (/^#\s?Authentication\s*$/mi.test(md)) return md;
+ return md + '\n# Authentication \n' + ComponentParser.build('security-definitions');
+ }
+
constructor(specMgr:SpecManager) {
super(specMgr);
}
init() {
+ this.componentSchema = this.componentSchema.securityDefinitions;
+ this.defs = Object.keys(this.componentSchema).map(name => {
+ let details = this.componentSchema[name];
+ details._displayType = AUTH_TYPES[details.type];
+ return {
+ name,
+ details
+ }
+ });
+
}
ngOnInit() {
diff --git a/lib/redoc.module.ts b/lib/redoc.module.ts
index ba6b4be1..16a1cf41 100644
--- a/lib/redoc.module.ts
+++ b/lib/redoc.module.ts
@@ -2,19 +2,27 @@ import { NgModule, ErrorHandler } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Redoc, SecurityDefinitions, REDOC_DIRECTIVES } from './components/index';
-import { REDOC_COMMON_DIRECTIVES } from './shared/components/index';
-import { REDOC_PIPES } from './utils/pipes';
+import { REDOC_COMMON_DIRECTIVES, DynamicNg2Wrapper } from './shared/components/index';
+import { REDOC_PIPES, KeysPipe } from './utils/pipes';
import { CustomErrorHandler } from './utils/'
-import { OptionsService, MenuService,
- ScrollService, Hash, WarningsService, AppStateService } from './services/';
+import {
+ OptionsService,
+ MenuService,
+ ScrollService,
+ Hash,
+ WarningsService,
+ AppStateService,
+ ComponentParser,
+ ContentProjector,
+ COMPONENT_PARSER_ALLOWED } from './services/';
import { SpecManager } from './utils/spec-manager';
@NgModule({
imports: [ CommonModule ],
- declarations: [ REDOC_DIRECTIVES, REDOC_COMMON_DIRECTIVES, REDOC_PIPES],
+ declarations: [ REDOC_DIRECTIVES, REDOC_COMMON_DIRECTIVES, REDOC_PIPES ],
bootstrap: [ Redoc ],
- entryComponents: [SecurityDefinitions],
+ entryComponents: [ SecurityDefinitions, DynamicNg2Wrapper ],
providers: [
SpecManager,
ScrollService,
@@ -23,7 +31,10 @@ import { SpecManager } from './utils/spec-manager';
WarningsService,
OptionsService,
AppStateService,
- { provide: ErrorHandler, useClass: CustomErrorHandler }
+ ComponentParser,
+ ContentProjector,
+ { provide: ErrorHandler, useClass: CustomErrorHandler },
+ { provide: COMPONENT_PARSER_ALLOWED, useValue: { 'security-definitions': SecurityDefinitions} }
],
exports: [Redoc]
})
diff --git a/lib/services/index.ts b/lib/services/index.ts
index aafde800..8a33b956 100644
--- a/lib/services/index.ts
+++ b/lib/services/index.ts
@@ -8,3 +8,6 @@ export * from './hash.service';
export * from './schema-normalizer.service';
export * from './schema-helper.service';
export * from './warnings.service';
+
+export * from './component-parser.service';
+export * from './content-projector.service';
diff --git a/lib/services/menu.service.ts b/lib/services/menu.service.ts
index eff2c2d3..8db4542c 100644
--- a/lib/services/menu.service.ts
+++ b/lib/services/menu.service.ts
@@ -141,11 +141,12 @@ export class MenuService {
let ptr = decodeURIComponent(hash.substr(namespace.length + 1));
if (namespace === 'operation') {
$el = this.getMethodElByOperId(ptr);
- } else {
+ } else if (namespace === 'tag'){
let sectionId = ptr.split('/')[0];
ptr = ptr.substr(sectionId.length) || null;
sectionId = namespace + (sectionId ? '/' + sectionId : '');
- $el = this.getMethodElByPtr(ptr, sectionId);
+ } else {
+ $el = this.getMethodElByPtr(null, namespace + '/' + ptr);
}
if ($el) this.scrollService.scrollTo($el);