From b9740bfe55b3c29dc215b6fc12320d970c21fd0d Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 30 Mar 2017 15:17:08 +0300 Subject: [PATCH 1/3] refactor: renamve Method to Operation --- README.md | 2 +- .../EndpointLink/endpoint-link.html | 6 +-- .../EndpointLink/endpoint-link.scss | 8 +-- .../EndpointLink/endpoint-link.spec.ts | 4 +- .../JsonSchema/json-schema-lazy.spec.ts | 2 +- lib/components/JsonSchema/json-schema.spec.ts | 2 +- lib/components/Method/method.html | 30 ------------ lib/components/Operation/operation.html | 30 ++++++++++++ .../method.scss => Operation/operation.scss} | 28 +++++------ .../operation.spec.ts} | 18 +++---- .../method.ts => Operation/operation.ts} | 22 ++++----- .../operations-list.html} | 8 +-- .../operations-list.scss} | 2 +- .../operations-list.spec.ts} | 10 ++-- .../operations-list.ts} | 12 ++--- lib/components/ParamsList/params-list.ts | 2 +- lib/components/Redoc/redoc.html | 2 +- lib/components/Redoc/redoc.ts | 18 ++++++- .../ResponsesList/responses-list.spec.ts | 2 +- lib/components/SideMenu/side-menu-items.scss | 2 +- lib/components/SideMenu/side-menu.spec.ts | 6 +-- lib/components/SideMenu/side-menu.ts | 23 +++++++-- lib/components/index.ts | 10 ++-- lib/redoc.module.ts | 9 +--- lib/services/hash.service.spec.ts | 2 +- lib/services/menu.service.spec.ts | 26 +++++----- lib/services/menu.service.ts | 49 ++++++++++--------- lib/services/schema-helper.service.ts | 34 ++++++------- lib/services/search.service.ts | 6 +-- lib/shared/styles/_variables.scss | 1 - lib/utils/spec-manager.ts | 18 +++---- lib/utils/swagger-defs.ts | 2 +- tests/e2e/redoc.e2e.js | 4 +- ...nt.json => operations-list-component.json} | 0 ...s.json => schema-mgr-operationParams.json} | 4 +- tests/unit/SpecManager.spec.ts | 22 ++++----- 36 files changed, 226 insertions(+), 200 deletions(-) delete mode 100644 lib/components/Method/method.html create mode 100644 lib/components/Operation/operation.html rename lib/components/{Method/method.scss => Operation/operation.scss} (76%) rename lib/components/{Method/method.spec.ts => Operation/operation.spec.ts} (70%) rename lib/components/{Method/method.ts => Operation/operation.ts} (76%) rename lib/components/{MethodsList/methods-list.html => OperationsList/operations-list.html} (64%) rename lib/components/{MethodsList/methods-list.scss => OperationsList/operations-list.scss} (97%) rename lib/components/{MethodsList/methods-list.spec.ts => OperationsList/operations-list.spec.ts} (79%) rename lib/components/{MethodsList/methods-list.ts => OperationsList/operations-list.ts} (74%) rename tests/schemas/{methods-list-component.json => operations-list-component.json} (100%) rename tests/schemas/{schema-mgr-methodparams.json => schema-mgr-operationParams.json} (93%) diff --git a/README.md b/README.md index bb44a39f..ffedfd87 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ ReDoc makes use of the following [vendor extensions](http://swagger.io/specifica * **function**: A getter function. Must return a number representing the offset (in pixels); * `suppress-warnings` - if set, warnings are not rendered at the top of documentation (they still are logged to the console). * `lazy-rendering` - if set, enables lazy rendering mode in ReDoc. This mode is useful for APIs with big number of operations (e.g. > 50). In this mode ReDoc shows initial screen ASAP and then renders the rest operations asynchronously while showing progress bar on the top. Check out the [demo](\\rebilly.github.io/ReDoc) for the example. -* `hide-hostname` - if set, the protocol and hostname is not shown in the method definition. +* `hide-hostname` - if set, the protocol and hostname is not shown in the operation definition. * `expand-responses` - specify which responses to expand by default by response codes. Values should be passed as comma-separated list without spaces e.g. `expand-responses="200,201"`. Special value `"all"` expands all responses by default. Be careful: this option can slow-down documentation rendering time. * `required-props-first` - show required properties first ordered in the same order as in `required` array. diff --git a/lib/components/EndpointLink/endpoint-link.html b/lib/components/EndpointLink/endpoint-link.html index 838bc08f..4e5bf5ba 100644 --- a/lib/components/EndpointLink/endpoint-link.html +++ b/lib/components/EndpointLink/endpoint-link.html @@ -1,7 +1,7 @@ -
+
{{verb}}
{{path}}{{path}}
@@ -11,7 +11,7 @@
- {{server.url}}{{path}} + {{server.url}}{{path}}
diff --git a/lib/components/EndpointLink/endpoint-link.scss b/lib/components/EndpointLink/endpoint-link.scss index 32d2d3a2..3bcbc510 100644 --- a/lib/components/EndpointLink/endpoint-link.scss +++ b/lib/components/EndpointLink/endpoint-link.scss @@ -6,7 +6,7 @@ cursor: pointer; } -.method-endpoint { +.operation-endpoint { padding: 10px 30px 10px 20px; border-radius: $border-radius*2; background-color: darken($black, 2%); @@ -18,7 +18,7 @@ border: 1px solid transparent; } -.method-endpoint > .method-params-subheader { +.operation-endpoint > .operation-params-subheader { padding-top: 1px; padding-bottom: 0; margin: 0; @@ -29,7 +29,7 @@ border-radius: $border-radius; } -.method-api-url { +.operation-api-url { color: rgba($black, .8); &-path { font-family: $headers-font, $headers-font-family; @@ -96,7 +96,7 @@ transition: all 0.25s ease; } :host.expanded { - > .method-endpoint { + > .operation-endpoint { border-color: $side-bar-bg-color; border-bottom-left-radius: 0; border-bottom-right-radius: 0; diff --git a/lib/components/EndpointLink/endpoint-link.spec.ts b/lib/components/EndpointLink/endpoint-link.spec.ts index 880ac312..ac0e50f5 100644 --- a/lib/components/EndpointLink/endpoint-link.spec.ts +++ b/lib/components/EndpointLink/endpoint-link.spec.ts @@ -72,11 +72,11 @@ describe('Redoc components', () => { }); -/** Test component that contains a Method. */ +/** Test component that contains an Operation. */ @Component({ selector: 'test-app', template: - `` + `` }) class TestAppComponent { } diff --git a/lib/components/JsonSchema/json-schema-lazy.spec.ts b/lib/components/JsonSchema/json-schema-lazy.spec.ts index 9e6df677..abcbd7d9 100644 --- a/lib/components/JsonSchema/json-schema-lazy.spec.ts +++ b/lib/components/JsonSchema/json-schema-lazy.spec.ts @@ -45,7 +45,7 @@ describe('Redoc components', () => { }); -/** Test component that contains a Method. */ +/** Test component that contains a lazy schema. */ @Component({ selector: 'test-app', template: diff --git a/lib/components/JsonSchema/json-schema.spec.ts b/lib/components/JsonSchema/json-schema.spec.ts index c0e6248d..fc7d3f9c 100644 --- a/lib/components/JsonSchema/json-schema.spec.ts +++ b/lib/components/JsonSchema/json-schema.spec.ts @@ -57,7 +57,7 @@ describe('Redoc components', () => { }); -/** Test component that contains a Method. */ +/** Test component that contains a json schema. */ @Component({ selector: 'test-app', template: diff --git a/lib/components/Method/method.html b/lib/components/Method/method.html deleted file mode 100644 index 5bc116ce..00000000 --- a/lib/components/Method/method.html +++ /dev/null @@ -1,30 +0,0 @@ -
-
-

- {{method.summary}} -

- -

-

- - - -
-
-

Definition

- - - -
- - -
-
-
- -
-
-
diff --git a/lib/components/Operation/operation.html b/lib/components/Operation/operation.html new file mode 100644 index 00000000..c9303120 --- /dev/null +++ b/lib/components/Operation/operation.html @@ -0,0 +1,30 @@ +
+
+

+ {{operation.summary}} +

+ +

+

+ + + +
+
+

Definition

+ + + +
+ + +
+
+
+ +
+
+
diff --git a/lib/components/Method/method.scss b/lib/components/Operation/operation.scss similarity index 76% rename from lib/components/Method/method.scss rename to lib/components/Operation/operation.scss index 6194a628..171696e7 100644 --- a/lib/components/Method/method.scss +++ b/lib/components/Operation/operation.scss @@ -14,11 +14,11 @@ // border-bottom: 0; // } -.method-header { +.operation-header { margin-bottom: calc(1em - 6px); } -.method-tags { +.operation-tags { margin-top: 20px; > a { @@ -39,45 +39,45 @@ } } -.method-content, .method-samples { +.operation-content, .operation-samples { display: block; box-sizing: border-box; float: left; } -.method-content { +.operation-content { width: 100% - $samples-panel-width; padding: $section-spacing; } -.method-samples { +.operation-samples { color: $sample-panel-color; width: 40%; padding: $section-spacing; background: $samples-panel-bg-color; } -.method-samples header, -.method-samples > h5 { +.operation-samples header, +.operation-samples > h5 { color: $sample-panel-headers-color; text-transform: uppercase; } -.method-samples > h5 { +.operation-samples > h5 { margin-bottom: 8px; } -.method-samples schema-sample { +.operation-samples schema-sample { display: block; } -.method:after { +.operation:after { content: ""; display: table; clear:both; } -.method-description { +.operation-description { padding: 6px 0 10px 0; margin: 0; } @@ -87,15 +87,15 @@ } @media (max-width: $right-panel-squash-breakpoint) { - .methods:before { + .operations:before { display: none; } - .method-samples, .method-content { + .operation-samples, .operation-content { width: 100%; } - .method-samples { + .operation-samples { margin-top: 2em; } diff --git a/lib/components/Method/method.spec.ts b/lib/components/Operation/operation.spec.ts similarity index 70% rename from lib/components/Method/method.spec.ts rename to lib/components/Operation/operation.spec.ts index 0d4eb5fe..44be2aae 100644 --- a/lib/components/Method/method.spec.ts +++ b/lib/components/Operation/operation.spec.ts @@ -9,7 +9,7 @@ import { import { getChildDebugElement } from '../../../tests/helpers'; -import { Method } from './method'; +import { Operation } from './operation'; import { SpecManager } from '../../utils/spec-manager';; import { LazyTasksService } from '../../shared/components/LazyFor/lazy-for';; @@ -17,9 +17,9 @@ describe('Redoc components', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ TestAppComponent ] }); }); - describe('Method Component', () => { + describe('Operation Component', () => { let builder; - let component: Method; + let component: Operation; let specMgr; beforeEach(async(inject([SpecManager, LazyTasksService], (_specMgr, lazyTasks) => { @@ -33,7 +33,7 @@ describe('Redoc components', () => { beforeEach(() => { let fixture = TestBed.createComponent(TestAppComponent); - component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; + component = getChildDebugElement(fixture.debugElement, 'operation').componentInstance; fixture.detectChanges(); }); @@ -43,23 +43,23 @@ describe('Redoc components', () => { }); it('should init basic component data', () => { - component.method.verb.should.be.equal('put'); - component.method.path.should.be.equal('/user/{username}'); + component.operation.verb.should.be.equal('put'); + component.operation.path.should.be.equal('/user/{username}'); }); it('should main tag', () => { - component.method.info.tags.should.be.empty(); + component.operation.info.tags.should.be.empty(); }); }); }); -/** Test component that contains a Method. */ +/** Test component that contains a Operation. */ @Component({ selector: 'test-app', template: - `` + `` }) class TestAppComponent { } diff --git a/lib/components/Method/method.ts b/lib/components/Operation/operation.ts similarity index 76% rename from lib/components/Method/method.ts rename to lib/components/Operation/operation.ts index 7bb553d7..7931069a 100644 --- a/lib/components/Method/method.ts +++ b/lib/components/Operation/operation.ts @@ -6,7 +6,7 @@ import { SchemaHelper } from '../../services/schema-helper.service'; import { OptionsService, MenuService } from '../../services/'; -interface MethodInfo { +interface OperationInfo { verb: string; path: string; info: { @@ -23,18 +23,18 @@ interface MethodInfo { } @Component({ - selector: 'method', - templateUrl: './method.html', - styleUrls: ['./method.css'], + selector: 'operation', + templateUrl: './operation.html', + styleUrls: ['./operation.css'], changeDetection: ChangeDetectionStrategy.OnPush }) -export class Method extends BaseComponent implements OnInit { +export class Operation extends BaseComponent implements OnInit { @Input() pointer :string; @Input() parentTagId :string; @HostBinding('attr.operation-id') operationId; - method: MethodInfo; + operation: OperationInfo; constructor( specMgr:SpecManager, @@ -46,7 +46,7 @@ export class Method extends BaseComponent implements OnInit { init() { this.operationId = this.componentSchema.operationId; - this.method = { + this.operation = { verb: JsonPointer.baseName(this.pointer), path: JsonPointer.baseName(this.pointer, 2), info: { @@ -54,7 +54,7 @@ export class Method extends BaseComponent implements OnInit { tags: this.filterMainTags(this.componentSchema.tags) }, bodyParam: this.findBodyParam(), - summary: SchemaHelper.methodSummary(this.componentSchema), + summary: SchemaHelper.operationSummary(this.componentSchema), anchor: this.buildAnchor(), externalDocs: this.componentSchema.externalDocs }; @@ -62,7 +62,7 @@ export class Method extends BaseComponent implements OnInit { buildAnchor():string { return this.menu.hashFor(this.pointer, - { type: 'method', operationId: this.operationId, pointer: this.pointer }, + { type: 'operation', operationId: this.operationId, pointer: this.pointer }, this.parentTagId ); } @@ -73,8 +73,8 @@ export class Method extends BaseComponent implements OnInit { } findBodyParam() { - let pathParams = this.specMgr.getMethodParams(this.pointer); - let bodyParam = pathParams.find(param => param.in === 'body'); + let params = this.specMgr.getOperationParams(this.pointer); + let bodyParam = params.find(param => param.in === 'body'); return bodyParam; } diff --git a/lib/components/MethodsList/methods-list.html b/lib/components/OperationsList/operations-list.html similarity index 64% rename from lib/components/MethodsList/methods-list.html rename to lib/components/OperationsList/operations-list.html index 7daccd7c..0907c592 100644 --- a/lib/components/MethodsList/methods-list.html +++ b/lib/components/OperationsList/operations-list.html @@ -1,12 +1,12 @@ -
+

{{tag.name}}

- +
diff --git a/lib/components/MethodsList/methods-list.scss b/lib/components/OperationsList/operations-list.scss similarity index 97% rename from lib/components/MethodsList/methods-list.scss rename to lib/components/OperationsList/operations-list.scss index fe57d8c2..04f32b6f 100644 --- a/lib/components/MethodsList/methods-list.scss +++ b/lib/components/OperationsList/operations-list.scss @@ -32,7 +32,7 @@ margin-top: 0; } -.methods { +.operations { display: block; position: relative;; } diff --git a/lib/components/MethodsList/methods-list.spec.ts b/lib/components/OperationsList/operations-list.spec.ts similarity index 79% rename from lib/components/MethodsList/methods-list.spec.ts rename to lib/components/OperationsList/operations-list.spec.ts index 6d2d56da..6f613fcf 100644 --- a/lib/components/MethodsList/methods-list.spec.ts +++ b/lib/components/OperationsList/operations-list.spec.ts @@ -10,14 +10,14 @@ import { import { getChildDebugElement } from '../../../tests/helpers'; -import { MethodsList } from './methods-list'; +import { OperationsList } from './operations-list'; import { SpecManager } from '../../utils/spec-manager'; describe('Redoc components', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ TestAppComponent ] }); }); - describe('MethodsList Component', () => { + describe('OperationsList Component', () => { let builder; let component; let fixture; @@ -28,12 +28,12 @@ describe('Redoc components', () => { }))); beforeEach(done => { - specMgr.load('/tests/schemas/methods-list-component.json').then(done, done.fail); + specMgr.load('/tests/schemas/operations-list-component.json').then(done, done.fail); }); beforeEach(() => { fixture = TestBed.createComponent(TestAppComponent); - component = getChildDebugElement(fixture.debugElement, 'methods-list').componentInstance; + component = getChildDebugElement(fixture.debugElement, 'operations-list').componentInstance; fixture.detectChanges(); }); @@ -56,7 +56,7 @@ describe('Redoc components', () => { @Component({ selector: 'test-app', template: - `` + `` }) class TestAppComponent { } diff --git a/lib/components/MethodsList/methods-list.ts b/lib/components/OperationsList/operations-list.ts similarity index 74% rename from lib/components/MethodsList/methods-list.ts rename to lib/components/OperationsList/operations-list.ts index ba434ec5..a0284321 100644 --- a/lib/components/MethodsList/methods-list.ts +++ b/lib/components/OperationsList/operations-list.ts @@ -4,12 +4,12 @@ import { BaseComponent, SpecManager } from '../base'; import { MenuService } from '../../services/index'; @Component({ - selector: 'methods-list', - templateUrl: './methods-list.html', - styleUrls: ['./methods-list.css'], + selector: 'operations-list', + templateUrl: './operations-list.html', + styleUrls: ['./operations-list.css'], changeDetection: ChangeDetectionStrategy.OnPush }) -export class MethodsList extends BaseComponent implements OnInit { +export class OperationsList extends BaseComponent implements OnInit { @Input() pointer:string; tags:Array = []; @@ -26,13 +26,13 @@ export class MethodsList extends BaseComponent implements OnInit { items: [] }; flatMenuItems.forEach(menuItem => { - // skip items that are not bound to swagger tags/methods + // skip items that are not bound to swagger tags/operations if (!menuItem.metadata) return; if (menuItem.metadata.type === 'tag') { this.tags.push(menuItem); } - if (menuItem.metadata.type === 'method' && !menuItem.parent) { + if (menuItem.metadata.type === 'operation' && !menuItem.parent) { emptyTag.items.push(menuItem); } }); diff --git a/lib/components/ParamsList/params-list.ts b/lib/components/ParamsList/params-list.ts index 6878176b..281c68a6 100644 --- a/lib/components/ParamsList/params-list.ts +++ b/lib/components/ParamsList/params-list.ts @@ -27,7 +27,7 @@ export class ParamsList extends BaseComponent implements OnInit { init() { this.params = []; - let paramsList = this.specMgr.getMethodParams(this.pointer); + let paramsList = this.specMgr.getOperationParams(this.pointer); paramsList = paramsList.map(paramSchema => { let propPointer = paramSchema._pointer; diff --git a/lib/components/Redoc/redoc.html b/lib/components/Redoc/redoc.html index f0c0905a..49550648 100644 --- a/lib/components/Redoc/redoc.html +++ b/lib/components/Redoc/redoc.html @@ -17,7 +17,7 @@
- +