-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: adding openapi-v3 #1046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: adding openapi-v3 #1046
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| Copyright (c) IBM Corp. 2018. All Rights Reserved. | ||
| Node module: @loopback/openapi-v3 | ||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| @loopback/openapi-v3 | ||
|
|
||
| This package contains: | ||
|
|
||
| * Decorators that describe LoopBack artifacts as OpenAPI 3.0.0 metadata. | ||
| * Utilities that transfer LoopBack metadata to OpenAPI 3.0.0 specifications. | ||
|
|
||
| ## Overview | ||
|
|
||
| The package has functions described above for LoopBack controller classes. | ||
| Decorators apply REST api mapping metadata to controller classes and their members. And utilities that inspect controller classes to build OpenAPI 3.0.0 specifications from REST API mapping metadata. | ||
|
|
||
| Functions for more artifacts will be added when we need. | ||
|
|
||
| ## Installation | ||
|
|
||
| ``` | ||
| $ npm install --save @loopback/openapi-v3 | ||
| ``` | ||
|
|
||
| ## Basic use | ||
|
|
||
| Currently this package only has spec generator for controllers. | ||
| It generates OpenAPI specifications for a given decorated controller class, including | ||
| `paths`, `components.schemas`, and `servers`. | ||
|
|
||
| Here is an example of calling function `getControllerSpec` to generate the OpenAPI spec: | ||
|
|
||
| ```js | ||
| import {api, getControllerSpec} from '@loopback/openapi-v3'; | ||
|
|
||
| @api(somePathSpec) | ||
| class MyController { | ||
| greet() { | ||
| return 'Hello world!'; | ||
| } | ||
| } | ||
|
|
||
| const myControllerSpec = getControllerSpec(MyController); | ||
| ``` | ||
|
|
||
| then the `myControllerSpec` will be: | ||
|
|
||
| ```js | ||
| { | ||
| openapi: '3.0.0', | ||
| info: { title: 'LoopBack Application', version: '1.0.0' }, | ||
| paths: { | ||
| '/greet': { | ||
| get: { | ||
| responses: { | ||
| '200': { | ||
| description: 'The string result.', | ||
| schema: { type: 'string' } | ||
| } | ||
| }, | ||
| 'x-operation-name': 'greet' | ||
| } | ||
| } | ||
| }, | ||
| servers: [ | ||
| {url: '/'} | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| For details of how to apply controller decorators, please check http://loopback.io/doc/en/lb4/Decorators.html#route-decorators | ||
|
|
||
| ## Related resources | ||
|
|
||
| See https://www.openapis.org/ and [version 3.0.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.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). | ||
|
|
||
| # Tests | ||
|
|
||
| run `npm test` from the root folder. | ||
|
|
||
| # Contributors | ||
|
|
||
| See [all contributors](https://github.com/strongloop/loopback-next/graphs/contributors). | ||
|
|
||
| # License | ||
|
|
||
| MIT | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "content": [ | ||
| "src/api-decorator.ts", | ||
| "src/controller-spec.ts", | ||
| "src/generate-schema.ts", | ||
| "src/index.ts", | ||
| "src/json-to-schema.ts", | ||
| "src/keys.ts", | ||
| "src/operation-decorator.ts", | ||
| "src/parameter-decorator.ts", | ||
| "src/request-body-decorator.ts" | ||
| ], | ||
| "codeSectionDepth": 6 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright IBM Corp. 2018. 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 | ||
|
|
||
| export * from './dist'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Copyright IBM Corp. 2018. 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 | ||
|
|
||
| module.exports = require('./dist'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Copyright IBM Corp. 2018. 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 | ||
|
|
||
| // DO NOT EDIT THIS FILE | ||
| // Add any aditional (re)exports to src/index.ts instead. | ||
| export * from './src'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| { | ||
| "name": "@loopback/openapi-v3", | ||
| "version": "0.1.0", | ||
| "description": "Processes openapi v3 related metadata", | ||
| "engines": { | ||
| "node": ">=8" | ||
| }, | ||
| "devDependencies": { | ||
| "@loopback/build": "^0.1.1", | ||
| "@loopback/openapi-spec-builder": "^0.1.1", | ||
| "@loopback/repository": "^0.1.1", | ||
| "@loopback/testlab": "^0.1.1", | ||
| "@types/debug": "0.0.30", | ||
| "@types/lodash": "^4.14.96" | ||
| }, | ||
| "scripts": { | ||
| "build": "lb-tsc es2017", | ||
| "build:apidocs": "lb-apidocs", | ||
| "clean": "lb-clean loopback-openapi-v3*.tgz dist* package", | ||
| "integration": "lb-mocha \"DIST/test/integration/**/*.js\"", | ||
| "prepublishOnly": "npm run build && npm run build:apidocs", | ||
| "pretest": "npm run build", | ||
| "test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/integration/**/*.js\"", | ||
| "unit": "lb-mocha \"DIST/test/unit/**/*.js\"", | ||
| "verify": "npm pack && tar xf loopback-openapi-v3*.tgz && tree package && npm run clean" | ||
| }, | ||
| "author": "IBM", | ||
| "copyright.owner": "IBM Corp.", | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "Swagger", | ||
| "OpenAPI Spec", | ||
| "TypeScript" | ||
| ], | ||
| "files": [ | ||
| "README.md", | ||
| "index.js", | ||
| "index.d.ts", | ||
| "dist/src", | ||
| "api-docs", | ||
| "src" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/strongloop/loopback-next.git" | ||
| }, | ||
| "dependencies": { | ||
| "@loopback/context": "^0.1.1", | ||
| "@loopback/openapi-v3-types": "^0.1.1", | ||
| "@loopback/repository-json-schema": "^0.1.1", | ||
| "debug": "^3.1.0", | ||
| "lodash": "^4.17.4" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright IBM Corp. 2018. 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 {ControllerSpec} from './controller-spec'; | ||
| import {ClassDecoratorFactory} from '@loopback/context'; | ||
| import {OAI3Keys} from './keys'; | ||
|
|
||
| /** | ||
| * Decorate the given Controller constructor with metadata describing | ||
| * the HTTP/REST API the Controller implements/provides. | ||
| * | ||
| * `@api` can be applied to controller classes. For example, | ||
| * ``` | ||
| * @api({basePath: '/my'}) | ||
| * class MyController { | ||
| * // ... | ||
| * } | ||
| * ``` | ||
| * | ||
| * @param spec OpenAPI specification describing the endpoints | ||
| * handled by this controller | ||
| * | ||
| * @decorator | ||
| */ | ||
| export function api(spec: ControllerSpec) { | ||
| return ClassDecoratorFactory.createDecorator<ControllerSpec>( | ||
| OAI3Keys.CLASS_KEY, | ||
| spec, | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
basePathgenerated here as well (I know it depends onsomePathSpec, but good for illustration)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope,
basePathis a spec property only exists for Swagger 2, in OpenAPI 3basePath,host,portare all merged intourl, seeURL structurein articlehttps://blog.readme.io/an-example-filled-guide-to-swagger-3-2/