@e22m4u/js-openapi 0.0.9 → 0.1.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/dist/cjs/index.cjs
CHANGED
|
@@ -257,7 +257,6 @@ var import_js_format7 = require("@e22m4u/js-format");
|
|
|
257
257
|
|
|
258
258
|
// src/oa-document-builder.js
|
|
259
259
|
var import_js_format6 = require("@e22m4u/js-format");
|
|
260
|
-
var import_js_service = require("@e22m4u/js-service");
|
|
261
260
|
|
|
262
261
|
// src/oa-document-object/validate-oa-document-object.js
|
|
263
262
|
var import_js_format5 = require("@e22m4u/js-format");
|
|
@@ -1906,7 +1905,7 @@ var OA_COMPONENT_TYPE_TO_DEFINITION_NAME_MAP = {
|
|
|
1906
1905
|
[OAComponentType.CALLBACK]: "callbacks-or-reference",
|
|
1907
1906
|
[OAComponentType.PATH_ITEM]: "path-item"
|
|
1908
1907
|
};
|
|
1909
|
-
var OADocumentBuilder = class
|
|
1908
|
+
var OADocumentBuilder = class {
|
|
1910
1909
|
static {
|
|
1911
1910
|
__name(this, "OADocumentBuilder");
|
|
1912
1911
|
}
|
|
@@ -1927,24 +1926,9 @@ var OADocumentBuilder = class extends import_js_service.Service {
|
|
|
1927
1926
|
/**
|
|
1928
1927
|
* Constructor.
|
|
1929
1928
|
*
|
|
1930
|
-
* @param {import('
|
|
1931
|
-
* @param {import('./oa-document-builder.js').OADocumentInput} document
|
|
1929
|
+
* @param {import('./oa-document-builder.js').OADocumentInput} [document]
|
|
1932
1930
|
*/
|
|
1933
|
-
constructor(
|
|
1934
|
-
if ((0, import_js_service.isServiceContainer)(containerOrDocument)) {
|
|
1935
|
-
super(containerOrDocument);
|
|
1936
|
-
} else {
|
|
1937
|
-
super();
|
|
1938
|
-
if (containerOrDocument !== void 0) {
|
|
1939
|
-
if (!containerOrDocument || typeof containerOrDocument !== "object" || Array.isArray(containerOrDocument)) {
|
|
1940
|
-
throw new import_js_format6.InvalidArgumentError(
|
|
1941
|
-
'Parameter "containerOrDocument" must be an Object, but %v was given.',
|
|
1942
|
-
containerOrDocument
|
|
1943
|
-
);
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
document = document === void 0 ? containerOrDocument : document;
|
|
1947
|
-
}
|
|
1931
|
+
constructor(document) {
|
|
1948
1932
|
if (document !== void 0) {
|
|
1949
1933
|
if (!document || typeof document !== "object" || Array.isArray(document)) {
|
|
1950
1934
|
throw new import_js_format6.InvalidArgumentError(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-openapi",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "JavaScript модуль для создания OpenAPI Документа",
|
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,24 +37,23 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@e22m4u/js-format": "~0.4.0",
|
|
40
|
-
"@e22m4u/js-service": "~0.6.1",
|
|
41
40
|
"ajv": "~8.18.0",
|
|
42
41
|
"ajv-formats": "~3.0.1"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@commitlint/cli": "~20.4.
|
|
46
|
-
"@commitlint/config-conventional": "~20.4.
|
|
44
|
+
"@commitlint/cli": "~20.4.4",
|
|
45
|
+
"@commitlint/config-conventional": "~20.4.4",
|
|
47
46
|
"@eslint/js": "~9.39.2",
|
|
48
47
|
"@types/chai": "~5.2.3",
|
|
49
48
|
"@types/mocha": "~10.0.10",
|
|
50
49
|
"c8": "~11.0.0",
|
|
51
50
|
"chai": "~6.2.2",
|
|
52
|
-
"esbuild": "~0.27.
|
|
51
|
+
"esbuild": "~0.27.4",
|
|
53
52
|
"eslint": "~9.39.2",
|
|
54
53
|
"eslint-config-prettier": "~10.1.8",
|
|
55
|
-
"eslint-plugin-chai-expect": "~
|
|
54
|
+
"eslint-plugin-chai-expect": "~4.0.0",
|
|
56
55
|
"eslint-plugin-import": "~2.32.0",
|
|
57
|
-
"eslint-plugin-jsdoc": "~62.
|
|
56
|
+
"eslint-plugin-jsdoc": "~62.8.0",
|
|
58
57
|
"eslint-plugin-mocha": "~11.2.0",
|
|
59
58
|
"globals": "~17.4.0",
|
|
60
59
|
"husky": "~9.1.7",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {Optional} from './types.js';
|
|
2
|
-
import {Service, ServiceContainer} from '@e22m4u/js-service';
|
|
3
2
|
|
|
4
3
|
import {
|
|
5
4
|
OAOperationGroup,
|
|
@@ -82,15 +81,7 @@ export type OADocumentInput = Optional<OADocumentObject, 'openapi' | 'info'>;
|
|
|
82
81
|
/**
|
|
83
82
|
* Document builder.
|
|
84
83
|
*/
|
|
85
|
-
export declare class OADocumentBuilder
|
|
86
|
-
/**
|
|
87
|
-
* Constructor.
|
|
88
|
-
*
|
|
89
|
-
* @param container
|
|
90
|
-
* @param document
|
|
91
|
-
*/
|
|
92
|
-
constructor(container: ServiceContainer, document?: OADocumentInput);
|
|
93
|
-
|
|
84
|
+
export declare class OADocumentBuilder {
|
|
94
85
|
/**
|
|
95
86
|
* Constructor.
|
|
96
87
|
*
|
|
@@ -98,17 +89,6 @@ export declare class OADocumentBuilder extends Service {
|
|
|
98
89
|
*/
|
|
99
90
|
constructor(document?: OADocumentInput);
|
|
100
91
|
|
|
101
|
-
/**
|
|
102
|
-
* Constructor.
|
|
103
|
-
*
|
|
104
|
-
* @param containerOrDocument
|
|
105
|
-
* @param document
|
|
106
|
-
*/
|
|
107
|
-
constructor(
|
|
108
|
-
containerOrDocument?: ServiceContainer | OADocumentInput,
|
|
109
|
-
document?: OADocumentInput,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
92
|
/**
|
|
113
93
|
* Get document object reference.
|
|
114
94
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {InvalidArgumentError} from '@e22m4u/js-format';
|
|
2
2
|
import {OAOperationGroup} from './oa-operation-group.js';
|
|
3
|
-
import {isServiceContainer, Service} from '@e22m4u/js-service';
|
|
4
3
|
import {validateOADocumentObject} from './oa-document-object/index.js';
|
|
5
4
|
import {escapeJsonPointer} from './json-pointer/escape-json-pointer.js';
|
|
6
5
|
import {OPENAPI_VERSION, OAOperationMethod} from './oa-specification.js';
|
|
@@ -67,7 +66,7 @@ export const OA_COMPONENT_TYPE_TO_DEFINITION_NAME_MAP = {
|
|
|
67
66
|
/**
|
|
68
67
|
* OpenAPI Document builder.
|
|
69
68
|
*/
|
|
70
|
-
export class OADocumentBuilder
|
|
69
|
+
export class OADocumentBuilder {
|
|
71
70
|
/**
|
|
72
71
|
* Document.
|
|
73
72
|
*
|
|
@@ -86,30 +85,9 @@ export class OADocumentBuilder extends Service {
|
|
|
86
85
|
/**
|
|
87
86
|
* Constructor.
|
|
88
87
|
*
|
|
89
|
-
* @param {import('
|
|
90
|
-
* @param {import('./oa-document-builder.js').OADocumentInput} document
|
|
88
|
+
* @param {import('./oa-document-builder.js').OADocumentInput} [document]
|
|
91
89
|
*/
|
|
92
|
-
constructor(
|
|
93
|
-
if (isServiceContainer(containerOrDocument)) {
|
|
94
|
-
super(containerOrDocument);
|
|
95
|
-
} else {
|
|
96
|
-
super();
|
|
97
|
-
// containerOrDocument
|
|
98
|
-
if (containerOrDocument !== undefined) {
|
|
99
|
-
if (
|
|
100
|
-
!containerOrDocument ||
|
|
101
|
-
typeof containerOrDocument !== 'object' ||
|
|
102
|
-
Array.isArray(containerOrDocument)
|
|
103
|
-
) {
|
|
104
|
-
throw new InvalidArgumentError(
|
|
105
|
-
'Parameter "containerOrDocument" must be an Object, ' +
|
|
106
|
-
'but %v was given.',
|
|
107
|
-
containerOrDocument,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
document = document === undefined ? containerOrDocument : document;
|
|
112
|
-
}
|
|
90
|
+
constructor(document) {
|
|
113
91
|
// document
|
|
114
92
|
if (document !== undefined) {
|
|
115
93
|
if (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
2
|
import {format} from '@e22m4u/js-format';
|
|
3
|
-
import {
|
|
3
|
+
import {OAOperationGroup} from './oa-operation-group.js';
|
|
4
4
|
import {OADocumentObjectValidationError} from './errors/index.js';
|
|
5
5
|
import {OAComponentType, OADocumentBuilder} from './oa-document-builder.js';
|
|
6
6
|
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
OASecuritySchemeType,
|
|
13
13
|
OAOperationMethod,
|
|
14
14
|
} from './oa-specification.js';
|
|
15
|
-
import {OAOperationGroup} from './oa-operation-group.js';
|
|
16
15
|
|
|
17
16
|
describe('OADocumentBuilder', function () {
|
|
18
17
|
describe('constructor', function () {
|
|
@@ -20,34 +19,8 @@ describe('OADocumentBuilder', function () {
|
|
|
20
19
|
new OADocumentBuilder();
|
|
21
20
|
});
|
|
22
21
|
|
|
23
|
-
it('should pass the ServiceContainer to the super class', function () {
|
|
24
|
-
const cont = new ServiceContainer();
|
|
25
|
-
const S = new OADocumentBuilder(cont);
|
|
26
|
-
expect(S.container).to.be.eq(cont);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should require the parameter "containerOrDocument" to be an Object', function () {
|
|
30
|
-
const throwable = v => () => new OADocumentBuilder(v);
|
|
31
|
-
const error = s =>
|
|
32
|
-
format(
|
|
33
|
-
'Parameter "containerOrDocument" must be an Object, ' +
|
|
34
|
-
'but %s was given.',
|
|
35
|
-
s,
|
|
36
|
-
);
|
|
37
|
-
expect(throwable('str')).to.throw(error('"str"'));
|
|
38
|
-
expect(throwable('')).to.throw(error('""'));
|
|
39
|
-
expect(throwable(10)).to.throw(error('10'));
|
|
40
|
-
expect(throwable(0)).to.throw(error('0'));
|
|
41
|
-
expect(throwable(true)).to.throw(error('true'));
|
|
42
|
-
expect(throwable(false)).to.throw(error('false'));
|
|
43
|
-
expect(throwable([])).to.throw(error('Array'));
|
|
44
|
-
expect(throwable(null)).to.throw(error('null'));
|
|
45
|
-
throwable({})();
|
|
46
|
-
throwable(undefined)();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
22
|
it('should require the parameter "document" to be an Object', function () {
|
|
50
|
-
const throwable = v => () => new OADocumentBuilder(
|
|
23
|
+
const throwable = v => () => new OADocumentBuilder(v);
|
|
51
24
|
const error = s =>
|
|
52
25
|
format('Parameter "document" must be an Object, but %s was given.', s);
|
|
53
26
|
expect(throwable('str')).to.throw(error('"str"'));
|
|
@@ -62,7 +35,7 @@ describe('OADocumentBuilder', function () {
|
|
|
62
35
|
throwable(undefined)();
|
|
63
36
|
});
|
|
64
37
|
|
|
65
|
-
it('should merge the document
|
|
38
|
+
it('should merge the parameter "document" with the default document', function () {
|
|
66
39
|
const doc = {
|
|
67
40
|
openapi: '3.1.2',
|
|
68
41
|
info: {
|
|
@@ -75,19 +48,6 @@ describe('OADocumentBuilder', function () {
|
|
|
75
48
|
expect(res).to.be.eql({...doc, paths: {}});
|
|
76
49
|
});
|
|
77
50
|
|
|
78
|
-
it('should merge the document from the second parameter with the default document', function () {
|
|
79
|
-
const doc = {
|
|
80
|
-
openapi: '3.1.2',
|
|
81
|
-
info: {
|
|
82
|
-
title: 'My OpenAPI Doc',
|
|
83
|
-
version: '1.0.0',
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
const S = new OADocumentBuilder(undefined, doc);
|
|
87
|
-
const res = S.getDocumentObjectRef();
|
|
88
|
-
expect(res).to.be.eql({...doc, paths: {}});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
51
|
it('should validate the given document object', function () {
|
|
92
52
|
const doc = {openapi: 'abc'};
|
|
93
53
|
const throwable = () => new OADocumentBuilder(doc);
|