@loopback/openapi-spec-builder 4.0.0-alpha.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +57 -28
- package/dist/index.d.ts +18 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi-spec-builder.d.ts +188 -0
- package/dist/openapi-spec-builder.js +352 -0
- package/dist/openapi-spec-builder.js.map +1 -0
- package/package.json +37 -24
- package/src/index.ts +24 -0
- package/src/openapi-spec-builder.ts +394 -0
- package/api-docs/apple-touch-icon-114x114-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-144x144-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-57x57-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-72x72-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-precomposed.png +0 -0
- package/api-docs/apple-touch-icon.png +0 -0
- package/api-docs/css/bootstrap.min.css +0 -9
- package/api-docs/css/code-themes/arta.css +0 -158
- package/api-docs/css/code-themes/ascetic.css +0 -50
- package/api-docs/css/code-themes/brown_paper.css +0 -104
- package/api-docs/css/code-themes/brown_papersq.png +0 -0
- package/api-docs/css/code-themes/dark.css +0 -103
- package/api-docs/css/code-themes/default.css +0 -135
- package/api-docs/css/code-themes/far.css +0 -111
- package/api-docs/css/code-themes/github.css +0 -127
- package/api-docs/css/code-themes/googlecode.css +0 -144
- package/api-docs/css/code-themes/idea.css +0 -121
- package/api-docs/css/code-themes/ir_black.css +0 -104
- package/api-docs/css/code-themes/magula.css +0 -121
- package/api-docs/css/code-themes/monokai.css +0 -114
- package/api-docs/css/code-themes/pojoaque.css +0 -104
- package/api-docs/css/code-themes/pojoaque.jpg +0 -0
- package/api-docs/css/code-themes/rainbow.css +0 -114
- package/api-docs/css/code-themes/school_book.css +0 -111
- package/api-docs/css/code-themes/school_book.png +0 -0
- package/api-docs/css/code-themes/sl-theme.css +0 -45
- package/api-docs/css/code-themes/solarized_dark.css +0 -88
- package/api-docs/css/code-themes/solarized_light.css +0 -88
- package/api-docs/css/code-themes/sunburst.css +0 -158
- package/api-docs/css/code-themes/tomorrow-night-blue.css +0 -52
- package/api-docs/css/code-themes/tomorrow-night-bright.css +0 -51
- package/api-docs/css/code-themes/tomorrow-night-eighties.css +0 -51
- package/api-docs/css/code-themes/tomorrow-night.css +0 -52
- package/api-docs/css/code-themes/tomorrow.css +0 -49
- package/api-docs/css/code-themes/vs.css +0 -86
- package/api-docs/css/code-themes/xcode.css +0 -154
- package/api-docs/css/code-themes/zenburn.css +0 -115
- package/api-docs/css/main.css +0 -139
- package/api-docs/favicon.ico +0 -0
- package/api-docs/fonts/0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/fonts/OsJ2DjdpjqFRVUSto6IffLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/fonts/_aijTyevf54tkVDLy-dlnLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/index.html +0 -1021
- package/api-docs/js/main.js +0 -19
- package/api-docs/js/vendor/bootstrap.min.js +0 -6
- package/api-docs/js/vendor/jquery-1.10.1.min.js +0 -6
- package/api-docs/js/vendor/jquery.scrollTo-1.4.3.1.js +0 -218
- package/api-docs/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js +0 -11
- package/index.d.ts +0 -6
- package/index.js +0 -9
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -11
- package/lib/index.js.map +0 -1
- package/lib/openapi-spec-builder.d.ts +0 -82
- package/lib/openapi-spec-builder.js +0 -138
- package/lib/openapi-spec-builder.js.map +0 -1
- package/lib6/index.d.ts +0 -1
- package/lib6/index.js +0 -11
- package/lib6/index.js.map +0 -1
- package/lib6/openapi-spec-builder.d.ts +0 -82
- package/lib6/openapi-spec-builder.js +0 -138
- package/lib6/openapi-spec-builder.js.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,82 +1,111 @@
|
|
|
1
1
|
# @loopback/openapi-spec-builder
|
|
2
2
|
|
|
3
|
-
Make it easy to create OpenAPI
|
|
4
|
-
|
|
3
|
+
Make it easy to create OpenAPI specification documents in your tests using the
|
|
4
|
+
builder pattern.
|
|
5
5
|
|
|
6
6
|
## Overview
|
|
7
7
|
|
|
8
8
|
Creating a full OpenAPI spec document in automated tests is rather cumbersome,
|
|
9
|
-
long JSON-like objects pollute the test test code and make it difficult
|
|
10
|
-
|
|
11
|
-
shared
|
|
9
|
+
long JSON-like objects pollute the test test code and make it difficult for
|
|
10
|
+
readers to distinguish between what's important in the test and what's just
|
|
11
|
+
shared OpenAPI boilerplate.
|
|
12
12
|
|
|
13
13
|
OpenApiSpecBuilder utilizes
|
|
14
|
-
[Test Data Builder pattern](http://www.natpryce.com/articles/000714.html)
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
[Test Data Builder pattern](http://www.natpryce.com/articles/000714.html) to
|
|
15
|
+
provide a TypeScript/JavaScript API allowing users to create full OpenAPI Spec
|
|
16
|
+
documents in few lines of code.
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
|
-
```
|
|
21
|
-
|
|
20
|
+
```sh
|
|
21
|
+
npm install --save-dev @loopback/openapi-spec-builder
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
_This package is typically used in tests, save it to `devDependencies` via
|
|
24
|
+
_This package is typically used in tests, save it to `devDependencies` via
|
|
25
|
+
`--save-dev`._
|
|
25
26
|
|
|
26
27
|
## Basic use
|
|
27
28
|
|
|
28
29
|
```ts
|
|
29
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
anOpenApiSpec,
|
|
32
|
+
OpenApiSpecBuilder,
|
|
33
|
+
} from '@loopback/openapi-spec-builder';
|
|
30
34
|
|
|
31
|
-
const spec =
|
|
35
|
+
const spec = anOpenApiSpec()
|
|
32
36
|
.withOperationReturningString('get', '/hello', 'greet')
|
|
33
37
|
.build();
|
|
34
38
|
|
|
35
39
|
// which is equivalent to the following longer form
|
|
36
|
-
|
|
37
40
|
const spec = new OpenApiSpecBuilder()
|
|
38
41
|
.withOperation('get', '/hello', {
|
|
39
42
|
'x-operation-name': 'greet',
|
|
40
43
|
responses: {
|
|
41
|
-
'200': {
|
|
44
|
+
'200': {
|
|
45
|
+
description: 'The string result.',
|
|
46
|
+
content: {
|
|
47
|
+
'text/plain': {
|
|
48
|
+
schema: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
42
54
|
},
|
|
43
55
|
})
|
|
44
56
|
.build();
|
|
45
57
|
|
|
46
58
|
// the spec
|
|
47
|
-
|
|
48
59
|
const spec = {
|
|
49
|
-
|
|
60
|
+
openapi: '3.0.0',
|
|
61
|
+
info: {title: 'LoopBack Application', version: '1.0.0'},
|
|
62
|
+
servers: [
|
|
63
|
+
{
|
|
64
|
+
url: '/',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
50
67
|
paths: {
|
|
51
68
|
'/hello': {
|
|
52
69
|
get: {
|
|
53
70
|
'x-operation-name': 'greet',
|
|
54
71
|
responses: {
|
|
55
|
-
'200': {
|
|
72
|
+
'200': {
|
|
73
|
+
description: 'The string result.',
|
|
74
|
+
content: {
|
|
75
|
+
'text/plain': {
|
|
76
|
+
schema: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
56
82
|
},
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
60
86
|
};
|
|
61
87
|
```
|
|
62
88
|
|
|
63
89
|
## Related resources
|
|
64
90
|
|
|
65
|
-
See https://www.openapis.org
|
|
91
|
+
See <https://www.openapis.org/> and
|
|
92
|
+
[version 3.0.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md)
|
|
66
93
|
of OpenAPI Specification.
|
|
67
94
|
|
|
68
95
|
## Contributions
|
|
69
96
|
|
|
70
|
-
|
|
97
|
+
- [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
|
|
98
|
+
- [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
|
|
71
99
|
|
|
72
|
-
|
|
100
|
+
## Tests
|
|
73
101
|
|
|
74
|
-
|
|
102
|
+
Run `npm test` from the root folder.
|
|
75
103
|
|
|
76
|
-
|
|
104
|
+
## Contributors
|
|
77
105
|
|
|
78
|
-
See
|
|
106
|
+
See
|
|
107
|
+
[all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
|
|
79
108
|
|
|
80
|
-
|
|
109
|
+
## License
|
|
81
110
|
|
|
82
111
|
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A package to simplify creating OpenAPI specification documents in your tests
|
|
3
|
+
* using the builder pattern.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Creating a full OpenAPI spec document in automated tests is rather
|
|
7
|
+
* cumbersome, long JSON-like objects pollute the test test code and make it
|
|
8
|
+
* difficult for readers to distinguish between what's important in the test and
|
|
9
|
+
* what's just shared OpenAPI boilerplate.
|
|
10
|
+
*
|
|
11
|
+
* OpenApiSpecBuilder utilizes
|
|
12
|
+
* {@link http://www.natpryce.com/articles/000714.html | Test Data Builder pattern}
|
|
13
|
+
* to provide a TypeScript/JavaScript API allowing users to create full OpenAPI
|
|
14
|
+
* Specification 3 documents in few lines of code.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
export * from './openapi-spec-builder';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/openapi-spec-builder
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
/**
|
|
9
|
+
* A package to simplify creating OpenAPI specification documents in your tests
|
|
10
|
+
* using the builder pattern.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Creating a full OpenAPI spec document in automated tests is rather
|
|
14
|
+
* cumbersome, long JSON-like objects pollute the test test code and make it
|
|
15
|
+
* difficult for readers to distinguish between what's important in the test and
|
|
16
|
+
* what's just shared OpenAPI boilerplate.
|
|
17
|
+
*
|
|
18
|
+
* OpenApiSpecBuilder utilizes
|
|
19
|
+
* {@link http://www.natpryce.com/articles/000714.html | Test Data Builder pattern}
|
|
20
|
+
* to provide a TypeScript/JavaScript API allowing users to create full OpenAPI
|
|
21
|
+
* Specification 3 documents in few lines of code.
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
(0, tslib_1.__exportStar)(require("./openapi-spec-builder"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8CAA8C;AAC9C,+CAA+C;AAC/C,gEAAgE;;;AAEhE;;;;;;;;;;;;;;;;GAgBG;AAEH,sEAAuC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { CallbackObject, ComponentsObject, ExampleObject, HeaderObject, ISpecificationExtension, LinkObject, OpenAPIObject, OperationObject, ParameterObject, ReferenceObject, RequestBodyObject, ResponseObject, SchemaObject, SecuritySchemeObject } from 'openapi3-ts';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new instance of OpenApiSpecBuilder.
|
|
4
|
+
*
|
|
5
|
+
* @param basePath - The base path on which the API is served.
|
|
6
|
+
*/
|
|
7
|
+
export declare function anOpenApiSpec(): OpenApiSpecBuilder;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new instance of OperationSpecBuilder.
|
|
10
|
+
*/
|
|
11
|
+
export declare function anOperationSpec(): OperationSpecBuilder;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of ComponentsSpecBuilder.
|
|
14
|
+
*/
|
|
15
|
+
export declare function aComponentsSpec(): ComponentsSpecBuilder;
|
|
16
|
+
export declare class BuilderBase<T extends ISpecificationExtension> {
|
|
17
|
+
protected _spec: T;
|
|
18
|
+
constructor(initialSpec: T);
|
|
19
|
+
/**
|
|
20
|
+
* Add a custom (extension) property to the spec object.
|
|
21
|
+
*
|
|
22
|
+
* @param key - The property name starting with "x-".
|
|
23
|
+
* @param value - The property value.
|
|
24
|
+
*/
|
|
25
|
+
withExtension(key: string, value: any): this;
|
|
26
|
+
/**
|
|
27
|
+
* Build the spec object.
|
|
28
|
+
*/
|
|
29
|
+
build(): T;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A builder for creating OpenApiSpec documents.
|
|
33
|
+
*/
|
|
34
|
+
export declare class OpenApiSpecBuilder extends BuilderBase<OpenAPIObject> {
|
|
35
|
+
/**
|
|
36
|
+
* @param basePath - The base path on which the API is served.
|
|
37
|
+
*/
|
|
38
|
+
constructor();
|
|
39
|
+
/**
|
|
40
|
+
* Define a new OperationObject at the given path and verb (method).
|
|
41
|
+
*
|
|
42
|
+
* @param verb - The HTTP verb.
|
|
43
|
+
* @param path - The path relative to basePath.
|
|
44
|
+
* @param spec - Additional specification of the operation.
|
|
45
|
+
*/
|
|
46
|
+
withOperation(verb: string, path: string, spec: OperationObject | OperationSpecBuilder): this;
|
|
47
|
+
/**
|
|
48
|
+
* Define a new operation that returns a string response.
|
|
49
|
+
*
|
|
50
|
+
* @param verb - The HTTP verb.
|
|
51
|
+
* @param path - The path relative to basePath.
|
|
52
|
+
* @param operationName - The name of the controller method implementing
|
|
53
|
+
* this operation (`x-operation-name` field).
|
|
54
|
+
*/
|
|
55
|
+
withOperationReturningString(verb: string, path: string, operationName?: string): this;
|
|
56
|
+
/**
|
|
57
|
+
* Define a new ComponentsObject.
|
|
58
|
+
*
|
|
59
|
+
* @param spec - Specification of the components.
|
|
60
|
+
*/
|
|
61
|
+
withComponents(spec: ComponentsObject | ComponentsSpecBuilder): this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A builder for creating OperationObject specifications.
|
|
65
|
+
*/
|
|
66
|
+
export declare class OperationSpecBuilder extends BuilderBase<OperationObject> {
|
|
67
|
+
constructor();
|
|
68
|
+
/**
|
|
69
|
+
* Describe a response for a given HTTP status code.
|
|
70
|
+
* @param status - HTTP status code or string "default"
|
|
71
|
+
* @param responseSpec - Specification of the response
|
|
72
|
+
*/
|
|
73
|
+
withResponse(status: number | 'default', responseSpec: ResponseObject): this;
|
|
74
|
+
withStringResponse(status?: number | 'default'): this;
|
|
75
|
+
/**
|
|
76
|
+
* Describe one more parameters accepted by the operation.
|
|
77
|
+
* Note that parameters are positional in OpenAPI Spec, therefore
|
|
78
|
+
* the first call of `withParameter` defines the first parameter,
|
|
79
|
+
* the second call defines the second parameter, etc.
|
|
80
|
+
* @param parameterSpecs
|
|
81
|
+
*/
|
|
82
|
+
withParameter(...parameterSpecs: ParameterObject[]): this;
|
|
83
|
+
withRequestBody(requestBodySpec: RequestBodyObject): this;
|
|
84
|
+
/**
|
|
85
|
+
* Define the operation name (controller method name).
|
|
86
|
+
*
|
|
87
|
+
* @param name - The name of the controller method implementing this operation.
|
|
88
|
+
*/
|
|
89
|
+
withOperationName(name: string): this;
|
|
90
|
+
/**
|
|
91
|
+
* Define the controller name (controller name).
|
|
92
|
+
*
|
|
93
|
+
* @param name - The name of the controller containing this operation.
|
|
94
|
+
*/
|
|
95
|
+
withControllerName(name: string): this;
|
|
96
|
+
/**
|
|
97
|
+
* Set up the `operationId` if not configured
|
|
98
|
+
*/
|
|
99
|
+
private setupOperationId;
|
|
100
|
+
/**
|
|
101
|
+
* Define the operationId
|
|
102
|
+
* @param operationId - Operation id
|
|
103
|
+
*/
|
|
104
|
+
withOperationId(operationId: string): this;
|
|
105
|
+
/**
|
|
106
|
+
* Describe tags associated with the operation
|
|
107
|
+
* @param tags
|
|
108
|
+
*/
|
|
109
|
+
withTags(tags: string | string[]): this;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A builder for creating ComponentsObject specifications.
|
|
113
|
+
*/
|
|
114
|
+
export declare class ComponentsSpecBuilder extends BuilderBase<ComponentsObject> {
|
|
115
|
+
constructor();
|
|
116
|
+
/**
|
|
117
|
+
* Define a component schema.
|
|
118
|
+
*
|
|
119
|
+
* @param name - The name of the schema
|
|
120
|
+
* @param schema - Specification of the schema
|
|
121
|
+
*
|
|
122
|
+
*/
|
|
123
|
+
withSchema(name: string, schema: SchemaObject | ReferenceObject): this;
|
|
124
|
+
/**
|
|
125
|
+
* Define a component response.
|
|
126
|
+
*
|
|
127
|
+
* @param name - The name of the response
|
|
128
|
+
* @param response - Specification of the response
|
|
129
|
+
*
|
|
130
|
+
*/
|
|
131
|
+
withResponse(name: string, response: ResponseObject | ReferenceObject): this;
|
|
132
|
+
/**
|
|
133
|
+
* Define a component parameter.
|
|
134
|
+
*
|
|
135
|
+
* @param name - The name of the parameter
|
|
136
|
+
* @param parameter - Specification of the parameter
|
|
137
|
+
*
|
|
138
|
+
*/
|
|
139
|
+
withParameter(name: string, parameter: ParameterObject | ReferenceObject): this;
|
|
140
|
+
/**
|
|
141
|
+
* Define a component example.
|
|
142
|
+
*
|
|
143
|
+
* @param name - The name of the example
|
|
144
|
+
* @param example - Specification of the example
|
|
145
|
+
*
|
|
146
|
+
*/
|
|
147
|
+
withExample(name: string, example: ExampleObject | ReferenceObject): this;
|
|
148
|
+
/**
|
|
149
|
+
* Define a component request body.
|
|
150
|
+
*
|
|
151
|
+
* @param name - The name of the request body
|
|
152
|
+
* @param requestBody - Specification of the request body
|
|
153
|
+
*
|
|
154
|
+
*/
|
|
155
|
+
withRequestBody(name: string, requestBody: RequestBodyObject | ReferenceObject): this;
|
|
156
|
+
/**
|
|
157
|
+
* Define a component header.
|
|
158
|
+
*
|
|
159
|
+
* @param name - The name of the header
|
|
160
|
+
* @param header - Specification of the header
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
withHeader(name: string, header: HeaderObject | ReferenceObject): this;
|
|
164
|
+
/**
|
|
165
|
+
* Define a component security scheme.
|
|
166
|
+
*
|
|
167
|
+
* @param name - The name of the security scheme
|
|
168
|
+
* @param securityScheme - Specification of the security scheme
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
withSecurityScheme(name: string, securityScheme: SecuritySchemeObject | ReferenceObject): this;
|
|
172
|
+
/**
|
|
173
|
+
* Define a component link.
|
|
174
|
+
*
|
|
175
|
+
* @param name - The name of the link
|
|
176
|
+
* @param link - Specification of the link
|
|
177
|
+
*
|
|
178
|
+
*/
|
|
179
|
+
withLink(name: string, link: LinkObject | ReferenceObject): this;
|
|
180
|
+
/**
|
|
181
|
+
* Define a component callback.
|
|
182
|
+
*
|
|
183
|
+
* @param name - The name of the callback
|
|
184
|
+
* @param callback - Specification of the callback
|
|
185
|
+
*
|
|
186
|
+
*/
|
|
187
|
+
withCallback(name: string, callback: CallbackObject | ReferenceObject): this;
|
|
188
|
+
}
|