Skip to content

Commit 4c2096c

Browse files
committed
feat(openapi-v3): remove dependency on openapi-v3-types
Move the definition of the type alias `OpenApiSpec` to a new file `types.ts`. Rework all imports from `@loopback/openapi-v3-types` to import from `types.ts` instead, remove the openapi-v3-types package from the dependencies too. Add the helper `createEmptyApiSpec()` to preserve backwards compatibility for code importing the helper from this package or its dependants like `@loopback/rest`. Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
1 parent ba0f907 commit 4c2096c

18 files changed

+115
-60
lines changed

packages/openapi-v3/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-v3/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"engines": {
66
"node": ">=8.9"
77
},
8+
"dependencies": {
9+
"@loopback/context": "^1.20.1",
10+
"openapi3-ts": "^1.3.0",
11+
"@loopback/repository-json-schema": "^1.7.2",
12+
"debug": "^4.1.1",
13+
"lodash": "^4.17.11"
14+
},
815
"devDependencies": {
916
"@loopback/build": "^2.0.2",
1017
"@loopback/eslint-config": "^1.1.2",
@@ -46,12 +53,5 @@
4653
"repository": {
4754
"type": "git",
4855
"url": "https://github.com/strongloop/loopback-next.git"
49-
},
50-
"dependencies": {
51-
"@loopback/context": "^1.20.1",
52-
"@loopback/openapi-v3-types": "^1.1.4",
53-
"@loopback/repository-json-schema": "^1.7.2",
54-
"debug": "^4.1.1",
55-
"lodash": "^4.17.11"
5656
}
5757
}

packages/openapi-v3/src/__tests__/integration/controller-spec.integration.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
import {
7-
OperationObject,
8-
ParameterObject,
9-
SchemaObject,
10-
} from '@loopback/openapi-v3-types';
116
import {Entity, model, property} from '@loopback/repository';
127
import {expect} from '@loopback/testlab';
138
import {
149
api,
1510
ControllerSpec,
1611
get,
1712
getControllerSpec,
13+
getModelSchemaRef,
14+
OperationObject,
1815
param,
16+
ParameterObject,
1917
post,
2018
requestBody,
21-
getModelSchemaRef,
19+
SchemaObject,
2220
} from '../..';
2321

2422
describe('controller spec', () => {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright IBM Corp. 2019. All Rights Reserved.
2+
// Node module: @loopback/openapi-v3
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
import {expect} from '@loopback/testlab';
7+
import {createEmptyApiSpec} from '../../types';
8+
9+
describe('createEmptyApiSpec', () => {
10+
it('sets version 3', () => {
11+
expect(createEmptyApiSpec().openapi).to.equal('3.0.0');
12+
});
13+
14+
it('sets the spec info object', () => {
15+
expect(createEmptyApiSpec().info).to.deepEqual({
16+
title: 'LoopBack Application',
17+
version: '1.0.0',
18+
});
19+
});
20+
21+
it('creates an empty paths object', () => {
22+
expect(createEmptyApiSpec().paths).to.deepEqual({});
23+
});
24+
25+
it('creates a default servers array', () => {
26+
expect(createEmptyApiSpec().servers).to.deepEqual([{url: '/'}]);
27+
});
28+
});

packages/openapi-v3/src/__tests__/unit/decorators/param/param-query.decorator.unit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
import {get, param, getControllerSpec} from '../../../..';
76
import {expect} from '@loopback/testlab';
8-
import {ParameterObject} from '@loopback/openapi-v3-types';
7+
import {get, getControllerSpec, param, ParameterObject} from '../../../..';
98

109
describe('Routing metadata for parameters', () => {
1110
describe('@param.query.string', () => {

packages/openapi-v3/src/__tests__/unit/decorators/param/param.decorator.unit.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
// License text available at https://opensource.org/licenses/MIT
55

66
import {anOperationSpec} from '@loopback/openapi-spec-builder';
7+
import {expect} from '@loopback/testlab';
78
import {
9+
get,
10+
getControllerSpec,
11+
operation,
812
OperationObject,
13+
param,
914
ParameterObject,
15+
patch,
1016
ResponsesObject,
11-
} from '@loopback/openapi-v3-types';
12-
import {expect} from '@loopback/testlab';
13-
import {get, getControllerSpec, operation, param, patch} from '../../../../';
17+
} from '../../../../';
1418

1519
describe('Routing metadata for parameters', () => {
1620
describe('@param', () => {

packages/openapi-v3/src/__tests__/unit/decorators/request-body/request-body-primitives.decorator.unit.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
import {Class} from '@loopback/repository';
7+
import {expect} from '@loopback/testlab';
68
import {
9+
ContentObject,
710
ControllerSpec,
11+
getControllerSpec,
812
post,
913
requestBody,
10-
getControllerSpec,
14+
SchemaObject,
1115
} from '../../../../';
12-
import {ContentObject, SchemaObject} from '@loopback/openapi-v3-types';
13-
import {Class} from '@loopback/repository';
14-
import {expect} from '@loopback/testlab';
1516

1617
describe('requestBody decorator', () => {
1718
context('for a primitive type', () => {

packages/openapi-v3/src/__tests__/unit/json-to-schema.unit.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
import {expect} from '@loopback/testlab';
7-
8-
import {SchemaObject} from '@loopback/openapi-v3-types';
9-
import {jsonToSchemaObject, jsonOrBooleanToJSON} from '../..';
106
import {JsonSchema} from '@loopback/repository-json-schema';
7+
import {expect} from '@loopback/testlab';
8+
import {jsonOrBooleanToJSON, jsonToSchemaObject, SchemaObject} from '../..';
119

1210
describe('jsonToSchemaObject', () => {
1311
it('does nothing when given an empty object', () => {

packages/openapi-v3/src/controller-spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
// License text available at https://opensource.org/licenses/MIT
55

66
import {DecoratorFactory, MetadataInspector} from '@loopback/context';
7+
import {
8+
getJsonSchema,
9+
getJsonSchemaRef,
10+
JsonSchemaOptions,
11+
} from '@loopback/repository-json-schema';
12+
import * as _ from 'lodash';
13+
import {resolveSchema} from './generate-schema';
14+
import {jsonToSchemaObject, SchemaRef} from './json-to-schema';
15+
import {OAI3Keys} from './keys';
716
import {
817
ComponentsObject,
918
ISpecificationExtension,
@@ -16,16 +25,7 @@ import {
1625
ResponseObject,
1726
SchemaObject,
1827
SchemasObject,
19-
} from '@loopback/openapi-v3-types';
20-
import {
21-
getJsonSchema,
22-
getJsonSchemaRef,
23-
JsonSchemaOptions,
24-
} from '@loopback/repository-json-schema';
25-
import * as _ from 'lodash';
26-
import {resolveSchema} from './generate-schema';
27-
import {jsonToSchemaObject, SchemaRef} from './json-to-schema';
28-
import {OAI3Keys} from './keys';
28+
} from './types';
2929

3030
const debug = require('debug')('loopback:openapi3:metadata:controller-spec');
3131

packages/openapi-v3/src/decorators/operation.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
import {OperationObject} from '@loopback/openapi-v3-types';
76
import {MethodDecoratorFactory} from '@loopback/context';
87
import {RestEndpoint} from '../controller-spec';
98
import {OAI3Keys} from '../keys';
9+
import {OperationObject} from '../types';
1010

1111
/**
1212
* Expose a Controller method as a REST API operation

0 commit comments

Comments
 (0)