Skip to content

Commit

Permalink
refactor: apply feedback
Browse files Browse the repository at this point in the history
apply feedback
  • Loading branch information
dougal83 committed Jan 11, 2020
1 parent 5f15308 commit 5f394d5
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {ConsolidateSchemaObjects, OpenAPIObject} from '../..';
import {ConsolidationEnhancer, OpenAPIObject} from '../../..';

describe('ConsolidateSchemaObjects', () => {
const consolidationEnhancer = new ConsolidationEnhancer();

describe('consolidateSchemaObjects', () => {
it('moves schema with title to component.schemas, replace with reference', () => {
const inputSpec: OpenAPIObject = {
openapi: '',
Expand All @@ -33,12 +35,12 @@ describe('ConsolidateSchemaObjects', () => {
},
paths: {
schema: {
$ref: '#/components/schemas/LoopbackExample',
$ref: '#/components/schemas/loopback.example',
},
},
components: {
schemas: {
LoopbackExample: {
'loopback.example': {
title: 'loopback.example',
properties: {
test: {
Expand All @@ -49,7 +51,7 @@ describe('ConsolidateSchemaObjects', () => {
},
},
};
expect(ConsolidateSchemaObjects(inputSpec)).to.eql(expectedSpec);
expect(consolidationEnhancer.modifySpec(inputSpec)).to.eql(expectedSpec);
});

it('ignores schema without title property', () => {
Expand All @@ -69,7 +71,7 @@ describe('ConsolidateSchemaObjects', () => {
},
},
};
expect(ConsolidateSchemaObjects(inputSpec)).to.eql(inputSpec);
expect(consolidationEnhancer.modifySpec(inputSpec)).to.eql(inputSpec);
});

it('Avoids naming collision', () => {
Expand All @@ -91,8 +93,8 @@ describe('ConsolidateSchemaObjects', () => {
},
components: {
schemas: {
LoopbackExample: {
title: 'Different LoopbackExample exists',
'loopback.example': {
title: 'Different loopback.example exists',
properties: {
testDiff: {
type: 'string',
Expand All @@ -110,20 +112,20 @@ describe('ConsolidateSchemaObjects', () => {
},
paths: {
schema: {
$ref: '#/components/schemas/LoopbackExample2',
$ref: '#/components/schemas/loopback.example1',
},
},
components: {
schemas: {
LoopbackExample: {
title: 'Different LoopbackExample exists',
'loopback.example': {
title: 'Different loopback.example exists',
properties: {
testDiff: {
type: 'string',
},
},
},
LoopbackExample2: {
'loopback.example1': {
title: 'loopback.example',
properties: {
test: {
Expand All @@ -134,7 +136,7 @@ describe('ConsolidateSchemaObjects', () => {
},
},
};
expect(ConsolidateSchemaObjects(inputSpec)).to.eql(expectedSpec);
expect(consolidationEnhancer.modifySpec(inputSpec)).to.eql(expectedSpec);
});

it('If array items has no title, copy parent title if exists', () => {
Expand All @@ -147,7 +149,7 @@ describe('ConsolidateSchemaObjects', () => {
paths: {
schema: {
myarray: {
title: 'my.array',
title: 'MyArray',
type: 'array',
items: {
properties: {
Expand All @@ -169,18 +171,18 @@ describe('ConsolidateSchemaObjects', () => {
paths: {
schema: {
myarray: {
title: 'my.array',
title: 'MyArray',
type: 'array',
items: {
$ref: '#/components/schemas/MyArray',
$ref: '#/components/schemas/MyArray.Items',
},
},
},
},
components: {
schemas: {
MyArray: {
title: 'my.array',
'MyArray.Items': {
title: 'MyArray.Items',
properties: {
test: {
type: 'string',
Expand All @@ -190,6 +192,6 @@ describe('ConsolidateSchemaObjects', () => {
},
},
};
expect(ConsolidateSchemaObjects(inputSpec)).to.eql(expectedSpec);
expect(consolidationEnhancer.modifySpec(inputSpec)).to.eql(expectedSpec);
});
});
106 changes: 0 additions & 106 deletions packages/openapi-v3/src/consolidate-schema.ts

This file was deleted.

Loading

0 comments on commit 5f394d5

Please sign in to comment.