Skip to content

Commit

Permalink
Fix response list for shared schemas (fixes #177)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jan 4, 2017
1 parent 7787738 commit 73bfb18
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
57 changes: 57 additions & 0 deletions lib/components/ResponsesList/responses-list.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';

import { Component } from '@angular/core';
import {
inject,
async,
TestBed,
ComponentFixture
} from '@angular/core/testing';

import { getChildDebugElement } from '../../../tests/helpers';


import { ResponsesList } from './responses-list';
import { SpecManager } from '../../utils/spec-manager';

describe('Redoc components', () => {

describe('MethodsList Component', () => {
let builder;
let component: ResponsesList;
let fixture: ComponentFixture<ResponsesList>
let specMgr;

beforeEach(async(inject([SpecManager], (_specMgr) => {
specMgr = _specMgr;
})));

beforeEach(done => {
specMgr.load('/tests/schemas/responses-list-component.json').then(done, done.fail);
});

beforeEach(() => {
fixture = TestBed.createComponent(ResponsesList);
component = fixture.componentInstance;
});

it('should instantiate without errors', () => {
should.exist(component);
});

it('should init repsonses list', () => {
component.pointer = '#/paths/~1test1/get/responses';
fixture.detectChanges();
should.exist(component.responses);
component.responses.should.be.lengthOf(2);
});

it('should not overwrite codes for shared schemas', () => {
component.pointer = '#/paths/~1test1/get/responses';
fixture.detectChanges();
let resp1 = component.responses[0];
let resp2 = component.responses[1];
resp1.code.should.not.be.equal(resp2.code);
});
});
});
2 changes: 1 addition & 1 deletion lib/components/ResponsesList/responses-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ResponsesList extends BaseComponent implements OnInit {
resp.pointer = JsonPointer.join(this.pointer, respCode);
if (resp.$ref) {
let ref = resp.$ref;
resp = this.specMgr.byPointer(resp.$ref);
resp = Object.assign({}, this.specMgr.byPointer(resp.$ref));
resp.pointer = ref;
}

Expand Down
41 changes: 41 additions & 0 deletions tests/schemas/responses-list-component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"swagger": "2.0",
"info": {
},
"host": "petstore.swagger.io",
"basePath": "/v2/",
"tags": [{
"name": "traitTag",
"x-traitTag": true,
"description": "description1"
},{
"name": "tag1",
"description": "tag1",
}],
"schemes": ["http"],
"paths": {
"/test1": {
"get": {
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/def1"
}
},
"201": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/def1"
}
}
}
}
}
},
"definitions": {
"def1": {
"type": "string"
}
}
}

0 comments on commit 73bfb18

Please sign in to comment.