Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,15 @@ import * as _ from 'lodash';

// Import API fragments here

export let spec = OpenApiSpec.createEmptyApiSpec();
spec.info = {
title: 'Your API',
version: '1.0',
export const spec: OpenApiSpec = {
openapi: '3.0.0',
info: {
title: 'Your API',
version: '1.0',
},
paths: {},
servers: [{url: '/'}],
};
spec.swagger = '2.0';
spec.basePath = '/';

_.merge(spec, ProductAPI);
_.merge(spec, DealAPI);
Expand Down
6 changes: 2 additions & 4 deletions docs/site/Routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ be confused with `x-operation-name`, which is a string for the Controller method
name.

```ts
import {RestApplication} from '@loopback/rest';
import {OpenApiSpec} from '@loopback/openapi-v3-types';
import {OpenApiSpec, RestApplication} from '@loopback/rest';

function greet(name: string) {
return `hello ${name}`;
Expand Down Expand Up @@ -107,8 +106,7 @@ which is defined using `spec`. The route is then attached to a valid server
context running underneath the application.

```ts
import {RestApplication, Route} from '@loopback/rest';
import {OperationObject} from '@loopback/openapi-v3-types';
import {OperationObject, RestApplication, Route} from '@loopback/rest';

const spec: OperationObject = {
parameters: [{name: 'name', in: 'query', schema: {type: 'string'}}],
Expand Down
2 changes: 1 addition & 1 deletion docs/site/Sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ building sequences, you use LoopBack Elements to respond to a request:
docs link
- [`OperationRetVal`](https://loopback.io/doc/en/lb4/apidocs.rest.operationretval.html)
- [`ParseParams`](https://loopback.io/doc/en/lb4/apidocs.rest.parseparams.html)
- [`OpenAPISpec`](https://loopback.io/doc/en/lb4/apidocs.openapi-v3-types.openapispec.html)
- [`OpenAPISpec`](https://loopback.io/doc/en/lb4/apidocs.openapi-v3.openapispec.html)

## Actions

Expand Down
1 change: 0 additions & 1 deletion examples/todo-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@loopback/context": "^1.20.1",
"@loopback/core": "^1.8.4",
"@loopback/openapi-v3": "^1.6.4",
"@loopback/openapi-v3-types": "^1.1.4",
"@loopback/repository": "^1.8.1",
"@loopback/rest": "^1.16.2",
"@loopback/rest-explorer": "^1.2.4",
Expand Down
1 change: 0 additions & 1 deletion examples/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@loopback/context": "^1.20.1",
"@loopback/core": "^1.8.4",
"@loopback/openapi-v3": "^1.6.4",
"@loopback/openapi-v3-types": "^1.1.4",
"@loopback/repository": "^1.8.1",
"@loopback/rest": "^1.16.2",
"@loopback/rest-explorer": "^1.2.4",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ Run the following command to install the CLI.
- @loopback/core: ^1.1.7
- @loopback/metadata: ^1.0.7
- @loopback/openapi-spec-builder: ^1.0.7
- @loopback/openapi-v3-types: ^1.0.7
- @loopback/openapi-v3: ^1.2.3
- @loopback/repository-json-schema: ^1.3.3
- @loopback/repository: ^1.1.7
Expand Down
5 changes: 5 additions & 0 deletions packages/openapi-spec-builder/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/openapi-spec-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"Testing"
],
"dependencies": {
"@loopback/openapi-v3-types": "^1.1.4"
"openapi3-ts": "^1.3.0"
},
"devDependencies": {
"@loopback/build": "^2.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {createEmptyApiSpec, ParameterObject} from '@loopback/openapi-v3-types';
import {expect} from '@loopback/testlab';
import {ParameterObject} from 'openapi3-ts';
import {anOpenApiSpec, anOperationSpec} from '../../openapi-spec-builder';

describe('OpenAPI Spec Builder', () => {
describe('anOpenApiSpec', () => {
it('creates an empty spec', () => {
const spec = anOpenApiSpec().build();
expect(spec).to.eql(createEmptyApiSpec());
expect(spec).to.eql({
openapi: '3.0.0',
info: {
title: 'LoopBack Application',
version: '1.0.0',
},
paths: {},
servers: [{url: '/'}],
});
});

it('adds an extension', () => {
Expand Down
19 changes: 13 additions & 6 deletions packages/openapi-spec-builder/src/openapi-spec-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import * as assert from 'assert';
import {
createEmptyApiSpec,
ISpecificationExtension,
OpenApiSpec,
OpenAPIObject,
OperationObject,
ParameterObject,
RequestBodyObject,
ResponseObject,
} from '@loopback/openapi-v3-types';
import * as assert from 'assert';
} from 'openapi3-ts';

/**
* Create a new instance of OpenApiSpecBuilder.
Expand Down Expand Up @@ -71,12 +70,20 @@ export class BuilderBase<T extends ISpecificationExtension> {
/**
* A builder for creating OpenApiSpec documents.
*/
export class OpenApiSpecBuilder extends BuilderBase<OpenApiSpec> {
export class OpenApiSpecBuilder extends BuilderBase<OpenAPIObject> {
/**
* @param basePath - The base path on which the API is served.
*/
constructor() {
super(createEmptyApiSpec());
super({
openapi: '3.0.0',
info: {
title: 'LoopBack Application',
version: '1.0.0',
},
paths: {},
servers: [{url: '/'}],
});
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/openapi-v3-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ TypeScript type definitions for OpenAPI Spec/Swagger documents.
TypeScript definitions describing the schema of OpenAPI/Swagger documents,
including LoopBack-specific extensions.

**This package is deprecated, use
[openapi3-ts](https://www.npmjs.com/package/openapi3-ts) or
[@loopback/openapi-v3](https://www.npmjs.com/package/@loopback/openapi-v3)
instead.**

## Installation

```sh
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-v3-types/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@loopback/openapi-v3-types",
"version": "1.1.4",
"description": "TypeScript type definitions for OpenAPI Specifications.",
"description": "[DEPRECATED] TypeScript type definitions for OpenAPI Specifications.",
"engines": {
"node": ">=8.9"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/openapi-v3/package-lock.json

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

14 changes: 7 additions & 7 deletions packages/openapi-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
"engines": {
"node": ">=8.9"
},
"dependencies": {
"@loopback/context": "^1.20.1",
"openapi3-ts": "^1.3.0",
"@loopback/repository-json-schema": "^1.7.2",
"debug": "^4.1.1",
"lodash": "^4.17.11"
},
"devDependencies": {
"@loopback/build": "^2.0.2",
"@loopback/eslint-config": "^1.1.2",
Expand Down Expand Up @@ -46,12 +53,5 @@
"repository": {
"type": "git",
"url": "https://github.com/strongloop/loopback-next.git"
},
"dependencies": {
"@loopback/context": "^1.20.1",
"@loopback/openapi-v3-types": "^1.1.4",
"@loopback/repository-json-schema": "^1.7.2",
"debug": "^4.1.1",
"lodash": "^4.17.11"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {
OperationObject,
ParameterObject,
SchemaObject,
} from '@loopback/openapi-v3-types';
import {Entity, model, property} from '@loopback/repository';
import {expect} from '@loopback/testlab';
import {
api,
ControllerSpec,
get,
getControllerSpec,
getModelSchemaRef,
OperationObject,
param,
ParameterObject,
post,
requestBody,
getModelSchemaRef,
SchemaObject,
} from '../..';

describe('controller spec', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright IBM Corp. 2019. All Rights Reserved.
// Node module: @loopback/openapi-v3
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {createEmptyApiSpec} from '../../types';

describe('createEmptyApiSpec', () => {
it('sets version 3', () => {
expect(createEmptyApiSpec().openapi).to.equal('3.0.0');
});

it('sets the spec info object', () => {
expect(createEmptyApiSpec().info).to.deepEqual({
title: 'LoopBack Application',
version: '1.0.0',
});
});

it('creates an empty paths object', () => {
expect(createEmptyApiSpec().paths).to.deepEqual({});
});

it('creates a default servers array', () => {
expect(createEmptyApiSpec().servers).to.deepEqual([{url: '/'}]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {get, param, getControllerSpec} from '../../../..';
import {expect} from '@loopback/testlab';
import {ParameterObject} from '@loopback/openapi-v3-types';
import {get, getControllerSpec, param, ParameterObject} from '../../../..';

describe('Routing metadata for parameters', () => {
describe('@param.query.string', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
// License text available at https://opensource.org/licenses/MIT

import {anOperationSpec} from '@loopback/openapi-spec-builder';
import {expect} from '@loopback/testlab';
import {
get,
getControllerSpec,
operation,
OperationObject,
param,
ParameterObject,
patch,
ResponsesObject,
} from '@loopback/openapi-v3-types';
import {expect} from '@loopback/testlab';
import {get, getControllerSpec, operation, param, patch} from '../../../../';
} from '../../../../';

describe('Routing metadata for parameters', () => {
describe('@param', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Class} from '@loopback/repository';
import {expect} from '@loopback/testlab';
import {
ContentObject,
ControllerSpec,
getControllerSpec,
post,
requestBody,
getControllerSpec,
SchemaObject,
} from '../../../../';
import {ContentObject, SchemaObject} from '@loopback/openapi-v3-types';
import {Class} from '@loopback/repository';
import {expect} from '@loopback/testlab';

describe('requestBody decorator', () => {
context('for a primitive type', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';

import {SchemaObject} from '@loopback/openapi-v3-types';
import {jsonToSchemaObject, jsonOrBooleanToJSON} from '../..';
import {JsonSchema} from '@loopback/repository-json-schema';
import {expect} from '@loopback/testlab';
import {jsonOrBooleanToJSON, jsonToSchemaObject, SchemaObject} from '../..';

describe('jsonToSchemaObject', () => {
it('does nothing when given an empty object', () => {
Expand Down
20 changes: 10 additions & 10 deletions packages/openapi-v3/src/controller-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
// License text available at https://opensource.org/licenses/MIT

import {DecoratorFactory, MetadataInspector} from '@loopback/context';
import {
getJsonSchema,
getJsonSchemaRef,
JsonSchemaOptions,
} from '@loopback/repository-json-schema';
import * as _ from 'lodash';
import {resolveSchema} from './generate-schema';
import {jsonToSchemaObject, SchemaRef} from './json-to-schema';
import {OAI3Keys} from './keys';
import {
ComponentsObject,
ISpecificationExtension,
Expand All @@ -16,16 +25,7 @@ import {
ResponseObject,
SchemaObject,
SchemasObject,
} from '@loopback/openapi-v3-types';
import {
getJsonSchema,
getJsonSchemaRef,
JsonSchemaOptions,
} from '@loopback/repository-json-schema';
import * as _ from 'lodash';
import {resolveSchema} from './generate-schema';
import {jsonToSchemaObject, SchemaRef} from './json-to-schema';
import {OAI3Keys} from './keys';
} from './types';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {OperationObject} from '@loopback/openapi-v3-types';
import {MethodDecoratorFactory} from '@loopback/context';
import {RestEndpoint} from '../controller-spec';
import {OAI3Keys} from '../keys';
import {OperationObject} from '../types';

/**
* Expose a Controller method as a REST API operation
Expand Down
Loading