diff --git a/packages/openapi-v3/package-lock.json b/packages/openapi-v3/package-lock.json index 4ef148770378..89b4f115bbb7 100644 --- a/packages/openapi-v3/package-lock.json +++ b/packages/openapi-v3/package-lock.json @@ -25,21 +25,6 @@ "integrity": "sha1-pSgtqWkKgSpiEoo0cIr0dqMI2UE=", "dev": true }, - "@types/json-schema": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz", - "integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==", - "dev": true - }, - "@types/json-schema-compare": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@types/json-schema-compare/-/json-schema-compare-0.2.0.tgz", - "integrity": "sha512-TtCXQjsCQi+fcandEbzDJhqyztpVM9c5mtGuk7Hf8yQsdaBpfjEkOicfydAEWB684wGCzUrV5ttvt9hCyDCoxA==", - "dev": true, - "requires": { - "@types/json-schema": "*" - } - }, "@types/lodash": { "version": "4.14.149", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.149.tgz", @@ -171,14 +156,6 @@ "deep-equal": "^1.0.0" } }, - "json-schema-compare": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/json-schema-compare/-/json-schema-compare-0.2.2.tgz", - "integrity": "sha512-c4WYmDKyJXhs7WWvAWm3uIYnfyWFoIp+JEoX34rctVvEkMYCPGhXtvmFFXiffBbxfZsvQ0RNnV5H7GvDF5HCqQ==", - "requires": { - "lodash": "^4.17.4" - } - }, "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", diff --git a/packages/rest/src/__tests__/unit/rest.server/consolidate.spec.extension.unit.ts b/packages/rest/src/__tests__/unit/rest.server/consolidate.spec.extension.unit.ts index b78cab62cb14..3cba032c8437 100644 --- a/packages/rest/src/__tests__/unit/rest.server/consolidate.spec.extension.unit.ts +++ b/packages/rest/src/__tests__/unit/rest.server/consolidate.spec.extension.unit.ts @@ -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'; @@ -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': { @@ -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': { @@ -53,7 +53,7 @@ describe('consolidateSchemaObjects', () => { }), ) .withComponents( - new ComponentsSpecBuilder().withSchema('loopback.example', { + aComponentsSpec().withSchema('loopback.example', { title: 'loopback.example', properties: { test: { @@ -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': { @@ -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': { @@ -114,7 +114,7 @@ describe('consolidateSchemaObjects', () => { }), ) .withComponents( - new ComponentsSpecBuilder().withSchema('loopback.example', { + aComponentsSpec().withSchema('loopback.example', { title: 'Different loopback.example exists', properties: { testDiff: { @@ -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': { @@ -141,7 +141,7 @@ describe('consolidateSchemaObjects', () => { }), ) .withComponents( - new ComponentsSpecBuilder() + aComponentsSpec() .withSchema('loopback.example', { title: 'Different loopback.example exists', properties: { @@ -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': { @@ -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': { @@ -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': { @@ -226,7 +226,7 @@ describe('consolidateSchemaObjects', () => { .withOperation( 'get', '/path2', - new OperationSpecBuilder().withResponse(200, { + anOperationSpec().withResponse(200, { description: 'Example', content: { 'application/json': { @@ -238,7 +238,7 @@ describe('consolidateSchemaObjects', () => { }), ) .withComponents( - new ComponentsSpecBuilder().withSchema('loopback.example', { + aComponentsSpec().withSchema('loopback.example', { title: 'loopback.example', properties: { test: { @@ -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': { diff --git a/packages/rest/src/spec-enhancers/consolidate.spec-enhancer.ts b/packages/rest/src/spec-enhancers/consolidate.spec-enhancer.ts index cf4ff32a8ced..9024f9300da1 100644 --- a/packages/rest/src/spec-enhancers/consolidate.spec-enhancer.ts +++ b/packages/rest/src/spec-enhancers/consolidate.spec-enhancer.ts @@ -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 {