diff --git a/packages/authentication/package.json b/packages/authentication/package.json new file mode 100644 index 000000000000..3e56dbf29fed --- /dev/null +++ b/packages/authentication/package.json @@ -0,0 +1,21 @@ +{ + "name": "@loopback/authentication", + "version": "4.0.0-alpha.1", + "description": "", + "main": "index", + "scripts": { + "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", + "integration": "mocha --opts ../../test/mocha.opts 'test/integration/**/*.ts'", + "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/integration/**/*.ts' 'test/acceptance/**/*.ts'", + "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'" + }, + "author": "IBM", + "license": "MIT", + "dependencies": { + }, + "devDependencies": { + "@loopback/openapi-spec-builder": "^4.0.0-alpha.1", + "@loopback/testlab": "^4.0.0-alpha.1", + "mocha": "^3.2.0" + } +} diff --git a/packages/authentication/test/acceptance/authentication/routing.acceptance.ts b/packages/authentication/test/acceptance/authentication/routing.acceptance.ts index 63b864345670..67be76997eec 100644 --- a/packages/authentication/test/acceptance/authentication/routing.acceptance.ts +++ b/packages/authentication/test/acceptance/authentication/routing.acceptance.ts @@ -6,7 +6,7 @@ import {Application, Server, api, OpenApiSpec, ParameterObject, OperationObject} from 'loopback'; import {Client} from 'loopback/test/support/client'; import {expect} from 'testlab'; -import {givenOpenApiSpec} from 'loopback/test/support/OpenApiSpecBuilder'; +import {givenOpenApiSpec} from '@loopback/openapi-spec-builder'; /* # Feature: Routing * - In order to build REST APIs diff --git a/packages/loopback/package.json b/packages/loopback/package.json index 99a9bde069a7..96b90879a028 100644 --- a/packages/loopback/package.json +++ b/packages/loopback/package.json @@ -21,6 +21,7 @@ "path-to-regexp": "^1.7.0" }, "devDependencies": { + "@loopback/openapi-spec-builder": "^4.0.0-alpha.1", "@loopback/testlab": "^4.0.0-alpha.1", "mocha": "^3.2.0" } diff --git a/packages/loopback/test/acceptance/routing/routing.acceptance.ts b/packages/loopback/test/acceptance/routing/routing.acceptance.ts index c6e0d82970ed..3d6c5266eb60 100644 --- a/packages/loopback/test/acceptance/routing/routing.acceptance.ts +++ b/packages/loopback/test/acceptance/routing/routing.acceptance.ts @@ -6,7 +6,7 @@ import {Application, Server, api, OpenApiSpec, ParameterObject, OperationObject} from '../../..'; import {Client} from './../../support/client'; import {expect} from 'testlab'; -import {givenOpenApiSpec} from '../../support/OpenApiSpecBuilder'; +import {givenOpenApiSpec} from '@loopback/openapi-spec-builder'; import {inject} from '@loopback/context'; /* # Feature: Routing diff --git a/packages/loopback/test/integration/router/SwaggerRouter.integration.ts b/packages/loopback/test/integration/router/SwaggerRouter.integration.ts index f49a035cb8b1..3834a48bc42a 100644 --- a/packages/loopback/test/integration/router/SwaggerRouter.integration.ts +++ b/packages/loopback/test/integration/router/SwaggerRouter.integration.ts @@ -11,7 +11,7 @@ import * as bluebird from 'bluebird'; import {expect} from 'testlab'; import {listen} from '../../support/util'; import {OpenApiSpec, ParameterObject} from '@loopback/openapi-spec'; -import {givenOpenApiSpec} from '../../support/OpenApiSpecBuilder'; +import {givenOpenApiSpec} from '@loopback/openapi-spec-builder'; describe('SwaggerRouter', () => { beforeEach(givenRouter); diff --git a/packages/openapi-spec-builder/LICENSE b/packages/openapi-spec-builder/LICENSE new file mode 100644 index 000000000000..dc243c3dd77f --- /dev/null +++ b/packages/openapi-spec-builder/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) IBM Corp. 2013,2017. All Rights Reserved. +Node module: @loopback/openapi-spec-builder +This project is licensed under the MIT License, full text below. + +-------- + +MIT license + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/openapi-spec-builder/README.md b/packages/openapi-spec-builder/README.md new file mode 100644 index 000000000000..190c1cd0e9c4 --- /dev/null +++ b/packages/openapi-spec-builder/README.md @@ -0,0 +1,74 @@ +# @loopback/openapi-spec-builder + +Make it easy to create OpenAPI (Swagger) specification documents in your +tests using the builder pattern. + +## Overview + +Creating a full OpenAPI spec document in automated tests is rather cumbersome, +long JSON-like objects pollute the test test code and make it difficult +for readers to distinguish between what's important in the test and what's just +shared swagger boilerplate. + +OpenApiSpecBuilder utilizes +[Test Data Builder pattern](http://www.natpryce.com/articles/000714.html) +to provide a TypeScript/JavaScript API allowing users to create +full OpenAPI Spec documents in few lines of code. + +## Installation + +```shell +$ npm install --save-dev @loopback/openapi-spec-builder +``` + +_This package is typically used in tests, save it to `devDependencies` via `--save-dev`._ + +## Basic use + +```ts +import {givenOpenApiSpec, OpenApiSpecBuilder} from '@loopback/openapi-spec-builder'; + +const spec = givenOpenApiSpec() + .withOperationReturningString('get', '/hello', 'greet') + .build(); + +// which is equivalent to the following longer form + +const spec = new OpenApiSpecBuilder() + .withOperation('get', '/hello', { + 'x-operation-name': 'greet', + responses: { + '200': { type: 'string' }, + }, + }) + .build(); + +// the spec + +const spec = { + basePath: '/', + paths: { + '/hello': { + get: { + 'x-operation-name': 'greet', + responses: { + '200': { type: 'string' }, + }, + } + } + } +}; +``` + +## Related resources + +See https://www.openapis.org/ and [version 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) +of OpenAPI Specification. + +## Contributions + +IBM/StrongLoop is an active supporter of open source and welcomes contributions to our projects as well as those of the Node.js community in general. For more information on how to contribute please refer to the [Contribution Guide](https://loopback.io/doc/en/contrib/index.html). + +## License + +MIT diff --git a/packages/openapi-spec-builder/index.ts b/packages/openapi-spec-builder/index.ts new file mode 100644 index 000000000000..f9e3b78698d3 --- /dev/null +++ b/packages/openapi-spec-builder/index.ts @@ -0,0 +1,6 @@ +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: @loopback/openapi-spec +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +export * from './src/OpenApiSpecBuilder'; diff --git a/packages/openapi-spec-builder/package.json b/packages/openapi-spec-builder/package.json new file mode 100644 index 000000000000..841ad6012562 --- /dev/null +++ b/packages/openapi-spec-builder/package.json @@ -0,0 +1,17 @@ +{ + "name": "@loopback/openapi-spec-builder", + "version": "4.0.0-alpha.1", + "description": "Make it easy to create OpenAPI (Swagger) specification documents in your tests using the builder pattern.", + "author": "IBM", + "license": "MIT", + "keywords": [ + "Swagger", + "OpenAPI Spec", + "TypeScript", + "Builder", + "Testing" + ], + "dependencies": { + "@loopback/openapi-spec": "^4.0.0-alpha.1" + } +} diff --git a/packages/loopback/test/support/OpenApiSpecBuilder.ts b/packages/openapi-spec-builder/src/OpenApiSpecBuilder.ts similarity index 100% rename from packages/loopback/test/support/OpenApiSpecBuilder.ts rename to packages/openapi-spec-builder/src/OpenApiSpecBuilder.ts