Skip to content

Commit

Permalink
fix: apply feedback
Browse files Browse the repository at this point in the history
inc update

Signed-off-by: Douglas McConnachie <[email protected]>
  • Loading branch information
dougal83 committed Apr 16, 2020
1 parent c2f7114 commit 3a4ddd5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 49 deletions.
23 changes: 0 additions & 23 deletions packages/openapi-v3/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// License text available at https://opensource.org/licenses/MIT

import {
ComponentsSpecBuilder,
OpenApiSpecBuilder,
OperationSpecBuilder,
aComponentsSpec,
anOpenApiSpec,
anOperationSpec,
} from '@loopback/openapi-spec-builder';
import {expect} from '@loopback/testlab';
import {ConsolidationEnhancer} from '../../../spec-enhancers/consolidate.spec-enhancer';
Expand All @@ -15,11 +15,11 @@ const consolidationEnhancer = new ConsolidationEnhancer();

describe('consolidateSchemaObjects', () => {
it('moves schema with title to component.schemas, replaces with reference', () => {
const INPUT_SPEC = new OpenApiSpecBuilder()
const INPUT_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -37,11 +37,11 @@ describe('consolidateSchemaObjects', () => {
)
.build();

const EXPECTED_SPEC = new OpenApiSpecBuilder()
const EXPECTED_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -53,7 +53,7 @@ describe('consolidateSchemaObjects', () => {
}),
)
.withComponents(
new ComponentsSpecBuilder().withSchema('loopback.example', {
aComponentsSpec().withSchema('loopback.example', {
title: 'loopback.example',
properties: {
test: {
Expand All @@ -68,11 +68,11 @@ describe('consolidateSchemaObjects', () => {
});

it('ignores schema without title property', () => {
const INPUT_SPEC = new OpenApiSpecBuilder()
const INPUT_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -93,11 +93,11 @@ describe('consolidateSchemaObjects', () => {
});

it('avoids naming collision', () => {
const INPUT_SPEC = new OpenApiSpecBuilder()
const INPUT_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -114,7 +114,7 @@ describe('consolidateSchemaObjects', () => {
}),
)
.withComponents(
new ComponentsSpecBuilder().withSchema('loopback.example', {
aComponentsSpec().withSchema('loopback.example', {
title: 'Different loopback.example exists',
properties: {
testDiff: {
Expand All @@ -125,11 +125,11 @@ describe('consolidateSchemaObjects', () => {
)
.build();

const EXPECTED_SPEC = new OpenApiSpecBuilder()
const EXPECTED_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -141,7 +141,7 @@ describe('consolidateSchemaObjects', () => {
}),
)
.withComponents(
new ComponentsSpecBuilder()
aComponentsSpec()
.withSchema('loopback.example', {
title: 'Different loopback.example exists',
properties: {
Expand All @@ -165,12 +165,12 @@ describe('consolidateSchemaObjects', () => {
});

it('consolidates same schema in multiple locations', () => {
const INPUT_SPEC = new OpenApiSpecBuilder()
const INPUT_SPEC = anOpenApiSpec()
.withOperation(
'get',
// first time has 'loopback.example'
'/path1',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -190,7 +190,7 @@ describe('consolidateSchemaObjects', () => {
'get',
// second time has 'loopback.example'
'/path2',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -208,11 +208,11 @@ describe('consolidateSchemaObjects', () => {
)
.build();

const EXPECTED_SPEC = new OpenApiSpecBuilder()
const EXPECTED_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/path1',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -226,7 +226,7 @@ describe('consolidateSchemaObjects', () => {
.withOperation(
'get',
'/path2',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -238,7 +238,7 @@ describe('consolidateSchemaObjects', () => {
}),
)
.withComponents(
new ComponentsSpecBuilder().withSchema('loopback.example', {
aComponentsSpec().withSchema('loopback.example', {
title: 'loopback.example',
properties: {
test: {
Expand All @@ -254,11 +254,11 @@ describe('consolidateSchemaObjects', () => {

it('obeys disabled option when set to true', () => {
consolidationEnhancer.disabled = true;
const INPUT_SPEC = new OpenApiSpecBuilder()
const INPUT_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ConsolidationEnhancer implements OASEnhancer {
@inject(CoreBindings.APPLICATION_CONFIG, {optional: true})
readonly config?: ApplicationConfig,
) {
this.disabled = !(this.config?.rest?.openApiSpec?.consolidate || true);
this.disabled = !(this.config?.rest?.openApiSpec?.consolidate ?? true);
}

modifySpec(spec: OpenApiSpec): OpenApiSpec {
Expand Down

0 comments on commit 3a4ddd5

Please sign in to comment.